diff --git a/src/Provider/GoogleMaps/GoogleMaps.php b/src/Provider/GoogleMaps/GoogleMaps.php index 8ee5f0268..f7ef08fab 100644 --- a/src/Provider/GoogleMaps/GoogleMaps.php +++ b/src/Provider/GoogleMaps/GoogleMaps.php @@ -260,10 +260,10 @@ private function fetchUrl($url, $locale, $limit) /** @var GoogleAddress $address */ $address = $builder->build(GoogleAddress::class); if (isset($result->geometry->location_type)) { - $address->setLocationType($result->geometry->location_type); + $address = $address->withLocationType($result->geometry->location_type); } if (isset($result->types)) { - $address->setResultType($result->types); + $address = $address->withResultType($result->types); } $results[] = $address; diff --git a/src/Provider/GoogleMaps/Model/GoogleAddress.php b/src/Provider/GoogleMaps/Model/GoogleAddress.php index 145aef195..152b2a270 100644 --- a/src/Provider/GoogleMaps/Model/GoogleAddress.php +++ b/src/Provider/GoogleMaps/Model/GoogleAddress.php @@ -34,11 +34,12 @@ final class GoogleAddress extends Address * * @return GoogleAddress */ - public function setLocationType($locationType) + public function withLocationType($locationType) { - $this->locationType = $locationType; + $new = clone $this; + $new->locationType = $locationType; - return $this; + return $new; } /** @@ -62,10 +63,11 @@ public function getResultType() * * @return GoogleAddress */ - public function setResultType(array $resultType) + public function withResultType(array $resultType) { - $this->resultType = $resultType; + $new = clone $this; + $new->resultType = $resultType; - return $this; + return $new; } } diff --git a/src/Provider/Yandex/Model/YandexAddress.php b/src/Provider/Yandex/Model/YandexAddress.php index 946ffce52..200d8425d 100644 --- a/src/Provider/Yandex/Model/YandexAddress.php +++ b/src/Provider/Yandex/Model/YandexAddress.php @@ -44,11 +44,12 @@ public function getPrecision() * * @return YandexAddress */ - public function setPrecision($precision) + public function withPrecision($precision) { - $this->precision = $precision; + $new = clone $this; + $new->precision = $precision; - return $this; + return $new; } /** @@ -64,10 +65,11 @@ public function getName() * * @return YandexAddress */ - public function setName($name) + public function withName($name) { - $this->name = $name; + $new = clone $this; + $new->name = $name; - return $this; + return $new; } } diff --git a/src/Provider/Yandex/Yandex.php b/src/Provider/Yandex/Yandex.php index 941ec3a35..a7ae8e508 100644 --- a/src/Provider/Yandex/Yandex.php +++ b/src/Provider/Yandex/Yandex.php @@ -164,8 +164,8 @@ function ($value, $key) use (&$flatArray) { /** @var YandexAddress $location */ $location = $builder->build(YandexAddress::class); - $location->setPrecision(isset($flatArray['precision']) ? $flatArray['precision'] : null); - $location->setName(isset($flatArray['name']) ? $flatArray['name'] : null); + $location = $location->withPrecision(isset($flatArray['precision']) ? $flatArray['precision'] : null); + $location = $location->withName(isset($flatArray['name']) ? $flatArray['name'] : null); $locations[] = $location; }