Skip to content

Commit

Permalink
adding address_components parameters (#732)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
svrdlic authored and Nyholm committed Jul 8, 2017
1 parent 7a9f2a9 commit 3c69d9c
Show file tree
Hide file tree
Showing 9 changed files with 1,333 additions and 4 deletions.
30 changes: 26 additions & 4 deletions GoogleMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,19 @@ private function fetchUrl(string $url, string $locale = null, int $limit, string
if (isset($result->formatted_address)) {
$address = $address->withFormattedAddress($result->formatted_address);
}
if ($builder->hasValue('subpremise')) {
$address = $address->withSubpremise($builder->getValue('subpremise'));
}
$address = $address->withStreetAddress($builder->getValue('street_address'));
$address = $address->withIntersection($builder->getValue('intersection'));
$address = $address->withPolitical($builder->getValue('political'));
$address = $address->withColloquialArea($builder->getValue('colloquial_area'));
$address = $address->withWard($builder->getValue('ward'));
$address = $address->withNeighborhood($builder->getValue('neighborhood'));
$address = $address->withPremise($builder->getValue('premise'));
$address = $address->withSubpremise($builder->getValue('subpremise'));
$address = $address->withNaturalFeature($builder->getValue('natural_feature'));
$address = $address->withAirport($builder->getValue('airport'));
$address = $address->withPark($builder->getValue('park'));
$address = $address->withPointOfInterest($builder->getValue('point_of_interest'));
$address = $address->withEstablishment($builder->getValue('establishment'));
$results[] = $address;

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

case 'street_address':
case 'intersection':
case 'political':
case 'colloquial_area':
case 'ward':
case 'neighborhood':
case 'premise':
case 'subpremise':
$builder->setValue('subpremise', $values->long_name);
case 'natural_feature':
case 'airport':
case 'park':
case 'point_of_interest':
case 'establishment':
$builder->setValue($type, $values->long_name);
break;

default:
Expand Down
288 changes: 288 additions & 0 deletions Model/GoogleAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,71 @@ final class GoogleAddress extends Address
*/
private $formattedAddress;

/**
* @var string|null
*/
private $streetAddress;

/**
* @var string|null
*/
private $intersection;

/**
* @var string|null
*/
private $political;

/**
* @var string|null
*/
private $colloquialArea;

/**
* @var string|null
*/
private $ward;

/**
* @var string|null
*/
private $neighborhood;

/**
* @var string|null
*/
private $premise;

/**
* @var string|null
*/
private $subpremise;

/**
* @var string|null
*/
private $naturalFeature;

/**
* @var string|null
*/
private $airport;

/**
* @var string|null
*/
private $park;

/**
* @var string|null
*/
private $pointOfInterest;

/**
* @var string|null
*/
private $establishment;

/**
* @param null|string $locationType
*
Expand Down Expand Up @@ -100,6 +160,196 @@ public function withFormattedAddress(string $formattedAddress = null)
return $new;
}

/**
* @return null|string
*/
public function getAirport()
{
return $this->airport;
}

/**
* @param null|string $airport
*/
public function withAirport(string $airport = null)
{
$new = clone $this;
$new->airport = $airport;

return $new;
}

/**
* @return null|string
*/
public function getColloquialArea()
{
return $this->colloquialArea;
}

/**
* @param null|string $colloquialArea
*/
public function withColloquialArea(string $colloquialArea = null)
{
$new = clone $this;
$new->colloquialArea = $colloquialArea;

return $new;
}

/**
* @return null|string
*/
public function getIntersection()
{
return $this->intersection;
}

/**
* @param null|string $intersection
*/
public function withIntersection(string $intersection = null)
{
$new = clone $this;
$new->intersection = $intersection;

return $new;
}

/**
* @return null|string
*/
public function getNaturalFeature()
{
return $this->naturalFeature;
}

/**
* @param null|string $naturalFeature
*/
public function withNaturalFeature(string $naturalFeature = null)
{
$new = clone $this;
$new->naturalFeature = $naturalFeature;

return $new;
}

/**
* @return null|string
*/
public function getNeighborhood()
{
return $this->neighborhood;
}

/**
* @param null|string $neighborhood
*/
public function withNeighborhood(string $neighborhood = null)
{
$new = clone $this;
$new->neighborhood = $neighborhood;

return $new;
}

/**
* @return null|string
*/
public function getPark()
{
return $this->park;
}

/**
* @param null|string $park
*/
public function withPark(string $park = null)
{
$new = clone $this;
$new->park = $park;

return $new;
}

/**
* @return null|string
*/
public function getPointOfInterest()
{
return $this->pointOfInterest;
}

/**
* @param null|string $pointOfInterest
*/
public function withPointOfInterest(string $pointOfInterest = null)
{
$new = clone $this;
$new->pointOfInterest = $pointOfInterest;

return $new;
}

/**
* @return null|string
*/
public function getPolitical()
{
return $this->political;
}

/**
* @param null|string $political
*/
public function withPolitical(string $political = null)
{
$new = clone $this;
$new->political = $political;

return $new;
}

/**
* @return null|string
*/
public function getPremise()
{
return $this->premise;
}

/**
* @param null|string $premise
*/
public function withPremise($premise = null)
{
$new = clone $this;
$new->premise = $premise;

return $new;
}

/**
* @return null|string
*/
public function getStreetAddress()
{
return $this->streetAddress;
}

/**
* @param null|string $streetAddress
*/
public function withStreetAddress(string $streetAddress = null)
{
$new = clone $this;
$new->streetAddress = $streetAddress;

return $new;
}

/**
* @return null|string
*/
Expand All @@ -118,4 +368,42 @@ public function withSubpremise(string $subpremise = null)

return $new;
}

/**
* @return null|string
*/
public function getWard()
{
return $this->ward;
}

/**
* @param null|string $ward
*/
public function withWard(string $ward = null)
{
$new = clone $this;
$new->ward = $ward;

return $new;
}

/**
* @return null|string
*/
public function getEstablishment()
{
return $this->establishment;
}

/**
* @param null|string $ward
*/
public function withEstablishment(string $establishment = null)
{
$new = clone $this;
$new->establishment = $establishment;

return $new;
}
}
Loading

0 comments on commit 3c69d9c

Please sign in to comment.