Skip to content

Commit

Permalink
[Photon] Add state, county & district properties (#1188)
Browse files Browse the repository at this point in the history
Add Photon properties

Add state, county and district properties from Photon API
  • Loading branch information
ybert committed Jul 9, 2023
1 parent 2346d59 commit ec94d77
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
75 changes: 75 additions & 0 deletions src/Provider/Photon/Model/PhotonAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
}
5 changes: 4 additions & 1 deletion src/Provider/Photon/Photon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"}";
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"}";
6 changes: 6 additions & 0 deletions src/Provider/Photon/Tests/PhotonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
}
}

0 comments on commit ec94d77

Please sign in to comment.