diff --git a/Model/Item.php b/Model/Item.php index 96f9aa9..a85fbff 100644 --- a/Model/Item.php +++ b/Model/Item.php @@ -732,6 +732,8 @@ public function map(callable $callable) $this->highlights = $array['highlights'] ?? []; $this->promoted = isset($array['is_promoted']) && true === $array['is_promoted']; $this->score = $array['score'] ?? null; - $this->coordinate = $array['coordinate'] ?? null; + $this->coordinate = is_array($array['coordinate'] ?? null) + ? Coordinate::createFromArray($array['coordinate']) + : null; } } diff --git a/Tests/Model/ItemTest.php b/Tests/Model/ItemTest.php index 1e65805..7f9e63e 100644 --- a/Tests/Model/ItemTest.php +++ b/Tests/Model/ItemTest.php @@ -524,6 +524,13 @@ public function testMap() $this->assertFalse($item->isPromoted()); $this->assertEquals(10, $item->getScore()); $this->assertNull($item->getCoordinate()); + + $item->map(function (array $map) { + $map['coordinate'] = ['lat' => 1, 'lon' => 2]; + + return $map; + }); + $this->assertInstanceOf(Coordinate::class, $item->getCoordinate()); } /**