Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec94d77

Browse files
authored
[Photon] Add state, county & district properties (#1188)
Add Photon properties Add state, county and district properties from Photon API
1 parent 2346d59 commit ec94d77

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

src/Provider/Photon/Model/PhotonAddress.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ final class PhotonAddress extends Address
3939
*/
4040
private $osmTag;
4141

42+
/**
43+
* @var string|null
44+
*/
45+
private $state;
46+
47+
/**
48+
* @var string|null
49+
*/
50+
private $county;
51+
52+
/**
53+
* @var string|null
54+
*/
55+
private $district;
56+
4257
/**
4358
* @return string|null
4459
*/
@@ -131,4 +146,64 @@ public function withOSMTag(string $key = null, string $value = null): self
131146

132147
return $new;
133148
}
149+
150+
/**
151+
* @return string|null
152+
*/
153+
public function getState()
154+
{
155+
return $this->state;
156+
}
157+
158+
/**
159+
* @param string|null $state
160+
* @return PhotonAddress
161+
*/
162+
public function withState(string $state = null): self
163+
{
164+
$new = clone $this;
165+
$new->state = $state;
166+
167+
return $new;
168+
}
169+
170+
/**
171+
* @return string|null
172+
*/
173+
public function getCounty()
174+
{
175+
return $this->county;
176+
}
177+
178+
/**
179+
* @param string|null $county
180+
* @return PhotonAddress
181+
*/
182+
public function withCounty(string $county = null): self
183+
{
184+
$new = clone $this;
185+
$new->county = $county;
186+
187+
return $new;
188+
}
189+
190+
/**
191+
* @return string|null
192+
*/
193+
public function getDistrict()
194+
{
195+
return $this->district;
196+
}
197+
198+
/**
199+
* @param string|null $district
200+
* @return PhotonAddress
201+
*/
202+
public function withDistrict(string $district = null): self
203+
{
204+
$new = clone $this;
205+
$new->district = $district;
206+
207+
return $new;
208+
}
134209
}

src/Provider/Photon/Photon.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ private function featureToAddress(\stdClass $feature): Location
156156
$properties->osm_key ?? null,
157157
$properties->osm_value ?? null
158158
)
159-
->withName($properties->name ?? null);
159+
->withName($properties->name ?? null)
160+
->withState($properties->state ?? null)
161+
->withCounty($properties->county ?? null)
162+
->withDistrict($properties->district ?? null);
160163

161164
return $address;
162165
}
Original file line numberDiff line numberDiff line change
@@ -1 +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"}";
1+
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"}";

src/Provider/Photon/Tests/PhotonTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public function testGeocodeQuery()
7575
$this->assertEquals('N', $result->getOSMType());
7676
$this->assertEquals('place', $result->getOSMTag()->key);
7777
$this->assertEquals('house', $result->getOSMTag()->value);
78+
$this->assertEquals('Île-de-France', $result->getState());
79+
$this->assertNull($result->getCounty());
80+
$this->assertEquals('Paris', $result->getDistrict());
7881
}
7982

8083
public function testGeocodeQueryWithNamedResult()
@@ -113,5 +116,8 @@ public function testReverseQuery()
113116
$this->assertEquals('N', $result->getOSMType());
114117
$this->assertEquals('tourism', $result->getOSMTag()->key);
115118
$this->assertEquals('information', $result->getOSMTag()->value);
119+
$this->assertEquals('Niedersachsen', $result->getState());
120+
$this->assertEquals('Landkreis Hildesheim', $result->getCounty());
121+
$this->assertEquals('Sehlem', $result->getDistrict());
116122
}
117123
}

0 commit comments

Comments
 (0)