Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4 from svityashchuk/master
Browse files Browse the repository at this point in the history
Fix infinity loop
  • Loading branch information
Bukashk0zzz authored Dec 1, 2017
2 parents 4af4bc3 + 627ee76 commit 7133f69
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/MapsPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,22 @@ public function getPlaceByPlaceId(string $placeId): ?Place
$obj->queryType = self::QUERY_TYPE_PLACE_ID;
$obj->query = $placeId;

return $this->getPlaceByObject($obj);
return $this->getPlaceByObject($obj, true);
}

/**
* @param string $address
*
* @return Place|null
* @param bool $checkByPoint
* @return null|Place
*/
public function getPlaceByAddress(string $address): ?Place
public function getPlaceByAddress(string $address, bool $checkByPoint = true): ?Place
{
$obj = clone $this;
$obj->queryType = self::QUERY_TYPE_ADDRESS;
$obj->query = $address;

return $this->getPlaceByObject($obj);
return $this->getPlaceByObject($obj, $checkByPoint);
}

/**
Expand All @@ -103,7 +104,7 @@ public function getPlaceByPoint(float $lat, float $lng): ?Place
{
$address = \sprintf('%f,%f', $lat, $lng);

return $this->getPlaceByAddress($address);
return $this->getPlaceByAddress($address, false);
}

/**
Expand Down Expand Up @@ -190,9 +191,10 @@ private function getValidatedCacheData(MapsPlace $obj): ?array

/**
* @param MapsPlace $obj
* @param bool $checkByPoint
* @return null|Place
*/
private function getPlaceByObject(MapsPlace $obj): ?Place
private function getPlaceByObject(MapsPlace $obj, bool $checkByPoint): ?Place
{
try {
$googleData = $this->getValidatedCacheData($obj);
Expand All @@ -204,7 +206,7 @@ private function getPlaceByObject(MapsPlace $obj): ?Place
|| $place->getStreet() !== null
|| $place->getStreetNumber() !== null;

if ($isComponentsUnderCityNotEmpty && $place->getCity() === null) {
if ($isComponentsUnderCityNotEmpty && $place->getCity() === null && $checkByPoint) {
$placeByPoint = $this->getPlaceByPoint($place->getLocationLat(), $place->getLocationLng());
$place->setCity($placeByPoint->getCity());
}
Expand Down

0 comments on commit 7133f69

Please sign in to comment.