Skip to content

Commit

Permalink
tests: fix in Map.php fromArray()
Browse files Browse the repository at this point in the history
  • Loading branch information
sblondeau committed Nov 11, 2024
1 parent 1517fe1 commit fd17d18
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Map/src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,21 @@ public function addPolygon(Polygon $polygon): self
public function addPolyline(Polyline $polyline): self
{
$this->polylines[] = $polyline;

return $this;
}

public function toArray(): array
{
if (!$this->fitBoundsToMarkers) {
if (null === $this->center) {
throw new InvalidArgumentException('The map "center" must be explicitly set when not enabling "fitBoundsToMarkers" feature.');
}

if (null === $this->zoom) {
throw new InvalidArgumentException('The map "zoom" must be explicitly set when not enabling "fitBoundsToMarkers" feature.');
}
}

return [
'center' => $this->center?->toArray(),
'zoom' => $this->zoom,
Expand Down Expand Up @@ -146,32 +145,31 @@ public function toArray(): array
public static function fromArray(array $map): self
{
$map['fitBoundsToMarkers'] = true;

if (isset($map['center'])) {
$map['center'] = Point::fromArray($map['center']);
}

if (isset($map['zoom']) || isset($map['center'])) {
$map['fitBoundsToMarkers'] = false;
}

$map['markers'] ??= [];
if (!\is_array($map['markers'])) {
throw new InvalidArgumentException('The "markers" parameter must be an array.');
}
$map['markers'] = array_map(Marker::fromArray(...), $map['markers']);

$map['polygons'] ??= [];
if (!\is_array($map['polygons'])) {
throw new InvalidArgumentException('The "polygons" parameter must be an array.');
}
$map['polygons'] = array_map(Polygon::fromArray(...), $map['polygons']);

$map['polylines'] ??= [];
if (!\is_array($map['polylines'])) {
throw new InvalidArgumentException('The "polylines" parameter must be an array.');
}
$map['polylines'] = array_map(Polygon::fromArray(...), $map['polylines']);
$map['polylines'] = array_map(Polyline::fromArray(...), $map['polylines']);

return new self(...$map);
}
Expand Down

0 comments on commit fd17d18

Please sign in to comment.