diff --git a/src/Provider/Photon/Model/PhotonAddress.php b/src/Provider/Photon/Model/PhotonAddress.php index 2366f0581..b8b40f04d 100644 --- a/src/Provider/Photon/Model/PhotonAddress.php +++ b/src/Provider/Photon/Model/PhotonAddress.php @@ -39,6 +39,21 @@ final class PhotonAddress extends Address */ private $osmTag; + /** + * @var string|null + */ + private $state; + + /** + * @var string|null + */ + private $county; + + /** + * @var string|null + */ + private $district; + /** * @return string|null */ @@ -131,4 +146,64 @@ public function withOSMTag(string $key = null, string $value = null): self return $new; } + + /** + * @return string|null + */ + public function getState() + { + return $this->state; + } + + /** + * @param string|null $state + * @return PhotonAddress + */ + public function withState(string $state = null): self + { + $new = clone $this; + $new->state = $state; + + return $new; + } + + /** + * @return string|null + */ + public function getCounty() + { + return $this->county; + } + + /** + * @param string|null $county + * @return PhotonAddress + */ + public function withCounty(string $county = null): self + { + $new = clone $this; + $new->county = $county; + + return $new; + } + + /** + * @return string|null + */ + public function getDistrict() + { + return $this->district; + } + + /** + * @param string|null $district + * @return PhotonAddress + */ + public function withDistrict(string $district = null): self + { + $new = clone $this; + $new->district = $district; + + return $new; + } } diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index 36f5ef181..f805bbbb7 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -156,7 +156,10 @@ private function featureToAddress(\stdClass $feature): Location $properties->osm_key ?? null, $properties->osm_value ?? null ) - ->withName($properties->name ?? null); + ->withName($properties->name ?? null) + ->withState($properties->state ?? null) + ->withCounty($properties->county ?? null) + ->withDistrict($properties->district ?? null); return $address; } diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_befc5e828aebefb41ad8dca3453898cf26e6fae4 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_befc5e828aebefb41ad8dca3453898cf26e6fae4 index 39fa603fc..5e7236e04 100644 --- a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_befc5e828aebefb41ad8dca3453898cf26e6fae4 +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_befc5e828aebefb41ad8dca3453898cf26e6fae4 @@ -1 +1 @@ -s:455:"{"features":[{"geometry":{"coordinates":[2.3890894,48.8631927],"type":"Point"},"type":"Feature","properties":{"osm_id":1988097192,"country":"France","city":"Paris","countrycode":"FR","postcode":"75020","locality":"Campagne à Paris","county":"Paris","type":"house","osm_type":"N","osm_key":"place","housenumber":"10","street":"Avenue Gambetta","district":"Quartier Saint-Fargeau","osm_value":"house","state":"Île-de-France"}}],"type":"FeatureCollection"}"; \ No newline at end of file +s:426:"{"features":[{"geometry":{"coordinates":[2.3890894,48.8631927],"type":"Point"},"type":"Feature","properties":{"osm_id":1988097192,"country":"France","city":"Paris","countrycode":"FR","postcode":"75020","locality":"Quartier Saint-Fargeau","type":"house","osm_type":"N","osm_key":"place","housenumber":"10","street":"Avenue Gambetta","district":"Paris","osm_value":"house","state":"Île-de-France"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index ca2f40733..b579a8c40 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -75,6 +75,9 @@ public function testGeocodeQuery() $this->assertEquals('N', $result->getOSMType()); $this->assertEquals('place', $result->getOSMTag()->key); $this->assertEquals('house', $result->getOSMTag()->value); + $this->assertEquals('Île-de-France', $result->getState()); + $this->assertNull($result->getCounty()); + $this->assertEquals('Paris', $result->getDistrict()); } public function testGeocodeQueryWithNamedResult() @@ -113,5 +116,8 @@ public function testReverseQuery() $this->assertEquals('N', $result->getOSMType()); $this->assertEquals('tourism', $result->getOSMTag()->key); $this->assertEquals('information', $result->getOSMTag()->value); + $this->assertEquals('Niedersachsen', $result->getState()); + $this->assertEquals('Landkreis Hildesheim', $result->getCounty()); + $this->assertEquals('Sehlem', $result->getDistrict()); } }