Skip to content

Commit ed3af33

Browse files
svrdlicNyholm
authored andcommitted
adding address_components parameters (#732)
* adding address_components paramerets * cs * cs * required changes * Adding a test for premise address component * adding establishment parameter * adding required tests * cs * removing unnecessary conditions, making code less complex
1 parent 60936cf commit ed3af33

9 files changed

+1333
-4
lines changed

src/Provider/GoogleMaps/GoogleMaps.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,19 @@ private function fetchUrl(string $url, string $locale = null, int $limit, string
264264
if (isset($result->formatted_address)) {
265265
$address = $address->withFormattedAddress($result->formatted_address);
266266
}
267-
if ($builder->hasValue('subpremise')) {
268-
$address = $address->withSubpremise($builder->getValue('subpremise'));
269-
}
267+
$address = $address->withStreetAddress($builder->getValue('street_address'));
268+
$address = $address->withIntersection($builder->getValue('intersection'));
269+
$address = $address->withPolitical($builder->getValue('political'));
270+
$address = $address->withColloquialArea($builder->getValue('colloquial_area'));
271+
$address = $address->withWard($builder->getValue('ward'));
272+
$address = $address->withNeighborhood($builder->getValue('neighborhood'));
273+
$address = $address->withPremise($builder->getValue('premise'));
274+
$address = $address->withSubpremise($builder->getValue('subpremise'));
275+
$address = $address->withNaturalFeature($builder->getValue('natural_feature'));
276+
$address = $address->withAirport($builder->getValue('airport'));
277+
$address = $address->withPark($builder->getValue('park'));
278+
$address = $address->withPointOfInterest($builder->getValue('point_of_interest'));
279+
$address = $address->withEstablishment($builder->getValue('establishment'));
270280
$results[] = $address;
271281

272282
if (count($results) >= $limit) {
@@ -321,8 +331,20 @@ private function updateAddressComponent(AddressBuilder $builder, string $type, $
321331
$builder->setSubLocality($values->long_name);
322332
break;
323333

334+
case 'street_address':
335+
case 'intersection':
336+
case 'political':
337+
case 'colloquial_area':
338+
case 'ward':
339+
case 'neighborhood':
340+
case 'premise':
324341
case 'subpremise':
325-
$builder->setValue('subpremise', $values->long_name);
342+
case 'natural_feature':
343+
case 'airport':
344+
case 'park':
345+
case 'point_of_interest':
346+
case 'establishment':
347+
$builder->setValue($type, $values->long_name);
326348
break;
327349

328350
default:

src/Provider/GoogleMaps/Model/GoogleAddress.php

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,71 @@ final class GoogleAddress extends Address
3434
*/
3535
private $formattedAddress;
3636

37+
/**
38+
* @var string|null
39+
*/
40+
private $streetAddress;
41+
42+
/**
43+
* @var string|null
44+
*/
45+
private $intersection;
46+
47+
/**
48+
* @var string|null
49+
*/
50+
private $political;
51+
52+
/**
53+
* @var string|null
54+
*/
55+
private $colloquialArea;
56+
57+
/**
58+
* @var string|null
59+
*/
60+
private $ward;
61+
62+
/**
63+
* @var string|null
64+
*/
65+
private $neighborhood;
66+
67+
/**
68+
* @var string|null
69+
*/
70+
private $premise;
71+
3772
/**
3873
* @var string|null
3974
*/
4075
private $subpremise;
4176

77+
/**
78+
* @var string|null
79+
*/
80+
private $naturalFeature;
81+
82+
/**
83+
* @var string|null
84+
*/
85+
private $airport;
86+
87+
/**
88+
* @var string|null
89+
*/
90+
private $park;
91+
92+
/**
93+
* @var string|null
94+
*/
95+
private $pointOfInterest;
96+
97+
/**
98+
* @var string|null
99+
*/
100+
private $establishment;
101+
42102
/**
43103
* @param null|string $locationType
44104
*
@@ -100,6 +160,196 @@ public function withFormattedAddress(string $formattedAddress = null)
100160
return $new;
101161
}
102162

163+
/**
164+
* @return null|string
165+
*/
166+
public function getAirport()
167+
{
168+
return $this->airport;
169+
}
170+
171+
/**
172+
* @param null|string $airport
173+
*/
174+
public function withAirport(string $airport = null)
175+
{
176+
$new = clone $this;
177+
$new->airport = $airport;
178+
179+
return $new;
180+
}
181+
182+
/**
183+
* @return null|string
184+
*/
185+
public function getColloquialArea()
186+
{
187+
return $this->colloquialArea;
188+
}
189+
190+
/**
191+
* @param null|string $colloquialArea
192+
*/
193+
public function withColloquialArea(string $colloquialArea = null)
194+
{
195+
$new = clone $this;
196+
$new->colloquialArea = $colloquialArea;
197+
198+
return $new;
199+
}
200+
201+
/**
202+
* @return null|string
203+
*/
204+
public function getIntersection()
205+
{
206+
return $this->intersection;
207+
}
208+
209+
/**
210+
* @param null|string $intersection
211+
*/
212+
public function withIntersection(string $intersection = null)
213+
{
214+
$new = clone $this;
215+
$new->intersection = $intersection;
216+
217+
return $new;
218+
}
219+
220+
/**
221+
* @return null|string
222+
*/
223+
public function getNaturalFeature()
224+
{
225+
return $this->naturalFeature;
226+
}
227+
228+
/**
229+
* @param null|string $naturalFeature
230+
*/
231+
public function withNaturalFeature(string $naturalFeature = null)
232+
{
233+
$new = clone $this;
234+
$new->naturalFeature = $naturalFeature;
235+
236+
return $new;
237+
}
238+
239+
/**
240+
* @return null|string
241+
*/
242+
public function getNeighborhood()
243+
{
244+
return $this->neighborhood;
245+
}
246+
247+
/**
248+
* @param null|string $neighborhood
249+
*/
250+
public function withNeighborhood(string $neighborhood = null)
251+
{
252+
$new = clone $this;
253+
$new->neighborhood = $neighborhood;
254+
255+
return $new;
256+
}
257+
258+
/**
259+
* @return null|string
260+
*/
261+
public function getPark()
262+
{
263+
return $this->park;
264+
}
265+
266+
/**
267+
* @param null|string $park
268+
*/
269+
public function withPark(string $park = null)
270+
{
271+
$new = clone $this;
272+
$new->park = $park;
273+
274+
return $new;
275+
}
276+
277+
/**
278+
* @return null|string
279+
*/
280+
public function getPointOfInterest()
281+
{
282+
return $this->pointOfInterest;
283+
}
284+
285+
/**
286+
* @param null|string $pointOfInterest
287+
*/
288+
public function withPointOfInterest(string $pointOfInterest = null)
289+
{
290+
$new = clone $this;
291+
$new->pointOfInterest = $pointOfInterest;
292+
293+
return $new;
294+
}
295+
296+
/**
297+
* @return null|string
298+
*/
299+
public function getPolitical()
300+
{
301+
return $this->political;
302+
}
303+
304+
/**
305+
* @param null|string $political
306+
*/
307+
public function withPolitical(string $political = null)
308+
{
309+
$new = clone $this;
310+
$new->political = $political;
311+
312+
return $new;
313+
}
314+
315+
/**
316+
* @return null|string
317+
*/
318+
public function getPremise()
319+
{
320+
return $this->premise;
321+
}
322+
323+
/**
324+
* @param null|string $premise
325+
*/
326+
public function withPremise($premise = null)
327+
{
328+
$new = clone $this;
329+
$new->premise = $premise;
330+
331+
return $new;
332+
}
333+
334+
/**
335+
* @return null|string
336+
*/
337+
public function getStreetAddress()
338+
{
339+
return $this->streetAddress;
340+
}
341+
342+
/**
343+
* @param null|string $streetAddress
344+
*/
345+
public function withStreetAddress(string $streetAddress = null)
346+
{
347+
$new = clone $this;
348+
$new->streetAddress = $streetAddress;
349+
350+
return $new;
351+
}
352+
103353
/**
104354
* @return null|string
105355
*/
@@ -118,4 +368,42 @@ public function withSubpremise(string $subpremise = null)
118368

119369
return $new;
120370
}
371+
372+
/**
373+
* @return null|string
374+
*/
375+
public function getWard()
376+
{
377+
return $this->ward;
378+
}
379+
380+
/**
381+
* @param null|string $ward
382+
*/
383+
public function withWard(string $ward = null)
384+
{
385+
$new = clone $this;
386+
$new->ward = $ward;
387+
388+
return $new;
389+
}
390+
391+
/**
392+
* @return null|string
393+
*/
394+
public function getEstablishment()
395+
{
396+
return $this->establishment;
397+
}
398+
399+
/**
400+
* @param null|string $ward
401+
*/
402+
public function withEstablishment(string $establishment = null)
403+
{
404+
$new = clone $this;
405+
$new->establishment = $establishment;
406+
407+
return $new;
408+
}
121409
}

0 commit comments

Comments
 (0)