From 58b6f504bb6d53823c6482119a1cd1c46b2729b5 Mon Sep 17 00:00:00 2001 From: Dimitar Dinchev Date: Sat, 1 Jul 2017 20:44:48 +0300 Subject: [PATCH 01/61] Mark ProviderAggregator as NOT final. --- ProviderAggregator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProviderAggregator.php b/ProviderAggregator.php index 75a9f458..04dd1cce 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -21,7 +21,7 @@ /** * @author William Durand */ -final class ProviderAggregator implements Geocoder +class ProviderAggregator implements Geocoder { /** * @var Provider[] From 6676e0a9fe1865076f91f013b1d3cdf4cbe1137a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 9 Jul 2017 16:51:20 +0200 Subject: [PATCH 02/61] Added a callable to decide what provider that should be used. (#731) * Added a callable to decide what provider that should be used. * Applied changes from StyleCI --- CHANGELOG.md | 10 +++++ ProviderAggregator.php | 47 +++++++++++++++------ Tests/ProviderAggregatorTest.php | 72 ++++++++++++++++++++------------ 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5501ff3..b21a298f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## Unreleased + +### Added + +- The constructor of `ProvierAggregator` will accept a callable that can decide what providers should be used for a specific query. + +### Changed + +- `ProvierAggregator::getProvider` is now private + ## 4.0.0 - Beta 2 ### Added diff --git a/ProviderAggregator.php b/ProviderAggregator.php index 04dd1cce..d36efa5c 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -38,12 +38,20 @@ class ProviderAggregator implements Geocoder */ private $limit; + /** + * A callable that decided what provider to use. + * + * @var callable + */ + private $decider; + /** * @param int $limit */ - public function __construct(int $limit = Geocoder::DEFAULT_RESULT_LIMIT) + public function __construct(int $limit = Geocoder::DEFAULT_RESULT_LIMIT, callable $decider = null) { $this->limit($limit); + $this->decider = $decider ?? __CLASS__.'::getProvider'; } /** @@ -51,7 +59,11 @@ public function __construct(int $limit = Geocoder::DEFAULT_RESULT_LIMIT) */ public function geocodeQuery(GeocodeQuery $query): Collection { - return $this->getProvider()->geocodeQuery($query); + if (null === $query->getLimit()) { + $query = $query->withLimit($this->limit); + } + + return call_user_func($this->decider, $query, $this->providers, $this->provider)->geocodeQuery($query); } /** @@ -59,7 +71,11 @@ public function geocodeQuery(GeocodeQuery $query): Collection */ public function reverseQuery(ReverseQuery $query): Collection { - return $this->getProvider()->reverseQuery($query); + if (null === $query->getLimit()) { + $query = $query->withLimit($this->limit); + } + + return call_user_func($this->decider, $query, $this->providers, $this->provider)->reverseQuery($query); } /** @@ -167,22 +183,29 @@ public function getProviders(): array } /** - * Returns the current provider in use. + * Get a provider to use for this query. + * + * @param GeocodeQuery|ReverseQuery $query + * @param Provider[] $providers + * @param Provider $currentProvider * * @return Provider * - * @throws \RuntimeException + * @throws ProviderNotRegistered */ - protected function getProvider(): Provider + private static function getProvider($query, array $providers, Provider $currentProvider = null): Provider { - if (null === $this->provider) { - if (0 === count($this->providers)) { - throw ProviderNotRegistered::noProviderRegistered(); - } + if (null !== $currentProvider) { + return $currentProvider; + } - $this->using(key($this->providers)); + if (0 === count($providers)) { + throw ProviderNotRegistered::noProviderRegistered(); } - return $this->provider; + // Take first + $key = key($providers); + + return $providers[$key]; } } diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index b3e41cb4..8f7c17f3 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -14,6 +14,8 @@ use Geocoder\Collection; use Geocoder\Geocoder; +use Geocoder\Model\Address; +use Geocoder\Model\AddressCollection; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; use Geocoder\ProviderAggregator; @@ -36,38 +38,49 @@ protected function setUp() $this->geocoder = new ProviderAggregator(); } - public function testRegisterProvider() + public function testGeocode() { - $provider = new MockProvider('test'); - $this->geocoder->registerProvider($provider); - - $this->assertSame($provider, NSA::invokeMethod($this->geocoder, 'getProvider')); - } + $provider1 = new MockProvider('test1'); + $provider1->result = [Address::createFromArray(['providedBy' => 'p1'])]; + $provider2 = new MockProvider('test2'); + $provider2->result = [Address::createFromArray(['providedBy' => 'p2'])]; - public function testRegisterProviders() - { - $provider = new MockProvider('test'); - $this->geocoder->registerProviders([$provider]); + $this->geocoder->registerProvider($provider1); + $this->geocoder->registerProvider($provider2); - $this->assertSame($provider, NSA::invokeMethod($this->geocoder, 'getProvider')); + $result = $this->geocoder->geocode('foo'); + $this->assertEquals('p1', $result->first()->getProvidedBy()); } - public function testUsing() + public function testReverse() { $provider1 = new MockProvider('test1'); + $provider1->result = [Address::createFromArray(['providedBy' => 'p1'])]; $provider2 = new MockProvider('test2'); - $this->geocoder->registerProviders([$provider1, $provider2]); + $provider2->result = [Address::createFromArray(['providedBy' => 'p2'])]; + + $this->geocoder->registerProvider($provider1); + $this->geocoder->registerProvider($provider2); + $this->geocoder->using('test2'); - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); + $result = $this->geocoder->reverse(0.1, 0.2); + $this->assertEquals('p2', $result->first()->getProvidedBy()); + } - $this->geocoder->using('test1'); - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); + public function testRegisterProvider() + { + $provider = new MockProvider('test'); + $this->geocoder->registerProvider($provider); - $this->geocoder->using('test2'); - $this->assertSame($provider2, NSA::invokeMethod($this->geocoder, 'getProvider')); + $this->assertSame(['test' => $provider], NSA::getProperty($this->geocoder, 'providers')); + } - $this->geocoder->using('test1'); - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); + public function testRegisterProviders() + { + $provider = new MockProvider('test'); + $this->geocoder->registerProviders([$provider]); + + $this->assertSame(['test' => $provider], NSA::getProperty($this->geocoder, 'providers')); } /** @@ -109,19 +122,21 @@ public function testGetProviders() */ public function testGetProvider() { - NSA::invokeMethod($this->geocoder, 'getProvider'); + NSA::invokeMethod($this->geocoder, 'getProvider', GeocodeQuery::create('foo'), [], null); $this->fail('getProvider() should throw an exception'); } public function testGetProviderWithMultipleProvidersReturnsTheFirstOne() { - $this->geocoder->registerProviders([ + $providers = [ $provider1 = new MockProvider('test1'), $provider2 = new MockProvider('test2'), $provider3 = new MockProvider('test3'), - ]); + ]; - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); + $query = GeocodeQuery::create('foo'); + $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider', $query, $providers, null)); + $this->assertSame($provider2, NSA::invokeMethod($this->geocoder, 'getProvider', $query, $providers, $provider2)); } public function testDefaultMaxResults() @@ -134,6 +149,8 @@ class MockProvider implements Provider { protected $name; + public $result = []; + public function __construct($name) { $this->name = $name; @@ -141,12 +158,12 @@ public function __construct($name) public function geocodeQuery(GeocodeQuery $query): Collection { - return $this->returnResult([]); + return $this->returnResult(); } public function reverseQuery(ReverseQuery $query): Collection { - return $this->returnResult([]); + return $this->returnResult(); } public function getName(): string @@ -163,7 +180,8 @@ public function limit($limit) return $this; } - public function returnResult(array $data = []) + private function returnResult() { + return new AddressCollection($this->result); } } From 8ba1066549c44fae8e59f9d242139af900518023 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 11 Jul 2017 18:41:21 +0200 Subject: [PATCH 03/61] Removed GetLimit (#736) --- CHANGELOG.md | 3 +++ ProviderAggregator.php | 27 ++++----------------------- Tests/ProviderAggregatorTest.php | 5 ----- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b21a298f..8d462abc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed - `ProvierAggregator::getProvider` is now private +- `ProvierAggregator::limit` was removed +- `ProvierAggregator::getLimit` was removed +- `ProvierAggregator::__constructor` changed the order of the parameters. ## 4.0.0 - Beta 2 diff --git a/ProviderAggregator.php b/ProviderAggregator.php index d36efa5c..38d63061 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -46,11 +46,12 @@ class ProviderAggregator implements Geocoder private $decider; /** - * @param int $limit + * @param callable|null $decider + * @param int $limit */ - public function __construct(int $limit = Geocoder::DEFAULT_RESULT_LIMIT, callable $decider = null) + public function __construct(callable $decider = null, int $limit = Geocoder::DEFAULT_RESULT_LIMIT) { - $this->limit($limit); + $this->limit = $limit; $this->decider = $decider ?? __CLASS__.'::getProvider'; } @@ -104,26 +105,6 @@ public function reverse(float $latitude, float $longitude): Collection ->withLimit($this->limit)); } - /** - * @param $limit - * - * @return $this - */ - public function limit(int $limit): self - { - $this->limit = $limit; - - return $this; - } - - /** - * @return int - */ - public function getLimit(): int - { - return $this->limit; - } - /** * Registers a new provider to the aggregator. * diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index 8f7c17f3..0f82a5a5 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -138,11 +138,6 @@ public function testGetProviderWithMultipleProvidersReturnsTheFirstOne() $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider', $query, $providers, null)); $this->assertSame($provider2, NSA::invokeMethod($this->geocoder, 'getProvider', $query, $providers, $provider2)); } - - public function testDefaultMaxResults() - { - $this->assertSame(Geocoder::DEFAULT_RESULT_LIMIT, $this->geocoder->getLimit()); - } } class MockProvider implements Provider From 5e28286c079fc34aedb48efdb8d5e334ee042a6f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 16 Jul 2017 14:46:23 +0200 Subject: [PATCH 04/61] Add withText and withCoordinates. --- Query/GeocodeQuery.php | 13 +++++++++++++ Query/ReverseQuery.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 699656cd..3343f9d7 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -70,6 +70,19 @@ public static function create(string $text): GeocodeQuery return new self($text); } + /** + * @param string $text + * + * @return GeocodeQuery + */ + public function withTest(string $text): GeocodeQuery + { + $new = clone $this; + $new->text = $text; + + return $new; + } + /** * @param Bounds $bounds * diff --git a/Query/ReverseQuery.php b/Query/ReverseQuery.php index 91d7c596..5f7b22a6 100644 --- a/Query/ReverseQuery.php +++ b/Query/ReverseQuery.php @@ -69,6 +69,19 @@ public static function fromCoordinates($latitude, $longitude): ReverseQuery return new self(new Coordinates($latitude, $longitude)); } + /** + * @param Coordinates $coordinates + * + * @return ReverseQuery + */ + public function withCoordinates(Coordinates $coordinates): ReverseQuery + { + $new = clone $this; + $new->coordinates = $coordinates; + + return $new; + } + /** * @param int $limit * From 71ca8e83e31e47fd3263f9635f5685ec423d4642 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 17 Jul 2017 11:17:59 +0200 Subject: [PATCH 05/61] Create interface for Query (#741) * Create interface for Query * Applied changes from StyleCI * Removed return type --- Query/GeocodeQuery.php | 2 +- Query/Query.php | 69 ++++++++++++++++++++++++++++++++++++++++++ Query/ReverseQuery.php | 2 +- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Query/Query.php diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 3343f9d7..7242edf1 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -19,7 +19,7 @@ /** * @author Tobias Nyholm */ -final class GeocodeQuery +final class GeocodeQuery implements Query { /** * The address or text that should be geocoded. diff --git a/Query/Query.php b/Query/Query.php new file mode 100644 index 00000000..41e3bee1 --- /dev/null +++ b/Query/Query.php @@ -0,0 +1,69 @@ + + */ +interface Query +{ + /** + * @param string $locale + * + * @return Query + */ + public function withLocale(string $locale); + + /** + * @param int $limit + * + * @return Query + */ + public function withLimit(int $limit); + + /** + * @param string $name + * @param mixed $value + * + * @return Query + */ + public function withData(string $name, $value); + + /** + * @return string|null + */ + public function getLocale(); + + /** + * @return int + */ + public function getLimit(): int; + + /** + * @param string $name + * @param mixed|null $default + * + * @return mixed + */ + public function getData(string $name, $default = null); + + /** + * @return array + */ + public function getAllData(): array; + + /** + * @return string + */ + public function __toString(); +} diff --git a/Query/ReverseQuery.php b/Query/ReverseQuery.php index 5f7b22a6..7c23c2a7 100644 --- a/Query/ReverseQuery.php +++ b/Query/ReverseQuery.php @@ -18,7 +18,7 @@ /** * @author Tobias Nyholm */ -final class ReverseQuery +final class ReverseQuery implements Query { /** * @var Coordinates From 0834bfe4a5a88513d063dfe0426416eac502e3db Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 17 Jul 2017 18:01:24 +0200 Subject: [PATCH 06/61] Fixed typo (#745) --- Query/GeocodeQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 7242edf1..277b3170 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -75,7 +75,7 @@ public static function create(string $text): GeocodeQuery * * @return GeocodeQuery */ - public function withTest(string $text): GeocodeQuery + public function withText(string $text): GeocodeQuery { $new = clone $this; $new->text = $text; From 9ebc8161e8313b3c888dd3c60a7cdd0a3e14170a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 1 Aug 2017 08:58:52 +0200 Subject: [PATCH 07/61] Updated changelogs --- CHANGELOG.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d462abc..4c383658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,25 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## Unreleased +## 4.0.0 + +No changes since Beta 5. + +## 4.0.0 - Beta 5 + +### Changed + +- `GeocodeQuery::withTest` was renamed to `GeocodeQuery::withText` + +## 4.0.0 - Beta 4 + +### Added + +- Add `GeocodeQuery::withText` and `ReverseQuery::withCoordinates`. +- Create interface for GeocodeQuery and ReverseQuery + +## 4.0.0 - Beta 3 + ### Added - The constructor of `ProvierAggregator` will accept a callable that can decide what providers should be used for a specific query. @@ -14,6 +33,8 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - `ProvierAggregator::limit` was removed - `ProvierAggregator::getLimit` was removed - `ProvierAggregator::__constructor` changed the order of the parameters. +- `ProvierAggregator` is not final. + ## 4.0.0 - Beta 2 From ab95b96f9c51054eed85287a09fa066d3684bc34 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 16 Sep 2017 12:20:13 +0200 Subject: [PATCH 08/61] Make sure we never use a country with name AND code as null (#768) * Make sure we never use a country with name AND code as null * cs * Bugfixes * Make sure one cannot create a country without data --- Formatter/StringFormatter.php | 11 ++++++++--- Model/Address.php | 20 ++++++++++++++++---- Model/Country.php | 8 ++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Formatter/StringFormatter.php b/Formatter/StringFormatter.php index 854c44e6..95adcf66 100644 --- a/Formatter/StringFormatter.php +++ b/Formatter/StringFormatter.php @@ -50,8 +50,13 @@ final class StringFormatter */ public function format(Location $location, string $format): string { - if (null !== $code = $location->getCountry()->getCode()) { - $code = strtoupper($code); + $countryName = null; + $code = null; + if (null !== $country = $location->getCountry()) { + $countryName = $country->getName(); + if (null !== $code = $country->getCode()) { + $code = strtoupper($code); + } } $replace = [ @@ -60,7 +65,7 @@ public function format(Location $location, string $format): string self::LOCALITY => $location->getLocality(), self::POSTAL_CODE => $location->getPostalCode(), self::SUB_LOCALITY => $location->getSubLocality(), - self::COUNTRY => $location->getCountry()->getName(), + self::COUNTRY => $countryName, self::COUNTRY_CODE => $code, self::TIMEZONE => $location->getTimezone(), ]; diff --git a/Model/Address.php b/Model/Address.php index 544d199d..27237f45 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -265,10 +265,7 @@ public static function createFromArray(array $data) $data['postalCode'], $data['locality'], $data['subLocality'], - new Country( - $data['country'], - $data['countryCode'] - ), + self::createCountry($data['country'], $data['countryCode']), $data['timezone'] ); } @@ -288,6 +285,21 @@ private static function createCoordinates($latitude, $longitude) return new Coordinates($latitude, $longitude); } + /** + * @param string|null $name + * @param string|null $code + * + * @return Country|null + */ + private static function createCountry($name, $code) + { + if (null === $name && null === $code) { + return null; + } + + return new Country($name, $code); + } + /** * @param float $south * @param float $west diff --git a/Model/Country.php b/Model/Country.php index dcbf3d92..6230e323 100644 --- a/Model/Country.php +++ b/Model/Country.php @@ -12,7 +12,11 @@ namespace Geocoder\Model; +use Geocoder\Exception\InvalidArgument; + /** + * A Country has either a name or a code. A Country will never be without data. + * * @author William Durand */ final class Country @@ -33,6 +37,10 @@ final class Country */ public function __construct(string $name = null, string $code = null) { + if (null === $name && null === $code) { + throw new InvalidArgument('A country must have either a name or a code'); + } + $this->name = $name; $this->code = $code; } From 6bb7a1d8d3b4f21d7947402da44bad55f8cb5f18 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 16 Sep 2017 12:25:29 +0200 Subject: [PATCH 09/61] Update requirements to support Country not being null --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0af87bf6..a9d44a75 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ }, "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "4.1-dev" } } } From f800c81b914eda02ee41233e1efbeeabca2d237c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 16 Sep 2017 12:29:39 +0200 Subject: [PATCH 10/61] Updated branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0af87bf6..a9d44a75 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ }, "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "4.1-dev" } } } From d5b6de9c79e676fd7f278615b58e3849df71d4ca Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 16 Sep 2017 15:21:54 +0200 Subject: [PATCH 11/61] Added changelogs --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c383658..62c2e647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## Unreleased +## 4.1.0 + +### Changed + +- Make sure a `Country` never will be empty of data. + ## 4.0.0 No changes since Beta 5. From ee5b997b528087e2134eed7d8fa1c24d04d2d723 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 6 Oct 2017 09:25:36 -0400 Subject: [PATCH 12/61] Fix phpunit version to 6.3.* This will fix the build error. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a9d44a75..85648860 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^6.1", + "phpunit/phpunit": "6.3.*", "symfony/stopwatch": "~2.5", "nyholm/nsa": "^1.1" }, From 6498c797f65d360107c2df6aea50ebdd1483da3c Mon Sep 17 00:00:00 2001 From: Leevi Graham Date: Wed, 22 Nov 2017 12:14:34 +1100 Subject: [PATCH 13/61] StyleCi fixes As reported: https://styleci.io/analyses/qxKNJB in PR: https://github.com/geocoder-php/Geocoder/pull/798 --- Exception/InvalidServerResponse.php | 4 ++-- Query/GeocodeQuery.php | 12 ++++++------ Query/ReverseQuery.php | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Exception/InvalidServerResponse.php b/Exception/InvalidServerResponse.php index 19f38e0b..3c2dc519 100644 --- a/Exception/InvalidServerResponse.php +++ b/Exception/InvalidServerResponse.php @@ -25,7 +25,7 @@ final class InvalidServerResponse extends \RuntimeException implements Exception * * @return InvalidServerResponse */ - public static function create(string $query, int $code = 0): InvalidServerResponse + public static function create(string $query, int $code = 0): self { return new self(sprintf('The geocoder server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query)); } @@ -35,7 +35,7 @@ public static function create(string $query, int $code = 0): InvalidServerRespon * * @return InvalidServerResponse */ - public static function emptyResponse(string $query): InvalidServerResponse + public static function emptyResponse(string $query): self { return new self(sprintf('The geocoder server returned an empty response for query "%s".', $query)); } diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 277b3170..46be7ed1 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -65,7 +65,7 @@ private function __construct(string $text) * * @return GeocodeQuery */ - public static function create(string $text): GeocodeQuery + public static function create(string $text): self { return new self($text); } @@ -75,7 +75,7 @@ public static function create(string $text): GeocodeQuery * * @return GeocodeQuery */ - public function withText(string $text): GeocodeQuery + public function withText(string $text): self { $new = clone $this; $new->text = $text; @@ -88,7 +88,7 @@ public function withText(string $text): GeocodeQuery * * @return GeocodeQuery */ - public function withBounds(Bounds $bounds): GeocodeQuery + public function withBounds(Bounds $bounds): self { $new = clone $this; $new->bounds = $bounds; @@ -101,7 +101,7 @@ public function withBounds(Bounds $bounds): GeocodeQuery * * @return GeocodeQuery */ - public function withLocale(string $locale): GeocodeQuery + public function withLocale(string $locale): self { $new = clone $this; $new->locale = $locale; @@ -114,7 +114,7 @@ public function withLocale(string $locale): GeocodeQuery * * @return GeocodeQuery */ - public function withLimit(int $limit): GeocodeQuery + public function withLimit(int $limit): self { $new = clone $this; $new->limit = $limit; @@ -128,7 +128,7 @@ public function withLimit(int $limit): GeocodeQuery * * @return GeocodeQuery */ - public function withData(string $name, $value): GeocodeQuery + public function withData(string $name, $value): self { $new = clone $this; $new->data[$name] = $value; diff --git a/Query/ReverseQuery.php b/Query/ReverseQuery.php index 7c23c2a7..548867ad 100644 --- a/Query/ReverseQuery.php +++ b/Query/ReverseQuery.php @@ -64,7 +64,7 @@ public static function create(Coordinates $coordinates) * * @return ReverseQuery */ - public static function fromCoordinates($latitude, $longitude): ReverseQuery + public static function fromCoordinates($latitude, $longitude): self { return new self(new Coordinates($latitude, $longitude)); } @@ -74,7 +74,7 @@ public static function fromCoordinates($latitude, $longitude): ReverseQuery * * @return ReverseQuery */ - public function withCoordinates(Coordinates $coordinates): ReverseQuery + public function withCoordinates(Coordinates $coordinates): self { $new = clone $this; $new->coordinates = $coordinates; @@ -87,7 +87,7 @@ public function withCoordinates(Coordinates $coordinates): ReverseQuery * * @return ReverseQuery */ - public function withLimit(int $limit): ReverseQuery + public function withLimit(int $limit): self { $new = clone $this; $new->limit = $limit; @@ -100,7 +100,7 @@ public function withLimit(int $limit): ReverseQuery * * @return ReverseQuery */ - public function withLocale(string $locale): ReverseQuery + public function withLocale(string $locale): self { $new = clone $this; $new->locale = $locale; @@ -114,7 +114,7 @@ public function withLocale(string $locale): ReverseQuery * * @return ReverseQuery */ - public function withData(string $name, $value): ReverseQuery + public function withData(string $name, $value): self { $new = clone $this; $new->data[$name] = $value; From 2b5953b28c10d0d9c9c33274d777aa64a28a92c5 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 14 Dec 2017 10:46:36 +0000 Subject: [PATCH 14/61] Apply fixes from StyleCI --- Geocoder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Geocoder.php b/Geocoder.php index 85c825cc..d52e1f3b 100644 --- a/Geocoder.php +++ b/Geocoder.php @@ -23,6 +23,7 @@ interface Geocoder extends Provider * Version of this package. */ const MAJOR_VERSION = 4; + const VERSION = '4.0'; /** From b6128b86348453654b9604d28b270891a7a5e2c3 Mon Sep 17 00:00:00 2001 From: Bas Date: Fri, 9 Feb 2018 17:46:56 +0100 Subject: [PATCH 15/61] Add Coordinates::toArray (#817) * Add Coordinates::toArray * lint * Flip lat, long to long lat --- Model/Coordinates.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Model/Coordinates.php b/Model/Coordinates.php index f346a298..7969af5f 100644 --- a/Model/Coordinates.php +++ b/Model/Coordinates.php @@ -67,4 +67,14 @@ public function getLongitude(): float { return $this->longitude; } + + /** + * Returns the coordinates as a tuple + * + * @return array + */ + public function toArray(): array + { + return [$this->getLongitude(), $this->getLatitude()]; + } } From 3bc807da0e581a9ed4c2251e291ee9804cd80278 Mon Sep 17 00:00:00 2001 From: Stadly Date: Fri, 9 Feb 2018 17:57:11 +0100 Subject: [PATCH 16/61] Use the returned query after setting bounds or locale (#815) After choosing to use bounds or locale with a query, the returned query object must be used. --- StatefulGeocoder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/StatefulGeocoder.php b/StatefulGeocoder.php index 400f20df..e618b25b 100644 --- a/StatefulGeocoder.php +++ b/StatefulGeocoder.php @@ -62,11 +62,11 @@ public function geocode(string $value): Collection ->withLimit($this->limit); if (!empty($this->locale)) { - $query->withLocale($this->locale); + $query = $query->withLocale($this->locale); } if (!empty($this->bounds)) { - $query->withBounds($this->bounds); + $query = $query->withBounds($this->bounds); } return $this->provider->geocodeQuery($query); @@ -112,7 +112,7 @@ public function reverseQuery(ReverseQuery $query): Collection { $locale = $query->getLocale(); if (empty($locale) && null !== $this->locale) { - $query->withLocale($this->locale); + $query = $query->withLocale($this->locale); } return $this->provider->reverseQuery($query); From 78437899e849516958eec98b5e628e1c096418ee Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 10 Feb 2018 14:22:58 +0100 Subject: [PATCH 17/61] Added changelog for php-common (#821) --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62c2e647..6b3de1e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## Unreleased +## 4.2.0 + +### Added + +- Add `Coordinates::toArray` + +### Fixed + +- Bug in `StatefulGeocoder` where different locale or bounds did not have any effect. + ## 4.1.0 ### Changed From 69c1e7f562c3bfc60ea1722a0d0bed5197e23499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 10 Mar 2018 00:11:43 +0200 Subject: [PATCH 18/61] common/readme: fix subtreesplit link (#836) --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 41581ff7..caa39c14 100644 --- a/Readme.md +++ b/Readme.md @@ -18,7 +18,7 @@ Just some months before the release of 4.0 of `willdurand/geocoder` we changed t from https://github.com/geocoder-php/Geocoder. The new repository will only contain classes and interfaces shared between multiple providers. The original repository is still used for issues and pull requests. -The new repository architecture allows us to use a [git subtree split](www.subtreesplit.com) from geocoder-php/Geocoder +The new repository architecture allows us to use a [git subtree split](https://www.subtreesplit.com) from geocoder-php/Geocoder to geocoder-php/php-common and to each provider. Versions before 4.0 `willdurand/geocoder` will still work as usual, but with the new repository. From 694221b2687f27a9a9f2971b5480a601cddd362b Mon Sep 17 00:00:00 2001 From: Damien Alexandre Date: Tue, 27 Nov 2018 11:35:12 +0100 Subject: [PATCH 19/61] Fix Mapbox Query build when there is Bound (#906) --- Model/Bounds.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/Bounds.php b/Model/Bounds.php index 52d91b2b..02f01740 100644 --- a/Model/Bounds.php +++ b/Model/Bounds.php @@ -40,10 +40,10 @@ final class Bounds private $east; /** - * @param float $south - * @param float $west - * @param float $north - * @param float $east + * @param float $south South bound, also min latitude + * @param float $west West bound, also min longitude + * @param float $north North bound, also max latitude + * @param float $east East bound, also max longitude */ public function __construct($south, $west, $north, $east) { From 11dde59175441ff4bee306f05a545dcc0b182607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Fri, 30 Nov 2018 09:29:52 +0100 Subject: [PATCH 20/61] Update AddressBuilder.php (#910) Fix #909 --- Model/AddressBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/AddressBuilder.php b/Model/AddressBuilder.php index 28301515..5695f6d6 100644 --- a/Model/AddressBuilder.php +++ b/Model/AddressBuilder.php @@ -109,7 +109,7 @@ public function build(string $class = Address::class): Address } $country = null; - if (!empty($this->country) || !empty($this->country)) { + if (!empty($this->country) || !empty($this->countryCode)) { $country = new Country($this->country, $this->countryCode); } From 965b91f6454fe2ceaaf69a5b1c88835864ea7c50 Mon Sep 17 00:00:00 2001 From: Eugene Kurasov Date: Wed, 26 Dec 2018 14:01:09 +0200 Subject: [PATCH 21/61] [Common] Update CHANGELOG.md (#925) --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b3de1e2..3e991d5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## Unreleased +## 4.2.1 + +### Fixed +- Bug in `AddressBuilder` where same expression is compare twice + ## 4.2.0 ### Added From ede5e37259591e4ed80296dc68b5e5ec9953b654 Mon Sep 17 00:00:00 2001 From: Dan Hunsaker Date: Sat, 5 Jan 2019 08:19:52 -0700 Subject: [PATCH 22/61] Mark GeoJson dumper as Dumper implementation (#926) --- Dumper/GeoJson.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dumper/GeoJson.php b/Dumper/GeoJson.php index c992be8f..d9a1a103 100644 --- a/Dumper/GeoJson.php +++ b/Dumper/GeoJson.php @@ -17,7 +17,7 @@ /** * @author Jan Sorgalla */ -final class GeoJson extends AbstractArrayDumper +final class GeoJson extends AbstractArrayDumper implements Dumper { /** * {@inheritdoc} From 7feb507d1ce715ff605e1e10e2050745d532e25c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 5 Jan 2019 19:19:45 +0100 Subject: [PATCH 23/61] Remove nyholm/psr7 from require-dev (#928) * Remove nyholm/psr7 from require-dev * cs --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 96ffe283..d855704f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php sudo: false -php: 7.0 +php: 7.2 install: - composer update --prefer-stable --prefer-dist From eb49ea6b9490e8541cc6155c44f2be590bdbbb84 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 6 Feb 2019 13:18:09 +0100 Subject: [PATCH 24/61] Make sure we dont include multiple vendor folders (#934) * Make sure we dont include multiple vendor folders * Require discovery 1.6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 85648860..0dd7be86 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "6.3.*", + "phpunit/phpunit": "^6.5 || ^7.5", "symfony/stopwatch": "~2.5", "nyholm/nsa": "^1.1" }, From 7d4068330d08ae8213c965c5800e7b891c891d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Nork=C5=ABnas?= Date: Mon, 21 Oct 2019 08:47:18 +0300 Subject: [PATCH 25/61] Fix building ProviderNotRegistered exception message (#1020) --- ProviderAggregator.php | 2 +- Tests/ProviderAggregatorTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ProviderAggregator.php b/ProviderAggregator.php index 38d63061..b9fb75bd 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -145,7 +145,7 @@ public function registerProviders(array $providers = []): self public function using(string $name): self { if (!isset($this->providers[$name])) { - throw ProviderNotRegistered::create($name ?? '', $this->providers); + throw ProviderNotRegistered::create($name, array_keys($this->providers)); } $this->provider = $this->providers[$name]; diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index 0f82a5a5..2a125045 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -85,9 +85,12 @@ public function testRegisterProviders() /** * @expectedException \Geocoder\Exception\ProviderNotRegistered + * @expectedExceptionMessage Provider "non_existant" is not registered, so you cannot use it. Did you forget to register it or made a typo? Registered providers are: test1. */ public function testUsingNonExistantProviderShouldThrowAnException() { + $this->geocoder->registerProvider(new MockProvider('test1')); + $this->geocoder->using('non_existant'); } From 7c80fd433fc1eaf297697bd2de84ba10c9d13dd7 Mon Sep 17 00:00:00 2001 From: atymic Date: Sat, 2 Nov 2019 09:27:06 +1100 Subject: [PATCH 26/61] docs: update google maps code in readme (#1030) * docs: update google maps code in readme * fix: throw exception if API key is not provided * fix: tests * docs: update google maps docs --- Tests/ProviderAggregatorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index 2a125045..382fee9c 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -13,7 +13,6 @@ namespace Geocoder\Tests; use Geocoder\Collection; -use Geocoder\Geocoder; use Geocoder\Model\Address; use Geocoder\Model\AddressCollection; use Geocoder\Query\GeocodeQuery; From 28ea72652dc87fe5b20d51efb0582c171a342690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Tue, 12 Nov 2019 10:26:59 +0100 Subject: [PATCH 27/61] Apply fixes from StyleCI (#1033) --- Assert.php | 4 +--- Model/AdminLevelCollection.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Assert.php b/Assert.php index 489c8b92..5f21534a 100644 --- a/Assert.php +++ b/Assert.php @@ -63,9 +63,7 @@ private static function typeToString($value): string private static function float($value, string $message) { if (!is_float($value)) { - throw new InvalidArgument( - sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value)) - ); + throw new InvalidArgument(sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value))); } } } diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index ecb71aca..8b7c23cc 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -132,9 +132,7 @@ public function all(): array private function checkLevel(int $level) { if ($level <= 0 || $level > self::MAX_LEVEL_DEPTH) { - throw new OutOfBounds( - sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level) - ); + throw new OutOfBounds(sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level)); } } } From 693fff13e919e46bebb06c52766138470cdaf00c Mon Sep 17 00:00:00 2001 From: Maxime Helias Date: Fri, 13 Dec 2019 09:42:18 +0100 Subject: [PATCH 28/61] Exception interface should extend Throwable interface (#1027) --- Exception/Exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exception/Exception.php b/Exception/Exception.php index 1600333c..8d905481 100644 --- a/Exception/Exception.php +++ b/Exception/Exception.php @@ -15,6 +15,6 @@ /** * @author William Durand */ -interface Exception +interface Exception extends \Throwable { } From 816d5e20f6a000abc9b36db6dc3a30a3fa6695f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Wed, 22 Jan 2020 10:02:24 +0100 Subject: [PATCH 29/61] Update CHANGELOG.md --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e991d5e..f2aebc53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,21 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## Unreleased +## 4.2.2 + +### Changed + +- GeoJson dumper implements Dumper +- Excpetion interface extends Throwable + +### Fixed + +- Fix building ProviderNotRegistered exception message ## 4.2.1 ### Fixed + - Bug in `AddressBuilder` where same expression is compare twice ## 4.2.0 From 5226cfbceaf036c2f19b46b2bf9f191fe7fa433d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Wed, 27 May 2020 08:20:31 +0200 Subject: [PATCH 30/61] Apply fixes from StyleCI (#1060) --- Exception/FunctionNotFound.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Exception/FunctionNotFound.php b/Exception/FunctionNotFound.php index a4ba0f60..8fe68935 100644 --- a/Exception/FunctionNotFound.php +++ b/Exception/FunctionNotFound.php @@ -23,7 +23,8 @@ final class FunctionNotFound extends \RuntimeException implements Exception */ public function __construct(string $functionName, $description = null) { - parent::__construct(sprintf('The function "%s" cannot be found. %s', + parent::__construct(sprintf( + 'The function "%s" cannot be found. %s', $functionName, null !== $description ? sprintf(' %s', $description) : '' )); From 30005fcfaa7f3728a6840ae587aeed22ea7c568b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 4 Jul 2020 10:05:10 +0200 Subject: [PATCH 31/61] Drop support for PHP 7.0 and PHP 7.1 (End of life) (#1068) * Drop support for PHP < 7.2 in composer.json * Update .travis.yml Drop PHP 7.0 abd 7.1 Add PHP 7.4 * Normalize composer.json files Using composer-normalize * Normalize composer.json files (1) Using composer-normalize * Fix TomTom testReverseError400 - Will return JSON instead of XML ; - If API error, returns empty address collection ; * Apply fixes from StyleCI * Upgrade to PHPUnit 7 + Upgrade `nyholm/psr7` * Normalize providers Travis config --- .travis.yml | 2 +- composer.json | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index d855704f..7e91c31d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ sudo: false php: 7.2 install: - - composer update --prefer-stable --prefer-dist + - composer update --prefer-stable --prefer-dist script: - composer test-ci diff --git a/composer.json b/composer.json index 0dd7be86..7e89162b 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,12 @@ "name": "willdurand/geocoder", "type": "library", "description": "Common files for PHP Geocoder", - "keywords": ["geocoder", "geocoding", "abstraction", "geoip"], + "keywords": [ + "geocoder", + "geocoding", + "abstraction", + "geoip" + ], "homepage": "http://geocoder-php.org", "license": "MIT", "authors": [ @@ -12,18 +17,25 @@ } ], "require": { - "php": "^7.0" + "php": "^7.2" }, "require-dev": { - "phpunit/phpunit": "^6.5 || ^7.5", - "symfony/stopwatch": "~2.5", - "nyholm/nsa": "^1.1" + "nyholm/nsa": "^1.1", + "phpunit/phpunit": "^7.5", + "symfony/stopwatch": "~2.5" }, "suggest": { "symfony/stopwatch": "If you want to use the TimedGeocoder" }, + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, "autoload": { - "psr-4": { "Geocoder\\": "" }, + "psr-4": { + "Geocoder\\": "" + }, "exclude-from-classmap": [ "/Tests/" ] @@ -31,10 +43,5 @@ "scripts": { "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" - }, - "extra": { - "branch-alias": { - "dev-master": "4.1-dev" - } } -} +} \ No newline at end of file From 11b28f1054e81383baa24076885fb10d2b442596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 4 Jul 2020 11:17:42 +0200 Subject: [PATCH 32/61] Remove deprecated `sudo` key in Travis CI config files. (#1072) See https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7e91c31d..251286c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: php -sudo: false php: 7.2 From dc9b6a1fe0c4b5f68c545fcf89f65231d45bdf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 4 Jul 2020 15:18:10 +0200 Subject: [PATCH 33/61] Update CHANGELOG for new minor releases (#1074) --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2aebc53..92197deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 4.3.0 + +### Removed + +- Drop support for PHP < 7.2 + ## 4.2.2 ### Changed From 7cf1b1cea0f8e42e5d2d43b8dae0bde295d0da0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Thu, 8 Oct 2020 22:27:03 +0200 Subject: [PATCH 34/61] Fix StyleCI (#1084) * Update .styleci.yml * Apply StyleCI fix * Update .styleci.yml * Apply StyleCI fix * Apply StyleCI fix --- Model/AddressBuilder.php | 16 ++++++++-------- Model/Coordinates.php | 2 +- Query/GeocodeQuery.php | 2 +- Query/ReverseQuery.php | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Model/AddressBuilder.php b/Model/AddressBuilder.php index 5695f6d6..23847079 100644 --- a/Model/AddressBuilder.php +++ b/Model/AddressBuilder.php @@ -179,7 +179,7 @@ public function addAdminLevel(int $level, string $name, string $code = null): se } /** - * @param null|string $streetNumber + * @param string|null $streetNumber * * @return AddressBuilder */ @@ -191,7 +191,7 @@ public function setStreetNumber($streetNumber): self } /** - * @param null|string $streetName + * @param string|null $streetName * * @return AddressBuilder */ @@ -203,7 +203,7 @@ public function setStreetName($streetName): self } /** - * @param null|string $locality + * @param string|null $locality * * @return AddressBuilder */ @@ -215,7 +215,7 @@ public function setLocality($locality): self } /** - * @param null|string $postalCode + * @param string|null $postalCode * * @return AddressBuilder */ @@ -227,7 +227,7 @@ public function setPostalCode($postalCode): self } /** - * @param null|string $subLocality + * @param string|null $subLocality * * @return AddressBuilder */ @@ -251,7 +251,7 @@ public function setAdminLevels($adminLevels): self } /** - * @param null|string $country + * @param string|null $country * * @return AddressBuilder */ @@ -263,7 +263,7 @@ public function setCountry($country): self } /** - * @param null|string $countryCode + * @param string|null $countryCode * * @return AddressBuilder */ @@ -275,7 +275,7 @@ public function setCountryCode($countryCode): self } /** - * @param null|string $timezone + * @param string|null $timezone * * @return AddressBuilder */ diff --git a/Model/Coordinates.php b/Model/Coordinates.php index 7969af5f..3821af43 100644 --- a/Model/Coordinates.php +++ b/Model/Coordinates.php @@ -69,7 +69,7 @@ public function getLongitude(): float } /** - * Returns the coordinates as a tuple + * Returns the coordinates as a tuple. * * @return array */ diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 46be7ed1..0533ed0c 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -192,7 +192,7 @@ public function getAllData(): array } /** - * String for logging. This is also a unique key for the query + * String for logging. This is also a unique key for the query. * * @return string */ diff --git a/Query/ReverseQuery.php b/Query/ReverseQuery.php index 548867ad..50e92c4d 100644 --- a/Query/ReverseQuery.php +++ b/Query/ReverseQuery.php @@ -170,7 +170,7 @@ public function getAllData(): array } /** - * String for logging. This is also a unique key for the query + * String for logging. This is also a unique key for the query. * * @return string */ From ee095b3e4dafc4320b56863d5401bfc9843a9ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 29 Nov 2020 11:04:09 +0100 Subject: [PATCH 35/61] Apply fixes from StyleCI (#1097) --- Model/AdminLevelCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index 8b7c23cc..cedd203e 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -113,7 +113,7 @@ public function get(int $level): AdminLevel throw new InvalidArgument(sprintf('Administrative level %d is not set for this address', $level)); } - return $this->adminLevels[$level]; + return $this->adminLevels[$level]; } /** From 86aeec661eb6234b886c0aafeac4bcd67445b1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 19 Dec 2020 10:41:04 +0100 Subject: [PATCH 36/61] Enable PHP 8.0 support (#1102) * Enable PHP 8.0 support * Add GitHub Actions * Upgrade php-http/curl-client + php-http/httplug * Upgrade PHPUnit * Drop PHP 7.2 support * Update GitHub Actions Remove PHP 7.2 * Update Travis CI Remove PHP 7.2 * Drop PHP 7.2 support --- Tests/Dumper/GeoArrayTest.php | 10 +++++----- Tests/Dumper/GeoJsonTest.php | 2 +- Tests/Dumper/GpxTest.php | 2 +- Tests/Dumper/KmlTest.php | 2 +- Tests/Dumper/WkbTest.php | 2 +- Tests/Dumper/WktTest.php | 2 +- Tests/Formatter/StringFormatterTest.php | 2 +- Tests/Model/AddressCollectionTest.php | 2 ++ Tests/ProviderAggregatorTest.php | 19 ++++++++----------- Tests/Query/GeocodeQueryTest.php | 10 +++++----- Tests/Query/ReverseQueryTest.php | 12 ++++++------ Tests/TimedGeocoderTest.php | 2 +- composer.json | 2 +- 13 files changed, 34 insertions(+), 35 deletions(-) diff --git a/Tests/Dumper/GeoArrayTest.php b/Tests/Dumper/GeoArrayTest.php index 252955cc..800d239d 100644 --- a/Tests/Dumper/GeoArrayTest.php +++ b/Tests/Dumper/GeoArrayTest.php @@ -26,7 +26,7 @@ class GeoArrayTest extends TestCase */ private $dumper; - protected function setUp() + protected function setUp(): void { $this->dumper = new GeoArray(); } @@ -47,7 +47,7 @@ public function testDump() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } @@ -71,7 +71,7 @@ public function testDumpWithData() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } @@ -107,7 +107,7 @@ public function testDumpWithBounds() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } @@ -147,7 +147,7 @@ public function testDumpWithProperties() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } } diff --git a/Tests/Dumper/GeoJsonTest.php b/Tests/Dumper/GeoJsonTest.php index 9e745a8e..eee43a08 100644 --- a/Tests/Dumper/GeoJsonTest.php +++ b/Tests/Dumper/GeoJsonTest.php @@ -27,7 +27,7 @@ class GeoJsonTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new GeoJson(); } diff --git a/Tests/Dumper/GpxTest.php b/Tests/Dumper/GpxTest.php index f72c70c0..297cdaf1 100644 --- a/Tests/Dumper/GpxTest.php +++ b/Tests/Dumper/GpxTest.php @@ -27,7 +27,7 @@ class GpxTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Gpx(); } diff --git a/Tests/Dumper/KmlTest.php b/Tests/Dumper/KmlTest.php index 2870acff..7d1331c0 100644 --- a/Tests/Dumper/KmlTest.php +++ b/Tests/Dumper/KmlTest.php @@ -27,7 +27,7 @@ class KmlTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Kml(); } diff --git a/Tests/Dumper/WkbTest.php b/Tests/Dumper/WkbTest.php index 325fa4bb..4808632f 100644 --- a/Tests/Dumper/WkbTest.php +++ b/Tests/Dumper/WkbTest.php @@ -27,7 +27,7 @@ class WkbTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Wkb(); } diff --git a/Tests/Dumper/WktTest.php b/Tests/Dumper/WktTest.php index 6a44ac01..8a135c5b 100644 --- a/Tests/Dumper/WktTest.php +++ b/Tests/Dumper/WktTest.php @@ -27,7 +27,7 @@ class WktTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Wkt(); } diff --git a/Tests/Formatter/StringFormatterTest.php b/Tests/Formatter/StringFormatterTest.php index 9e83bffe..89b9c3da 100644 --- a/Tests/Formatter/StringFormatterTest.php +++ b/Tests/Formatter/StringFormatterTest.php @@ -26,7 +26,7 @@ class StringFormatterTest extends TestCase */ private $formatter; - public function setUp() + public function setUp(): void { $this->formatter = new StringFormatter(); } diff --git a/Tests/Model/AddressCollectionTest.php b/Tests/Model/AddressCollectionTest.php index 842d4e3a..6981119f 100644 --- a/Tests/Model/AddressCollectionTest.php +++ b/Tests/Model/AddressCollectionTest.php @@ -25,6 +25,8 @@ class AddressCollectionTest extends TestCase */ public function testFirstOnEmpty() { + $this->expectException(\Geocoder\Exception\CollectionIsEmpty::class); + $collection = new AddressCollection([]); $collection->first(); } diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index 382fee9c..ebea95c4 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -32,7 +32,7 @@ class ProviderAggregatorTest extends TestCase */ protected $geocoder; - protected function setUp() + protected function setUp(): void { $this->geocoder = new ProviderAggregator(); } @@ -82,22 +82,20 @@ public function testRegisterProviders() $this->assertSame(['test' => $provider], NSA::getProperty($this->geocoder, 'providers')); } - /** - * @expectedException \Geocoder\Exception\ProviderNotRegistered - * @expectedExceptionMessage Provider "non_existant" is not registered, so you cannot use it. Did you forget to register it or made a typo? Registered providers are: test1. - */ public function testUsingNonExistantProviderShouldThrowAnException() { + $this->expectException(\Geocoder\Exception\ProviderNotRegistered::class); + $this->expectExceptionMessage('Provider "non_existant" is not registered, so you cannot use it. Did you forget to register it or made a typo? Registered providers are: test1.'); + $this->geocoder->registerProvider(new MockProvider('test1')); $this->geocoder->using('non_existant'); } - /** - * @expectedException \Geocoder\Exception\ProviderNotRegistered - */ public function testUsingAnEmptyProviderNameShouldThrowAnException() { + $this->expectException(\Geocoder\Exception\ProviderNotRegistered::class); + $this->geocoder->using(''); } @@ -119,11 +117,10 @@ public function testGetProviders() $this->assertArrayHasKey('test2', $result); } - /** - * @expectedException \RuntimeException - */ public function testGetProvider() { + $this->expectException(\RuntimeException::class); + NSA::invokeMethod($this->geocoder, 'getProvider', GeocodeQuery::create('foo'), [], null); $this->fail('getProvider() should throw an exception'); } diff --git a/Tests/Query/GeocodeQueryTest.php b/Tests/Query/GeocodeQueryTest.php index 60e4fa2c..c14f3481 100644 --- a/Tests/Query/GeocodeQueryTest.php +++ b/Tests/Query/GeocodeQueryTest.php @@ -26,10 +26,10 @@ public function testToString() $query = $query->withData('name', 'value'); $string = $query->__toString(); - $this->assertContains('GeocodeQuery', $string); - $this->assertContains('"text":"foo"', $string); - $this->assertContains('"locale":"en"', $string); - $this->assertContains('"limit":3', $string); - $this->assertContains('"name":"value"', $string); + $this->assertStringContainsString('GeocodeQuery', $string); + $this->assertStringContainsString('"text":"foo"', $string); + $this->assertStringContainsString('"locale":"en"', $string); + $this->assertStringContainsString('"limit":3', $string); + $this->assertStringContainsString('"name":"value"', $string); } } diff --git a/Tests/Query/ReverseQueryTest.php b/Tests/Query/ReverseQueryTest.php index 40272588..9bb815e0 100644 --- a/Tests/Query/ReverseQueryTest.php +++ b/Tests/Query/ReverseQueryTest.php @@ -26,11 +26,11 @@ public function testToString() $query = $query->withData('name', 'value'); $string = $query->__toString(); - $this->assertContains('ReverseQuery', $string); - $this->assertContains('"lat":1', $string); - $this->assertContains('"lng":2', $string); - $this->assertContains('"locale":"en"', $string); - $this->assertContains('"limit":3', $string); - $this->assertContains('"name":"value"', $string); + $this->assertStringContainsString('ReverseQuery', $string); + $this->assertStringContainsString('"lat":1', $string); + $this->assertStringContainsString('"lng":2', $string); + $this->assertStringContainsString('"locale":"en"', $string); + $this->assertStringContainsString('"limit":3', $string); + $this->assertStringContainsString('"name":"value"', $string); } } diff --git a/Tests/TimedGeocoderTest.php b/Tests/TimedGeocoderTest.php index 438a0f97..c46a82fb 100644 --- a/Tests/TimedGeocoderTest.php +++ b/Tests/TimedGeocoderTest.php @@ -35,7 +35,7 @@ class TimedGeocoderTest extends TestCase */ private $geocoder; - protected function setUp() + protected function setUp(): void { $this->stopwatch = new Stopwatch(); $this->delegate = $this->getMockBuilder(Provider::class)->getMock(); diff --git a/composer.json b/composer.json index 7e89162b..e276831a 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.2" + "php": "^7.3 || ^8.0" }, "require-dev": { "nyholm/nsa": "^1.1", From 2606f5381aac744ff55824063507af9091c54625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Mon, 21 Dec 2020 10:30:01 +0100 Subject: [PATCH 37/61] Enable PHP 8.0 support (1) (#1103) * Upragde PHPUnit * Upgrade PHPUnit configuration * Upgrade Travis CI configuration * Update changelogs --- .travis.yml | 7 ++++++- CHANGELOG.md | 48 ++++++++++++++++++++++++++++++------------------ composer.json | 2 +- phpunit.xml.dist | 48 ++++++++++++++++++++++-------------------------- 4 files changed, 59 insertions(+), 46 deletions(-) diff --git a/.travis.yml b/.travis.yml index 251286c3..1752e6f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ language: php -php: 7.2 +matrix: + fast_finish: true + include: + - php: 7.3 + - php: 7.4 + - php: 8.0 install: - composer update --prefer-stable --prefer-dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 92197deb..51baa469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 4.4.0 + +### Added + +- Add support for PHP 8.0 + +### Removed + +- Drop support for PHP 7.2 + +### Changed + +- Upgrade PHPUnit to version 9 + ## 4.3.0 ### Removed @@ -17,7 +31,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Fixed -- Fix building ProviderNotRegistered exception message +- Fix building ProviderNotRegistered exception message ## 4.2.1 @@ -33,17 +47,17 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Fixed -- Bug in `StatefulGeocoder` where different locale or bounds did not have any effect. +- Bug in `StatefulGeocoder` where different locale or bounds did not have any effect. ## 4.1.0 ### Changed -- Make sure a `Country` never will be empty of data. +- Make sure a `Country` never will be empty of data. ## 4.0.0 -No changes since Beta 5. +No changes since Beta 5. ## 4.0.0 - Beta 5 @@ -60,40 +74,38 @@ No changes since Beta 5. ## 4.0.0 - Beta 3 -### Added +### Added -- The constructor of `ProvierAggregator` will accept a callable that can decide what providers should be used for a specific query. +- The constructor of `ProvierAggregator` will accept a callable that can decide what providers should be used for a specific query. ### Changed - `ProvierAggregator::getProvider` is now private - `ProvierAggregator::limit` was removed - `ProvierAggregator::getLimit` was removed -- `ProvierAggregator::__constructor` changed the order of the parameters. -- `ProvierAggregator` is not final. - +- `ProvierAggregator::__constructor` changed the order of the parameters. +- `ProvierAggregator` is not final. ## 4.0.0 - Beta 2 ### Added -- PHP7 type hints. +- PHP7 type hints. - `AbstractArrayDumper` and `AbstractDumper` - `LogicException` and `OutOfBounds` - `GeocodeQuery::__toString` and `ReverseQuery::__toString` ### Changed -- All Dumpers are now final. -- All Exceptions are now final. -- `AddressCollection` is now final. -- `ProviderAggregator` is now final. -- `StatefulGeocoder` is now final. -- `TimedGeocoder` is now final. +- All Dumpers are now final. +- All Exceptions are now final. +- `AddressCollection` is now final. +- `ProviderAggregator` is now final. +- `StatefulGeocoder` is now final. +- `TimedGeocoder` is now final. - `ProviderAggregator::getName()` will return "provider_aggregator" - `TimedGeocoder::getName()` will return "timed_geocoder" - ## 4.0.0 - Beta1 -First release of this library. +First release of this library. diff --git a/composer.json b/composer.json index e276831a..1101685c 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "nyholm/nsa": "^1.1", - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^9.5", "symfony/stopwatch": "~2.5" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7581e875..d3ed6e38 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,24 @@ - - - - - - - - - ./Tests/ - - - - - - ./ - - ./Tests - ./vendor - - - + + + + ./ + + + ./Tests + ./vendor + + + + + + + + ./Tests/ + + From 9132c56cca9b63cf057186fee056ef785ee3e0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Mon, 21 Dec 2020 18:20:39 +0100 Subject: [PATCH 38/61] Clean tests phpdoc --- Tests/Model/AddressCollectionTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/Model/AddressCollectionTest.php b/Tests/Model/AddressCollectionTest.php index 6981119f..877987f4 100644 --- a/Tests/Model/AddressCollectionTest.php +++ b/Tests/Model/AddressCollectionTest.php @@ -20,9 +20,6 @@ */ class AddressCollectionTest extends TestCase { - /** - * @expectedException \Geocoder\Exception\CollectionIsEmpty - */ public function testFirstOnEmpty() { $this->expectException(\Geocoder\Exception\CollectionIsEmpty::class); From 36bb89398eb5dcd6d38cf7cbcda79b41bbd6279b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 20 Jun 2021 15:32:03 +0200 Subject: [PATCH 39/61] Add GitHub Actions (#1101) * Add GitHub Actions * Update GitHub Actions * Add low/high dependencies * Update low/high dependencies * Disable fail fast See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategyfail-fast * Update GitHub Actions * Update GitHub Action name * Create provider.yml * Create component.yml * Update component.yml * Update provider.yml * Update component.yml * Update GitHub Action name * Update component.yml * Split tests with ext-geoip + Disable test for deprecated providers * Update provider.yml GeoIP extensions is not (yet?) available for PHP 8.0. * Update provider.yml Disable test for IP2LocationBinary because it needs binary file. Travis CI test has also never passed. * Update provider.yml Use `composer update` insted of `composer install`. * Update provider.yml Use `composer update` insted of `composer install`. * Update README.md * Delete .travis.yml * Delete .travis.yml for providers * Add GitHub Actions workflow for providers * Update provider.yml (Geoip) * Delete .travis.yml for components * Add GitHub Actions workflow for components --- .github/workflows/component.yml | 33 +++++++++++++++++++++++++++++++++ .travis.yml | 18 ------------------ 2 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/component.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml new file mode 100644 index 00000000..887f865b --- /dev/null +++ b/.github/workflows/component.yml @@ -0,0 +1,33 @@ +name: Component + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + name: PHP ${{ matrix.php-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-version: ['7.3', '7.4', '8.0'] + steps: + - uses: actions/checkout@v2 + - name: Use PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: curl + - name: Validate composer.json and composer.lock + run: composer validate --strict + - name: Install dependencies + run: composer update --prefer-stable --prefer-dist --no-progress + - name: Run test suite + run: composer run-script test-ci + - name: Upload Coverage report + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1752e6f9..00000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: php - -matrix: - fast_finish: true - include: - - php: 7.3 - - php: 7.4 - - php: 8.0 - -install: - - composer update --prefer-stable --prefer-dist - -script: - - composer test-ci - -after_success: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml From 45d3db1f3e4f960b803c36245ae8e8fba916c613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Mon, 21 Jun 2021 08:13:22 +0200 Subject: [PATCH 40/61] Replace empty() by more strict checks (#1125) * Replace empty() by stricter checks * Apply StyleCI fixes * Compare with empty string instead of checking length * Compare with empty array instead of checking count * Compare with empty string instead of checking length --- Dumper/AbstractArrayDumper.php | 2 +- Model/Address.php | 4 ++-- Model/AddressBuilder.php | 2 +- Model/AddressCollection.php | 4 ++-- Model/AdminLevelCollection.php | 2 +- ProviderAggregator.php | 2 +- Query/GeocodeQuery.php | 2 +- StatefulGeocoder.php | 10 +++++----- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Dumper/AbstractArrayDumper.php b/Dumper/AbstractArrayDumper.php index b3226f1f..7e6b6cfd 100644 --- a/Dumper/AbstractArrayDumper.php +++ b/Dumper/AbstractArrayDumper.php @@ -36,7 +36,7 @@ protected function getArray(Location $location): array $properties['bounds'] ); - if (0 === count($properties)) { + if ([] === $properties) { $properties = null; } diff --git a/Model/Address.php b/Model/Address.php index 27237f45..a0ff0e33 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -235,12 +235,12 @@ public static function createFromArray(array $data) $adminLevels = []; foreach ($data['adminLevels'] as $adminLevel) { - if (empty($adminLevel['level'])) { + if (null === $adminLevel['level'] || 0 === $adminLevel['level']) { continue; } $name = $adminLevel['name'] ?? $adminLevel['code'] ?? null; - if (empty($name)) { + if (null === $name || '' === $name) { continue; } diff --git a/Model/AddressBuilder.php b/Model/AddressBuilder.php index 23847079..4540897b 100644 --- a/Model/AddressBuilder.php +++ b/Model/AddressBuilder.php @@ -109,7 +109,7 @@ public function build(string $class = Address::class): Address } $country = null; - if (!empty($this->country) || !empty($this->countryCode)) { + if ((null !== $this->country && '' !== $this->country) || (null !== $this->countryCode && '' !== $this->countryCode)) { $country = new Country($this->country, $this->countryCode); } diff --git a/Model/AddressCollection.php b/Model/AddressCollection.php index 9895b18d..e9b12b13 100644 --- a/Model/AddressCollection.php +++ b/Model/AddressCollection.php @@ -53,7 +53,7 @@ public function count() */ public function first(): Location { - if (empty($this->locations)) { + if ([] === $this->locations) { throw new CollectionIsEmpty(); } @@ -65,7 +65,7 @@ public function first(): Location */ public function isEmpty(): bool { - return empty($this->locations); + return [] === $this->locations; } /** diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index cedd203e..073b1f1c 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -73,7 +73,7 @@ public function count() */ public function first(): AdminLevel { - if (empty($this->adminLevels)) { + if ([] === $this->adminLevels) { throw new CollectionIsEmpty(); } diff --git a/ProviderAggregator.php b/ProviderAggregator.php index b9fb75bd..c3e26940 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -180,7 +180,7 @@ private static function getProvider($query, array $providers, Provider $currentP return $currentProvider; } - if (0 === count($providers)) { + if ([] === $providers) { throw ProviderNotRegistered::noProviderRegistered(); } diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 0533ed0c..13412dc7 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -53,7 +53,7 @@ final class GeocodeQuery implements Query */ private function __construct(string $text) { - if (empty($text)) { + if ('' === $text) { throw new InvalidArgument('Geocode query cannot be empty'); } diff --git a/StatefulGeocoder.php b/StatefulGeocoder.php index e618b25b..ebf5e4c9 100644 --- a/StatefulGeocoder.php +++ b/StatefulGeocoder.php @@ -23,7 +23,7 @@ final class StatefulGeocoder implements Geocoder { /** - * @var string + * @var string|null */ private $locale; @@ -61,7 +61,7 @@ public function geocode(string $value): Collection $query = GeocodeQuery::create($value) ->withLimit($this->limit); - if (!empty($this->locale)) { + if (null !== $this->locale && '' !== $this->locale) { $query = $query->withLocale($this->locale); } @@ -80,7 +80,7 @@ public function reverse(float $latitude, float $longitude): Collection $query = ReverseQuery::fromCoordinates($latitude, $longitude) ->withLimit($this->limit); - if (!empty($this->locale)) { + if (null !== $this->locale && '' !== $this->locale) { $query = $query->withLocale($this->locale); } @@ -93,7 +93,7 @@ public function reverse(float $latitude, float $longitude): Collection public function geocodeQuery(GeocodeQuery $query): Collection { $locale = $query->getLocale(); - if (empty($locale) && null !== $this->locale) { + if ((null === $locale || '' === $locale) && null !== $this->locale) { $query = $query->withLocale($this->locale); } @@ -111,7 +111,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection public function reverseQuery(ReverseQuery $query): Collection { $locale = $query->getLocale(); - if (empty($locale) && null !== $this->locale) { + if ((null === $locale || '' === $locale) && null !== $this->locale) { $query = $query->withLocale($this->locale); } From 8d8854cd4f61a336ef036a997d02114c6c9ddccd Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Fri, 3 Dec 2021 10:13:09 +0100 Subject: [PATCH 41/61] Add PHP 8.1 support by specifying return types for `getIterator` and `count` (#1142) * Test on PHP 8.1 * Specify return types for `getIterator` and `count` This is required for PHP 8.1. --- Model/AddressCollection.php | 5 +++-- Model/AdminLevelCollection.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Model/AddressCollection.php b/Model/AddressCollection.php index e9b12b13..b176bf27 100644 --- a/Model/AddressCollection.php +++ b/Model/AddressCollection.php @@ -16,6 +16,7 @@ use Geocoder\Exception\CollectionIsEmpty; use Geocoder\Exception\OutOfBounds; use Geocoder\Location; +use Traversable; final class AddressCollection implements Collection { @@ -35,7 +36,7 @@ public function __construct(array $locations = []) /** * {@inheritdoc} */ - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->all()); } @@ -43,7 +44,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->locations); } diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index 073b1f1c..f7c477e6 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -15,6 +15,7 @@ use Geocoder\Exception\CollectionIsEmpty; use Geocoder\Exception\InvalidArgument; use Geocoder\Exception\OutOfBounds; +use Traversable; /** * @author Giorgio Premi @@ -53,7 +54,7 @@ public function __construct(array $adminLevels = []) /** * {@inheritdoc} */ - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->all()); } @@ -61,7 +62,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->adminLevels); } From 8eb20d023996cf4ef65502bf945f23338a2602cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Fri, 7 Jan 2022 15:34:12 +0100 Subject: [PATCH 42/61] Add PHP 8.1 to GitHub Actions workflows --- .github/workflows/component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index 887f865b..be890485 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.3', '7.4', '8.0'] + php-version: ['7.3', '7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v2 - name: Use PHP ${{ matrix.php-version }} From ff863b0c39873a9f3b7216de7e6a3c06e35ef003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Fri, 7 Jan 2022 15:44:30 +0100 Subject: [PATCH 43/61] [php-common] Update CHANGELOG.md --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51baa469..3c6660bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 4.5.0 + +### Added + +- Add support for PHP 8.1 + +### Changed + +- Replace `empty()` by more strict checks + ## 4.4.0 ### Added From e32b2039581af8af474e972d916a2ce71c92175a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 30 Jul 2022 12:36:58 +0200 Subject: [PATCH 44/61] Drop support for PHP 7.3 (#1158) * Update compser.json files * Update GitHub Actions workflows * Update CHANGELOG.md * Update php.yml --- .github/workflows/component.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index be890485..93d74825 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.3', '7.4', '8.0', '8.1'] + php-version: ['7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v2 - name: Use PHP ${{ matrix.php-version }} diff --git a/composer.json b/composer.json index 1101685c..dbacc8ee 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.3 || ^8.0" + "php": "^7.4 || ^8.0" }, "require-dev": { "nyholm/nsa": "^1.1", From 335dbd5aafb9ab603ec180798bce7eb831adf5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 30 Jul 2022 13:09:43 +0200 Subject: [PATCH 45/61] [php-common] Update CHANGELOG.ms --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c6660bd..e060ede2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 4.6.0 + +### Removed + +- Drop support for PHP 7.3 + ## 4.5.0 ### Added From 59b75057a623333faa8f94567f3700cb789eb929 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 5 Jan 2023 15:02:12 +0100 Subject: [PATCH 46/61] chore: components and plugins, add ci tests for php 8.2 (#1171) chore: components and plugins, add ci tests for php 8.2, bump github actions versions Co-authored-by: Christopher Georg --- .github/workflows/component.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index 93d74825..af55ac97 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -13,9 +13,9 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1'] + php-version: ['7.4', '8.0', '8.1', '8.2'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Use PHP ${{ matrix.php-version }} uses: shivammathur/setup-php@v2 with: @@ -30,4 +30,4 @@ jobs: - name: Upload Coverage report run: | wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml \ No newline at end of file + php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml From e81842dfb27f2a454126d3e7f62adada5c9d4791 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 19 Feb 2023 18:31:45 +0100 Subject: [PATCH 47/61] Update symfony/stopwatch requirement from ~2.5 to ~2.5 || ~5.0 in /src/Common (#1175) Update symfony/stopwatch requirement || ~5.0 in /src/Common Updates the requirements on [symfony/stopwatch](https://github.com/symfony/stopwatch) to permit the latest version. - [Release notes](https://github.com/symfony/stopwatch/releases) - [Changelog](https://github.com/symfony/stopwatch/blob/6.2/CHANGELOG.md) - [Commits](https://github.com/symfony/stopwatch/compare/v2.5.0...v5.4.19) --- updated-dependencies: - dependency-name: symfony/stopwatch dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dbacc8ee..0aa5132c 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "nyholm/nsa": "^1.1", "phpunit/phpunit": "^9.5", - "symfony/stopwatch": "~2.5" + "symfony/stopwatch": "~2.5 || ~5.0" }, "suggest": { "symfony/stopwatch": "If you want to use the TimedGeocoder" From e0e1e1f7ec5e133e610cff20c604d4ee31f7a52a Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sun, 9 Jul 2023 15:20:35 +0200 Subject: [PATCH 48/61] Specify iterable type (#1140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will help static analysis tools to understand the iterable type of `Collection` Co-authored-by: Jonathan Beliën --- Collection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Collection.php b/Collection.php index 64f4ec99..b84d3a96 100644 --- a/Collection.php +++ b/Collection.php @@ -20,6 +20,8 @@ * * @author William Durand * @author Tobias Nyholm + * + * @template-extends \IteratorAggregate */ interface Collection extends \IteratorAggregate, \Countable { From 876c5aebe46d15a24aea5977acbc5721716b6ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 16 Jul 2023 16:36:39 +0200 Subject: [PATCH 49/61] Add PHPStan in CI (#1193) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add PHPStan * Update php.yml * Update composer.json * Fix PHPStan level 0 * Fix PHPStan level 1 * Update phpstan.neon * Fix PHPStan level 2 * Update composer.json * Fix PHPStan level 3 * Fix tests * Fix PHPStan level 4 * Update src/Common/Tests/TimedGeocoderTest.php Co-authored-by: Tomas Norkūnas * Update src/Provider/Cache/Tests/ProviderCacheTest.php Co-authored-by: Tomas Norkūnas * Update src/Provider/Cache/Tests/ProviderCacheTest.php Co-authored-by: Tomas Norkūnas * Update src/Provider/GeoIP2/Tests/GeoIP2Test.php Co-authored-by: Tomas Norkūnas * Fix PHPStan level 5 * Normalize composer.json * Rename analyse script * Update composer.json * Update IntegrationTest * Update AlgoliaPlacesTest * Update composer.json * Update RequestInterface vs. getParsedResponse() * Update src/Plugin/PluginProvider.php Co-authored-by: Tomas Norkūnas * Update src/Plugin/PluginProvider.php Co-authored-by: Tomas Norkūnas * Use PHPStan baseline instead of ignore See https://phpstan.org/user-guide/baseline --------- Co-authored-by: Tomas Norkūnas --- Model/Address.php | 2 +- ProviderAggregator.php | 8 -------- StatefulGeocoder.php | 2 +- Tests/TimedGeocoderTest.php | 3 ++- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Model/Address.php b/Model/Address.php index a0ff0e33..e22872c8 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -87,7 +87,7 @@ class Address implements Location * @param Country|null $country * @param string|null $timezone */ - public function __construct( + final public function __construct( string $providedBy, AdminLevelCollection $adminLevels, Coordinates $coordinates = null, diff --git a/ProviderAggregator.php b/ProviderAggregator.php index c3e26940..ae7a78a8 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -60,10 +60,6 @@ public function __construct(callable $decider = null, int $limit = Geocoder::DEF */ public function geocodeQuery(GeocodeQuery $query): Collection { - if (null === $query->getLimit()) { - $query = $query->withLimit($this->limit); - } - return call_user_func($this->decider, $query, $this->providers, $this->provider)->geocodeQuery($query); } @@ -72,10 +68,6 @@ public function geocodeQuery(GeocodeQuery $query): Collection */ public function reverseQuery(ReverseQuery $query): Collection { - if (null === $query->getLimit()) { - $query = $query->withLimit($this->limit); - } - return call_user_func($this->decider, $query, $this->providers, $this->provider)->reverseQuery($query); } diff --git a/StatefulGeocoder.php b/StatefulGeocoder.php index ebf5e4c9..73c72463 100644 --- a/StatefulGeocoder.php +++ b/StatefulGeocoder.php @@ -65,7 +65,7 @@ public function geocode(string $value): Collection $query = $query->withLocale($this->locale); } - if (!empty($this->bounds)) { + if (null !== $this->bounds) { $query = $query->withBounds($this->bounds); } diff --git a/Tests/TimedGeocoderTest.php b/Tests/TimedGeocoderTest.php index c46a82fb..318ef408 100644 --- a/Tests/TimedGeocoderTest.php +++ b/Tests/TimedGeocoderTest.php @@ -15,6 +15,7 @@ use Geocoder\Model\AddressCollection; use Geocoder\Provider\Provider; use Geocoder\TimedGeocoder; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Stopwatch\Stopwatch; @@ -26,7 +27,7 @@ class TimedGeocoderTest extends TestCase private $stopwatch; /** - * @var Provider|\PHPUnit_Framework_MockObject_MockObject + * @var Provider&MockObject */ private $delegate; From e3eb3b2f58fc6473f0720da79d26c1f0d73d0d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Fri, 21 Jul 2023 11:32:47 +0200 Subject: [PATCH 50/61] Add PHP Coding Standards Fixer in CI (#1196) * Update composer.json * Update .gitignore * Update php.yml * Apply PHPCSFixer fixes * Switch to php-cs-fixer/shim * Create .php-cs-fixer.dist.php --- Assert.php | 14 ++------ Collection.php | 10 ------ Dumper/AbstractArrayDumper.php | 5 --- Dumper/AbstractDumper.php | 5 --- Dumper/Dumper.php | 4 --- Dumper/GeoArray.php | 3 -- Dumper/GeoJson.php | 3 -- Dumper/Gpx.php | 11 ++----- Dumper/Kml.php | 3 -- Dumper/Wkb.php | 3 -- Dumper/Wkt.php | 3 -- Exception/FunctionNotFound.php | 1 - Exception/InvalidServerResponse.php | 11 ------- Exception/ProviderNotRegistered.php | 4 --- Formatter/StringFormatter.php | 27 +++++++-------- Geocoder.php | 15 ++------- GeocoderTrait.php | 6 ---- Location.php | 6 ---- Model/Address.php | 51 ----------------------------- Model/AddressBuilder.php | 51 ----------------------------- Model/AddressCollection.php | 24 +------------- Model/AdminLevel.php | 9 ----- Model/AdminLevelCollection.php | 23 ++----------- Model/Bounds.php | 10 ------ Model/Coordinates.php | 6 ---- Model/Country.php | 2 -- Provider/AbstractProvider.php | 2 -- Provider/Provider.php | 10 ------ ProviderAggregator.php | 33 +------------------ Query/GeocodeQuery.php | 46 -------------------------- Query/Query.php | 16 --------- Query/ReverseQuery.php | 40 ---------------------- StatefulGeocoder.php | 35 ++------------------ Tests/Dumper/GpxTest.php | 10 +++--- Tests/ProviderAggregatorTest.php | 4 +-- TimedGeocoder.php | 8 +---- 36 files changed, 33 insertions(+), 481 deletions(-) diff --git a/Assert.php b/Assert.php index 5f21534a..92738c86 100644 --- a/Assert.php +++ b/Assert.php @@ -17,8 +17,7 @@ class Assert { /** - * @param float $value - * @param string $message + * @param float $value */ public static function latitude($value, string $message = '') { @@ -29,8 +28,7 @@ public static function latitude($value, string $message = '') } /** - * @param float $value - * @param string $message + * @param float $value */ public static function longitude($value, string $message = '') { @@ -40,10 +38,6 @@ public static function longitude($value, string $message = '') } } - /** - * @param mixed $value - * @param string $message - */ public static function notNull($value, string $message = '') { if (null === $value) { @@ -56,10 +50,6 @@ private static function typeToString($value): string return is_object($value) ? get_class($value) : gettype($value); } - /** - * @param $value - * @param $message - */ private static function float($value, string $message) { if (!is_float($value)) { diff --git a/Collection.php b/Collection.php index b84d3a96..32e32074 100644 --- a/Collection.php +++ b/Collection.php @@ -26,15 +26,10 @@ interface Collection extends \IteratorAggregate, \Countable { /** - * @return Location - * * @throws CollectionIsEmpty */ public function first(): Location; - /** - * @return bool - */ public function isEmpty(): bool; /** @@ -42,14 +37,9 @@ public function isEmpty(): bool; */ public function slice(int $offset, int $length = null); - /** - * @return bool - */ public function has(int $index): bool; /** - * @return Location - * * @throws OutOfBounds */ public function get(int $index): Location; diff --git a/Dumper/AbstractArrayDumper.php b/Dumper/AbstractArrayDumper.php index 7e6b6cfd..ae654639 100644 --- a/Dumper/AbstractArrayDumper.php +++ b/Dumper/AbstractArrayDumper.php @@ -19,11 +19,6 @@ */ abstract class AbstractArrayDumper { - /** - * @param Location $location - * - * @return array - */ protected function getArray(Location $location): array { $properties = array_filter($location->toArray(), function ($value) { diff --git a/Dumper/AbstractDumper.php b/Dumper/AbstractDumper.php index b46025f3..9f0bba5e 100644 --- a/Dumper/AbstractDumper.php +++ b/Dumper/AbstractDumper.php @@ -16,11 +16,6 @@ abstract class AbstractDumper { - /** - * @param Location $address - * - * @return string - */ protected function formatName(Location $address): string { $name = []; diff --git a/Dumper/Dumper.php b/Dumper/Dumper.php index 44529252..8903e9cd 100644 --- a/Dumper/Dumper.php +++ b/Dumper/Dumper.php @@ -22,10 +22,6 @@ interface Dumper /** * Dumps an `Location` object as a string representation of * the implemented format. - * - * @param Location $location - * - * @return mixed */ public function dump(Location $location); } diff --git a/Dumper/GeoArray.php b/Dumper/GeoArray.php index f9926862..df74889f 100644 --- a/Dumper/GeoArray.php +++ b/Dumper/GeoArray.php @@ -19,9 +19,6 @@ */ final class GeoArray extends AbstractArrayDumper implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): array { return $this->getArray($location); diff --git a/Dumper/GeoJson.php b/Dumper/GeoJson.php index d9a1a103..e0a09ad9 100644 --- a/Dumper/GeoJson.php +++ b/Dumper/GeoJson.php @@ -19,9 +19,6 @@ */ final class GeoJson extends AbstractArrayDumper implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { return json_encode($this->getArray($location)); diff --git a/Dumper/Gpx.php b/Dumper/Gpx.php index 935a9dad..df26074d 100644 --- a/Dumper/Gpx.php +++ b/Dumper/Gpx.php @@ -20,11 +20,6 @@ */ final class Gpx extends AbstractDumper implements Dumper { - /** - * @param Location $location - * - * @return string - */ public function dump(Location $location): string { $gpx = sprintf(<<<'GPX' @@ -37,14 +32,14 @@ public function dump(Location $location): string xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> GPX - , Geocoder::VERSION); + , Geocoder::VERSION); if (null !== $bounds = $location->getBounds()) { $gpx .= sprintf(<<<'GPX' GPX - , $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth()); + , $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth()); } $lat = null; @@ -61,7 +56,7 @@ public function dump(Location $location): string GPX - , $lat, $lon, $this->formatName($location)); + , $lat, $lon, $this->formatName($location)); $gpx .= <<<'GPX' diff --git a/Dumper/Kml.php b/Dumper/Kml.php index 9182c25c..35e35ad6 100644 --- a/Dumper/Kml.php +++ b/Dumper/Kml.php @@ -19,9 +19,6 @@ */ final class Kml extends AbstractDumper implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { $name = $this->formatName($location); diff --git a/Dumper/Wkb.php b/Dumper/Wkb.php index 9cbf2145..d602ef40 100644 --- a/Dumper/Wkb.php +++ b/Dumper/Wkb.php @@ -19,9 +19,6 @@ */ final class Wkb implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { $lat = null; diff --git a/Dumper/Wkt.php b/Dumper/Wkt.php index e07331f2..85ccc99d 100644 --- a/Dumper/Wkt.php +++ b/Dumper/Wkt.php @@ -19,9 +19,6 @@ */ final class Wkt implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { $lat = null; diff --git a/Exception/FunctionNotFound.php b/Exception/FunctionNotFound.php index 8fe68935..78b02b95 100644 --- a/Exception/FunctionNotFound.php +++ b/Exception/FunctionNotFound.php @@ -18,7 +18,6 @@ final class FunctionNotFound extends \RuntimeException implements Exception { /** - * @param string $functionName * @param string $description */ public function __construct(string $functionName, $description = null) diff --git a/Exception/InvalidServerResponse.php b/Exception/InvalidServerResponse.php index 3c2dc519..a74cfd50 100644 --- a/Exception/InvalidServerResponse.php +++ b/Exception/InvalidServerResponse.php @@ -19,22 +19,11 @@ */ final class InvalidServerResponse extends \RuntimeException implements Exception { - /** - * @param string $query - * @param int $code - * - * @return InvalidServerResponse - */ public static function create(string $query, int $code = 0): self { return new self(sprintf('The geocoder server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query)); } - /** - * @param string $query - * - * @return InvalidServerResponse - */ public static function emptyResponse(string $query): self { return new self(sprintf('The geocoder server returned an empty response for query "%s".', $query)); diff --git a/Exception/ProviderNotRegistered.php b/Exception/ProviderNotRegistered.php index eb479afa..38d56fb0 100644 --- a/Exception/ProviderNotRegistered.php +++ b/Exception/ProviderNotRegistered.php @@ -17,10 +17,6 @@ */ final class ProviderNotRegistered extends \RuntimeException implements Exception { - /** - * @param string $providerName - * @param array $registeredProviders - */ public static function create(string $providerName, array $registeredProviders = []) { return new self(sprintf( diff --git a/Formatter/StringFormatter.php b/Formatter/StringFormatter.php index 95adcf66..0acdb361 100644 --- a/Formatter/StringFormatter.php +++ b/Formatter/StringFormatter.php @@ -12,41 +12,36 @@ namespace Geocoder\Formatter; -use Geocoder\Model\AdminLevelCollection; use Geocoder\Location; +use Geocoder\Model\AdminLevelCollection; /** * @author William Durand */ final class StringFormatter { - const STREET_NUMBER = '%n'; + public const STREET_NUMBER = '%n'; - const STREET_NAME = '%S'; + public const STREET_NAME = '%S'; - const LOCALITY = '%L'; + public const LOCALITY = '%L'; - const POSTAL_CODE = '%z'; + public const POSTAL_CODE = '%z'; - const SUB_LOCALITY = '%D'; + public const SUB_LOCALITY = '%D'; - const ADMIN_LEVEL = '%A'; + public const ADMIN_LEVEL = '%A'; - const ADMIN_LEVEL_CODE = '%a'; + public const ADMIN_LEVEL_CODE = '%a'; - const COUNTRY = '%C'; + public const COUNTRY = '%C'; - const COUNTRY_CODE = '%c'; + public const COUNTRY_CODE = '%c'; - const TIMEZONE = '%T'; + public const TIMEZONE = '%T'; /** * Transform an `Address` instance into a string representation. - * - * @param Location $location - * @param string $format - * - * @return string */ public function format(Location $location, string $format): string { diff --git a/Geocoder.php b/Geocoder.php index d52e1f3b..82032aef 100644 --- a/Geocoder.php +++ b/Geocoder.php @@ -22,22 +22,18 @@ interface Geocoder extends Provider /** * Version of this package. */ - const MAJOR_VERSION = 4; + public const MAJOR_VERSION = 4; - const VERSION = '4.0'; + public const VERSION = '4.0'; /** * The default result limit. */ - const DEFAULT_RESULT_LIMIT = 5; + public const DEFAULT_RESULT_LIMIT = 5; /** * Geocodes a given value. * - * @param string $value - * - * @return Collection - * * @throws \Geocoder\Exception\Exception */ public function geocode(string $value): Collection; @@ -45,11 +41,6 @@ public function geocode(string $value): Collection; /** * Reverses geocode given latitude and longitude values. * - * @param float $latitude - * @param float $longitude - * - * @return Collection - * * @throws \Geocoder\Exception\Exception */ public function reverse(float $latitude, float $longitude): Collection; diff --git a/GeocoderTrait.php b/GeocoderTrait.php index 7d5949ec..2210ebf0 100644 --- a/GeocoderTrait.php +++ b/GeocoderTrait.php @@ -26,17 +26,11 @@ abstract public function geocodeQuery(GeocodeQuery $query): Collection; abstract public function reverseQuery(ReverseQuery $query): Collection; - /** - * {@inheritdoc} - */ public function geocode(string $value): Collection { return $this->geocodeQuery(GeocodeQuery::create($value)); } - /** - * {@inheritdoc} - */ public function reverse(float $latitude, float $longitude): Collection { return $this->reverseQuery(ReverseQuery::fromCoordinates($latitude, $longitude)); diff --git a/Location.php b/Location.php index 5d9b9e44..c1148982 100644 --- a/Location.php +++ b/Location.php @@ -79,8 +79,6 @@ public function getSubLocality(); * Returns the administrative levels. * * This method MUST NOT return null. - * - * @return AdminLevelCollection */ public function getAdminLevels(): AdminLevelCollection; @@ -102,15 +100,11 @@ public function getTimezone(); /** * Returns an array with data indexed by name. - * - * @return array */ public function toArray(): array; /** * The name of the provider that created this Location. - * - * @return string */ public function getProvidedBy(): string; } diff --git a/Model/Address.php b/Model/Address.php index e22872c8..a5f719d6 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -74,19 +74,6 @@ class Address implements Location */ private $providedBy; - /** - * @param string $providedBy - * @param AdminLevelCollection $adminLevels - * @param Coordinates|null $coordinates - * @param Bounds|null $bounds - * @param string|null $streetNumber - * @param string|null $streetName - * @param string|null $postalCode - * @param string|null $locality - * @param string|null $subLocality - * @param Country|null $country - * @param string|null $timezone - */ final public function __construct( string $providedBy, AdminLevelCollection $adminLevels, @@ -113,89 +100,56 @@ final public function __construct( $this->timezone = $timezone; } - /** - * @return string - */ public function getProvidedBy(): string { return $this->providedBy; } - /** - * {@inheritdoc} - */ public function getCoordinates() { return $this->coordinates; } - /** - * {@inheritdoc} - */ public function getBounds() { return $this->bounds; } - /** - * {@inheritdoc} - */ public function getStreetNumber() { return $this->streetNumber; } - /** - * {@inheritdoc} - */ public function getStreetName() { return $this->streetName; } - /** - * {@inheritdoc} - */ public function getLocality() { return $this->locality; } - /** - * {@inheritdoc} - */ public function getPostalCode() { return $this->postalCode; } - /** - * {@inheritdoc} - */ public function getSubLocality() { return $this->subLocality; } - /** - * {@inheritdoc} - */ public function getAdminLevels(): AdminLevelCollection { return $this->adminLevels; } - /** - * {@inheritdoc} - */ public function getCountry() { return $this->country; } - /** - * {@inheritdoc} - */ public function getTimezone() { return $this->timezone; @@ -204,8 +158,6 @@ public function getTimezone() /** * Create an Address with an array. Useful for testing. * - * @param array $data - * * @return static */ public static function createFromArray(array $data) @@ -316,9 +268,6 @@ private static function createBounds($south, $west, $north, $east) return new Bounds($south, $west, $north, $east); } - /** - * {@inheritdoc} - */ public function toArray(): array { $adminLevels = []; diff --git a/Model/AddressBuilder.php b/Model/AddressBuilder.php index 4540897b..d8b2e257 100644 --- a/Model/AddressBuilder.php +++ b/Model/AddressBuilder.php @@ -89,19 +89,11 @@ final class AddressBuilder */ private $data = []; - /** - * @param string $providedBy - */ public function __construct(string $providedBy) { $this->providedBy = $providedBy; } - /** - * @param string $class - * - * @return Address - */ public function build(string $class = Address::class): Address { if (!is_a($class, Address::class, true)) { @@ -133,8 +125,6 @@ public function build(string $class = Address::class): Address * @param float $west * @param float $north * @param float $east - * - * @return AddressBuilder */ public function setBounds($south, $west, $north, $east): self { @@ -150,8 +140,6 @@ public function setBounds($south, $west, $north, $east): self /** * @param float $latitude * @param float $longitude - * - * @return AddressBuilder */ public function setCoordinates($latitude, $longitude): self { @@ -164,13 +152,6 @@ public function setCoordinates($latitude, $longitude): self return $this; } - /** - * @param int $level - * @param string $name - * @param string|null $code - * - * @return AddressBuilder - */ public function addAdminLevel(int $level, string $name, string $code = null): self { $this->adminLevels[] = new AdminLevel($level, $name, $code); @@ -180,8 +161,6 @@ public function addAdminLevel(int $level, string $name, string $code = null): se /** * @param string|null $streetNumber - * - * @return AddressBuilder */ public function setStreetNumber($streetNumber): self { @@ -192,8 +171,6 @@ public function setStreetNumber($streetNumber): self /** * @param string|null $streetName - * - * @return AddressBuilder */ public function setStreetName($streetName): self { @@ -204,8 +181,6 @@ public function setStreetName($streetName): self /** * @param string|null $locality - * - * @return AddressBuilder */ public function setLocality($locality): self { @@ -216,8 +191,6 @@ public function setLocality($locality): self /** * @param string|null $postalCode - * - * @return AddressBuilder */ public function setPostalCode($postalCode): self { @@ -228,8 +201,6 @@ public function setPostalCode($postalCode): self /** * @param string|null $subLocality - * - * @return AddressBuilder */ public function setSubLocality($subLocality): self { @@ -240,8 +211,6 @@ public function setSubLocality($subLocality): self /** * @param array $adminLevels - * - * @return AddressBuilder */ public function setAdminLevels($adminLevels): self { @@ -252,8 +221,6 @@ public function setAdminLevels($adminLevels): self /** * @param string|null $country - * - * @return AddressBuilder */ public function setCountry($country): self { @@ -264,8 +231,6 @@ public function setCountry($country): self /** * @param string|null $countryCode - * - * @return AddressBuilder */ public function setCountryCode($countryCode): self { @@ -276,8 +241,6 @@ public function setCountryCode($countryCode): self /** * @param string|null $timezone - * - * @return AddressBuilder */ public function setTimezone($timezone): self { @@ -286,12 +249,6 @@ public function setTimezone($timezone): self return $this; } - /** - * @param string $name - * @param mixed $value - * - * @return AddressBuilder - */ public function setValue(string $name, $value): self { $this->data[$name] = $value; @@ -300,10 +257,7 @@ public function setValue(string $name, $value): self } /** - * @param string $name * @param mixed|null $default - * - * @return mixed */ public function getValue(string $name, $default = null) { @@ -314,11 +268,6 @@ public function getValue(string $name, $default = null) return $default; } - /** - * @param string $name - * - * @return bool - */ public function hasValue(string $name): bool { return array_key_exists($name, $this->data); diff --git a/Model/AddressCollection.php b/Model/AddressCollection.php index b176bf27..a1f50414 100644 --- a/Model/AddressCollection.php +++ b/Model/AddressCollection.php @@ -16,7 +16,6 @@ use Geocoder\Exception\CollectionIsEmpty; use Geocoder\Exception\OutOfBounds; use Geocoder\Location; -use Traversable; final class AddressCollection implements Collection { @@ -33,25 +32,16 @@ public function __construct(array $locations = []) $this->locations = array_values($locations); } - /** - * {@inheritdoc} - */ - public function getIterator(): Traversable + public function getIterator(): \Traversable { return new \ArrayIterator($this->all()); } - /** - * {@inheritdoc} - */ public function count(): int { return count($this->locations); } - /** - * {@inheritdoc} - */ public function first(): Location { if ([] === $this->locations) { @@ -61,9 +51,6 @@ public function first(): Location return reset($this->locations); } - /** - * {@inheritdoc} - */ public function isEmpty(): bool { return [] === $this->locations; @@ -77,17 +64,11 @@ public function slice(int $offset, int $length = null) return array_slice($this->locations, $offset, $length); } - /** - * @return bool - */ public function has(int $index): bool { return isset($this->locations[$index]); } - /** - * {@inheritdoc} - */ public function get(int $index): Location { if (!isset($this->locations[$index])) { @@ -97,9 +78,6 @@ public function get(int $index): Location return $this->locations[$index]; } - /** - * {@inheritdoc} - */ public function all(): array { return $this->locations; diff --git a/Model/AdminLevel.php b/Model/AdminLevel.php index d2271b8b..523669da 100644 --- a/Model/AdminLevel.php +++ b/Model/AdminLevel.php @@ -32,11 +32,6 @@ final class AdminLevel */ private $code; - /** - * @param int $level - * @param string $name - * @param string|null $code - */ public function __construct(int $level, string $name, string $code = null) { $this->level = $level; @@ -56,8 +51,6 @@ public function getLevel(): int /** * Returns the administrative level name. - * - * @return string */ public function getName(): string { @@ -76,8 +69,6 @@ public function getCode() /** * Returns a string with the administrative level name. - * - * @return string */ public function __toString(): string { diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index f7c477e6..84d3296e 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -15,14 +15,13 @@ use Geocoder\Exception\CollectionIsEmpty; use Geocoder\Exception\InvalidArgument; use Geocoder\Exception\OutOfBounds; -use Traversable; /** * @author Giorgio Premi */ final class AdminLevelCollection implements \IteratorAggregate, \Countable { - const MAX_LEVEL_DEPTH = 5; + public const MAX_LEVEL_DEPTH = 5; /** * @var AdminLevel[] @@ -51,25 +50,17 @@ public function __construct(array $adminLevels = []) ksort($this->adminLevels, SORT_NUMERIC); } - /** - * {@inheritdoc} - */ - public function getIterator(): Traversable + public function getIterator(): \Traversable { return new \ArrayIterator($this->all()); } - /** - * {@inheritdoc} - */ public function count(): int { return count($this->adminLevels); } /** - * @return AdminLevel - * * @throws CollectionIsEmpty */ public function first(): AdminLevel @@ -82,9 +73,6 @@ public function first(): AdminLevel } /** - * @param int $offset - * @param int|null $length - * * @return AdminLevel[] */ public function slice(int $offset, int $length = null): array @@ -92,17 +80,12 @@ public function slice(int $offset, int $length = null): array return array_slice($this->adminLevels, $offset, $length, true); } - /** - * @return bool - */ public function has(int $level): bool { return isset($this->adminLevels[$level]); } /** - * @return AdminLevel - * * @throws \OutOfBoundsException * @throws InvalidArgument */ @@ -126,8 +109,6 @@ public function all(): array } /** - * @param int $level - * * @throws \OutOfBoundsException */ private function checkLevel(int $level) diff --git a/Model/Bounds.php b/Model/Bounds.php index 02f01740..6bf74343 100644 --- a/Model/Bounds.php +++ b/Model/Bounds.php @@ -70,8 +70,6 @@ public function __construct($south, $west, $north, $east) /** * Returns the south bound. - * - * @return float */ public function getSouth(): float { @@ -80,8 +78,6 @@ public function getSouth(): float /** * Returns the west bound. - * - * @return float */ public function getWest(): float { @@ -90,8 +86,6 @@ public function getWest(): float /** * Returns the north bound. - * - * @return float */ public function getNorth(): float { @@ -100,8 +94,6 @@ public function getNorth(): float /** * Returns the east bound. - * - * @return float */ public function getEast(): float { @@ -110,8 +102,6 @@ public function getEast(): float /** * Returns an array with bounds. - * - * @return array */ public function toArray(): array { diff --git a/Model/Coordinates.php b/Model/Coordinates.php index 3821af43..861f374b 100644 --- a/Model/Coordinates.php +++ b/Model/Coordinates.php @@ -50,8 +50,6 @@ public function __construct($latitude, $longitude) /** * Returns the latitude. - * - * @return float */ public function getLatitude(): float { @@ -60,8 +58,6 @@ public function getLatitude(): float /** * Returns the longitude. - * - * @return float */ public function getLongitude(): float { @@ -70,8 +66,6 @@ public function getLongitude(): float /** * Returns the coordinates as a tuple. - * - * @return array */ public function toArray(): array { diff --git a/Model/Country.php b/Model/Country.php index 6230e323..69b65f9a 100644 --- a/Model/Country.php +++ b/Model/Country.php @@ -67,8 +67,6 @@ public function getCode() /** * Returns a string with the country name. - * - * @return string */ public function __toString(): string { diff --git a/Provider/AbstractProvider.php b/Provider/AbstractProvider.php index 7c8b8b6c..9a698a93 100644 --- a/Provider/AbstractProvider.php +++ b/Provider/AbstractProvider.php @@ -22,8 +22,6 @@ abstract class AbstractProvider implements Provider { /** * Returns the results for the 'localhost' special case. - * - * @return Location */ protected function getLocationForLocalhost(): Location { diff --git a/Provider/Provider.php b/Provider/Provider.php index bea5d02b..15b5369d 100644 --- a/Provider/Provider.php +++ b/Provider/Provider.php @@ -25,27 +25,17 @@ interface Provider { /** - * @param GeocodeQuery $query - * - * @return Collection - * * @throws \Geocoder\Exception\Exception */ public function geocodeQuery(GeocodeQuery $query): Collection; /** - * @param ReverseQuery $query - * - * @return Collection - * * @throws \Geocoder\Exception\Exception */ public function reverseQuery(ReverseQuery $query): Collection; /** * Returns the provider's name. - * - * @return string */ public function getName(): string; } diff --git a/ProviderAggregator.php b/ProviderAggregator.php index ae7a78a8..d42ec7bb 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -14,9 +14,9 @@ use Geocoder\Exception\ProviderNotRegistered; use Geocoder\Model\Coordinates; +use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\Provider\Provider; /** * @author William Durand @@ -45,52 +45,33 @@ class ProviderAggregator implements Geocoder */ private $decider; - /** - * @param callable|null $decider - * @param int $limit - */ public function __construct(callable $decider = null, int $limit = Geocoder::DEFAULT_RESULT_LIMIT) { $this->limit = $limit; $this->decider = $decider ?? __CLASS__.'::getProvider'; } - /** - * {@inheritdoc} - */ public function geocodeQuery(GeocodeQuery $query): Collection { return call_user_func($this->decider, $query, $this->providers, $this->provider)->geocodeQuery($query); } - /** - * {@inheritdoc} - */ public function reverseQuery(ReverseQuery $query): Collection { return call_user_func($this->decider, $query, $this->providers, $this->provider)->reverseQuery($query); } - /** - * {@inheritdoc} - */ public function getName(): string { return 'provider_aggregator'; } - /** - * {@inheritdoc} - */ public function geocode(string $value): Collection { return $this->geocodeQuery(GeocodeQuery::create($value) ->withLimit($this->limit)); } - /** - * {@inheritdoc} - */ public function reverse(float $latitude, float $longitude): Collection { return $this->reverseQuery(ReverseQuery::create(new Coordinates($latitude, $longitude)) @@ -99,10 +80,6 @@ public function reverse(float $latitude, float $longitude): Collection /** * Registers a new provider to the aggregator. - * - * @param Provider $provider - * - * @return ProviderAggregator */ public function registerProvider(Provider $provider): self { @@ -115,8 +92,6 @@ public function registerProvider(Provider $provider): self * Registers a set of providers. * * @param Provider[] $providers - * - * @return ProviderAggregator */ public function registerProviders(array $providers = []): self { @@ -129,10 +104,6 @@ public function registerProviders(array $providers = []): self /** * Sets the default provider to use. - * - * @param string $name - * - * @return ProviderAggregator */ public function using(string $name): self { @@ -162,8 +133,6 @@ public function getProviders(): array * @param Provider[] $providers * @param Provider $currentProvider * - * @return Provider - * * @throws ProviderNotRegistered */ private static function getProvider($query, array $providers, Provider $currentProvider = null): Provider diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 13412dc7..2aefd620 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -48,9 +48,6 @@ final class GeocodeQuery implements Query */ private $data = []; - /** - * @param string $text - */ private function __construct(string $text) { if ('' === $text) { @@ -60,21 +57,11 @@ private function __construct(string $text) $this->text = $text; } - /** - * @param string $text - * - * @return GeocodeQuery - */ public static function create(string $text): self { return new self($text); } - /** - * @param string $text - * - * @return GeocodeQuery - */ public function withText(string $text): self { $new = clone $this; @@ -83,11 +70,6 @@ public function withText(string $text): self return $new; } - /** - * @param Bounds $bounds - * - * @return GeocodeQuery - */ public function withBounds(Bounds $bounds): self { $new = clone $this; @@ -96,11 +78,6 @@ public function withBounds(Bounds $bounds): self return $new; } - /** - * @param string $locale - * - * @return GeocodeQuery - */ public function withLocale(string $locale): self { $new = clone $this; @@ -109,11 +86,6 @@ public function withLocale(string $locale): self return $new; } - /** - * @param int $limit - * - * @return GeocodeQuery - */ public function withLimit(int $limit): self { $new = clone $this; @@ -122,12 +94,6 @@ public function withLimit(int $limit): self return $new; } - /** - * @param string $name - * @param mixed $value - * - * @return GeocodeQuery - */ public function withData(string $name, $value): self { $new = clone $this; @@ -136,9 +102,6 @@ public function withData(string $name, $value): self return $new; } - /** - * @return string - */ public function getText(): string { return $this->text; @@ -160,19 +123,13 @@ public function getLocale() return $this->locale; } - /** - * @return int - */ public function getLimit(): int { return $this->limit; } /** - * @param string $name * @param mixed|null $default - * - * @return mixed */ public function getData(string $name, $default = null) { @@ -183,9 +140,6 @@ public function getData(string $name, $default = null) return $this->data[$name]; } - /** - * @return array - */ public function getAllData(): array { return $this->data; diff --git a/Query/Query.php b/Query/Query.php index 41e3bee1..8ffbe657 100644 --- a/Query/Query.php +++ b/Query/Query.php @@ -18,23 +18,16 @@ interface Query { /** - * @param string $locale - * * @return Query */ public function withLocale(string $locale); /** - * @param int $limit - * * @return Query */ public function withLimit(int $limit); /** - * @param string $name - * @param mixed $value - * * @return Query */ public function withData(string $name, $value); @@ -44,22 +37,13 @@ public function withData(string $name, $value); */ public function getLocale(); - /** - * @return int - */ public function getLimit(): int; /** - * @param string $name * @param mixed|null $default - * - * @return mixed */ public function getData(string $name, $default = null); - /** - * @return array - */ public function getAllData(): array; /** diff --git a/Query/ReverseQuery.php b/Query/ReverseQuery.php index 50e92c4d..39db8280 100644 --- a/Query/ReverseQuery.php +++ b/Query/ReverseQuery.php @@ -40,17 +40,12 @@ final class ReverseQuery implements Query */ private $data = []; - /** - * @param Coordinates $coordinates - */ private function __construct(Coordinates $coordinates) { $this->coordinates = $coordinates; } /** - * @param Coordinates $coordinates - * * @return ReverseQuery */ public static function create(Coordinates $coordinates) @@ -61,19 +56,12 @@ public static function create(Coordinates $coordinates) /** * @param float $latitude * @param float $longitude - * - * @return ReverseQuery */ public static function fromCoordinates($latitude, $longitude): self { return new self(new Coordinates($latitude, $longitude)); } - /** - * @param Coordinates $coordinates - * - * @return ReverseQuery - */ public function withCoordinates(Coordinates $coordinates): self { $new = clone $this; @@ -82,11 +70,6 @@ public function withCoordinates(Coordinates $coordinates): self return $new; } - /** - * @param int $limit - * - * @return ReverseQuery - */ public function withLimit(int $limit): self { $new = clone $this; @@ -95,11 +78,6 @@ public function withLimit(int $limit): self return $new; } - /** - * @param string $locale - * - * @return ReverseQuery - */ public function withLocale(string $locale): self { $new = clone $this; @@ -108,12 +86,6 @@ public function withLocale(string $locale): self return $new; } - /** - * @param string $name - * @param mixed $value - * - * @return ReverseQuery - */ public function withData(string $name, $value): self { $new = clone $this; @@ -122,17 +94,11 @@ public function withData(string $name, $value): self return $new; } - /** - * @return Coordinates - */ public function getCoordinates(): Coordinates { return $this->coordinates; } - /** - * @return int - */ public function getLimit(): int { return $this->limit; @@ -147,10 +113,7 @@ public function getLocale() } /** - * @param string $name * @param mixed|null $default - * - * @return mixed */ public function getData(string $name, $default = null) { @@ -161,9 +124,6 @@ public function getData(string $name, $default = null) return $this->data[$name]; } - /** - * @return array - */ public function getAllData(): array { return $this->data; diff --git a/StatefulGeocoder.php b/StatefulGeocoder.php index 73c72463..8610fe3d 100644 --- a/StatefulGeocoder.php +++ b/StatefulGeocoder.php @@ -13,9 +13,9 @@ namespace Geocoder; use Geocoder\Model\Bounds; +use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\Provider\Provider; /** * @author Tobias Nyholm @@ -43,8 +43,7 @@ final class StatefulGeocoder implements Geocoder private $provider; /** - * @param Provider $provider - * @param string $locale + * @param string $locale */ public function __construct(Provider $provider, string $locale = null) { @@ -53,9 +52,6 @@ public function __construct(Provider $provider, string $locale = null) $this->limit = Geocoder::DEFAULT_RESULT_LIMIT; } - /** - * {@inheritdoc} - */ public function geocode(string $value): Collection { $query = GeocodeQuery::create($value) @@ -72,9 +68,6 @@ public function geocode(string $value): Collection return $this->provider->geocodeQuery($query); } - /** - * {@inheritdoc} - */ public function reverse(float $latitude, float $longitude): Collection { $query = ReverseQuery::fromCoordinates($latitude, $longitude) @@ -87,9 +80,6 @@ public function reverse(float $latitude, float $longitude): Collection return $this->provider->reverseQuery($query); } - /** - * {@inheritdoc} - */ public function geocodeQuery(GeocodeQuery $query): Collection { $locale = $query->getLocale(); @@ -105,9 +95,6 @@ public function geocodeQuery(GeocodeQuery $query): Collection return $this->provider->geocodeQuery($query); } - /** - * {@inheritdoc} - */ public function reverseQuery(ReverseQuery $query): Collection { $locale = $query->getLocale(); @@ -118,11 +105,6 @@ public function reverseQuery(ReverseQuery $query): Collection return $this->provider->reverseQuery($query); } - /** - * @param string $locale - * - * @return StatefulGeocoder - */ public function setLocale(string $locale): self { $this->locale = $locale; @@ -130,11 +112,6 @@ public function setLocale(string $locale): self return $this; } - /** - * @param Bounds $bounds - * - * @return StatefulGeocoder - */ public function setBounds(Bounds $bounds): self { $this->bounds = $bounds; @@ -142,11 +119,6 @@ public function setBounds(Bounds $bounds): self return $this; } - /** - * @param int $limit - * - * @return StatefulGeocoder - */ public function setLimit(int $limit): self { $this->limit = $limit; @@ -154,9 +126,6 @@ public function setLimit(int $limit): self return $this; } - /** - * {@inheritdoc} - */ public function getName(): string { return 'stateful_geocoder'; diff --git a/Tests/Dumper/GpxTest.php b/Tests/Dumper/GpxTest.php index 297cdaf1..ccd5b06f 100644 --- a/Tests/Dumper/GpxTest.php +++ b/Tests/Dumper/GpxTest.php @@ -12,8 +12,8 @@ namespace Geocoder\Tests\Dumper; -use Geocoder\Geocoder; use Geocoder\Dumper\Gpx; +use Geocoder\Geocoder; use Geocoder\Model\Address; use PHPUnit\Framework\TestCase; @@ -49,7 +49,7 @@ public function testDump() GPX - , Geocoder::VERSION, '0', '0'); + , Geocoder::VERSION, '0', '0'); $result = $this->dumper->dump($address); @@ -78,7 +78,7 @@ public function testDumpWithData() GPX - , Geocoder::VERSION, $address->getCoordinates()->getLatitude(), $address->getCoordinates()->getLongitude()); + , Geocoder::VERSION, $address->getCoordinates()->getLatitude(), $address->getCoordinates()->getLongitude()); $result = $this->dumper->dump($address); @@ -115,7 +115,7 @@ public function testDumpWithBounds() GPX - , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); + , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); $this->assertNotNull($address->getBounds()); @@ -160,7 +160,7 @@ public function testDumpWithName() GPX - , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); + , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); $this->assertNotNull($address->getBounds()); diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index ebea95c4..31c748fc 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -15,10 +15,10 @@ use Geocoder\Collection; use Geocoder\Model\Address; use Geocoder\Model\AddressCollection; +use Geocoder\Provider\Provider; +use Geocoder\ProviderAggregator; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\ProviderAggregator; -use Geocoder\Provider\Provider; use Nyholm\NSA; use PHPUnit\Framework\TestCase; diff --git a/TimedGeocoder.php b/TimedGeocoder.php index 4abebc53..94bac6fa 100644 --- a/TimedGeocoder.php +++ b/TimedGeocoder.php @@ -12,9 +12,9 @@ namespace Geocoder; +use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\Provider\Provider; use Symfony\Component\Stopwatch\Stopwatch; /** @@ -42,9 +42,6 @@ public function __construct(Provider $delegate, Stopwatch $stopwatch) $this->stopwatch = $stopwatch; } - /** - * {@inheritdoc} - */ public function geocodeQuery(GeocodeQuery $query): Collection { $this->stopwatch->start('geocode', 'geocoder'); @@ -62,9 +59,6 @@ public function geocodeQuery(GeocodeQuery $query): Collection return $result; } - /** - * {@inheritdoc} - */ public function reverseQuery(ReverseQuery $query): Collection { $this->stopwatch->start('reverse', 'geocoder'); From 9d009e5d0246c65ddd44c07c18560c63d72cc415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Mon, 31 Jul 2023 21:52:23 +0200 Subject: [PATCH 51/61] Drop support for PHP 7.4 (#1197) * Remove PHP 7.4 * Remove remaining .travis.yml * Update CI for GeoIP * Deprecate Geoip provider geoip extension doesn't seem to be available in PHP 8. --- .github/workflows/component.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index af55ac97..c471a222 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1', '8.2'] + php-version: ['8.0', '8.1', '8.2'] steps: - uses: actions/checkout@v3 - name: Use PHP ${{ matrix.php-version }} diff --git a/composer.json b/composer.json index 0aa5132c..82b9332e 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.4 || ^8.0" + "php": "^8.0" }, "require-dev": { "nyholm/nsa": "^1.1", From 35fdf2ca9b6c8af02ce0f5954426085b32e6fa1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Mon, 31 Jul 2023 22:07:24 +0200 Subject: [PATCH 52/61] Enable PHPStan Level 6 (#1194) * Update phpstan.neon * Update YandexTest.php * Update TomTomTest.php * Update PickPointTest.php * Update PickPoint.php * Update PhotonTest.php * Update PeliasTest.php * Update OpenRouteServiceTest.php * Update OpenCageTest.php * Update OpenCage.php * Update NominatimTest.php * Update MaxMindBinaryTest.php * Update MaxMindTest.php * [WIP] Apply PHPStan fixes * Apply PHPCSFixer fixes * [WIP] Apply PHPStan fixes * [WIP] Apply PHPStan fixes * Revert "[WIP] Apply PHPStan fixes" This reverts commit 734c5c52fbcba4bc12cbda07b58d902a79d47891. * [WIP] Apply PHPStan fixes * [WIP] Apply PHPStan fixes * Update phpstan-baseline.neon --- Assert.php | 16 ++++-------- Dumper/AbstractArrayDumper.php | 3 +++ Dumper/Dumper.php | 2 +- Dumper/GeoArray.php | 3 +++ Exception/ProviderNotRegistered.php | 7 +++-- Location.php | 34 ++++++++----------------- Model/Address.php | 22 ++++++++-------- Model/AddressBuilder.php | 13 ++++------ Model/AdminLevelCollection.php | 4 ++- Model/Bounds.php | 2 ++ Model/Coordinates.php | 2 ++ Query/GeocodeQuery.php | 26 +++++++------------ Query/Query.php | 31 ++++++---------------- Query/ReverseQuery.php | 21 ++++++--------- Tests/Dumper/GeoArrayTest.php | 8 +++--- Tests/Dumper/GeoJsonTest.php | 8 +++--- Tests/Dumper/GpxTest.php | 8 +++--- Tests/Dumper/KmlTest.php | 4 +-- Tests/Dumper/WkbTest.php | 4 +-- Tests/Dumper/WktTest.php | 4 +-- Tests/Formatter/StringFormatterTest.php | 9 +++++-- Tests/Model/AddressCollectionTest.php | 2 +- Tests/Model/AddressTest.php | 4 +-- Tests/ProviderAggregatorTest.php | 33 +++++++++++++----------- Tests/Query/GeocodeQueryTest.php | 2 +- Tests/Query/ReverseQueryTest.php | 2 +- Tests/TimedGeocoderTest.php | 8 +++--- TimedGeocoder.php | 2 +- 28 files changed, 129 insertions(+), 155 deletions(-) diff --git a/Assert.php b/Assert.php index 92738c86..c9363209 100644 --- a/Assert.php +++ b/Assert.php @@ -16,10 +16,7 @@ class Assert { - /** - * @param float $value - */ - public static function latitude($value, string $message = '') + public static function latitude(mixed $value, string $message = ''): void { self::float($value, $message); if ($value < -90 || $value > 90) { @@ -27,10 +24,7 @@ public static function latitude($value, string $message = '') } } - /** - * @param float $value - */ - public static function longitude($value, string $message = '') + public static function longitude(mixed $value, string $message = ''): void { self::float($value, $message); if ($value < -180 || $value > 180) { @@ -38,19 +32,19 @@ public static function longitude($value, string $message = '') } } - public static function notNull($value, string $message = '') + public static function notNull(mixed $value, string $message = ''): void { if (null === $value) { throw new InvalidArgument(sprintf($message ?: 'Value cannot be null')); } } - private static function typeToString($value): string + private static function typeToString(mixed $value): string { return is_object($value) ? get_class($value) : gettype($value); } - private static function float($value, string $message) + private static function float(mixed $value, string $message): void { if (!is_float($value)) { throw new InvalidArgument(sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value))); diff --git a/Dumper/AbstractArrayDumper.php b/Dumper/AbstractArrayDumper.php index ae654639..e7873cc4 100644 --- a/Dumper/AbstractArrayDumper.php +++ b/Dumper/AbstractArrayDumper.php @@ -19,6 +19,9 @@ */ abstract class AbstractArrayDumper { + /** + * @return array{type: 'Feature', geometry: array{type: 'Point', coordinates: array{0: float, 1: float}}, properties: array, bounds?: array{south: float, west: float, north: float, east: float}} + */ protected function getArray(Location $location): array { $properties = array_filter($location->toArray(), function ($value) { diff --git a/Dumper/Dumper.php b/Dumper/Dumper.php index 8903e9cd..18589fa9 100644 --- a/Dumper/Dumper.php +++ b/Dumper/Dumper.php @@ -23,5 +23,5 @@ interface Dumper * Dumps an `Location` object as a string representation of * the implemented format. */ - public function dump(Location $location); + public function dump(Location $location): mixed; } diff --git a/Dumper/GeoArray.php b/Dumper/GeoArray.php index df74889f..495cf7be 100644 --- a/Dumper/GeoArray.php +++ b/Dumper/GeoArray.php @@ -19,6 +19,9 @@ */ final class GeoArray extends AbstractArrayDumper implements Dumper { + /** + * @return array{type: 'Feature', geometry: array{type: 'Point', coordinates: array{0: float, 1: float}}, properties: array, bounds?: array{south: float, west: float, north: float, east: float}} + */ public function dump(Location $location): array { return $this->getArray($location); diff --git a/Exception/ProviderNotRegistered.php b/Exception/ProviderNotRegistered.php index 38d56fb0..9bd57f8c 100644 --- a/Exception/ProviderNotRegistered.php +++ b/Exception/ProviderNotRegistered.php @@ -17,7 +17,10 @@ */ final class ProviderNotRegistered extends \RuntimeException implements Exception { - public static function create(string $providerName, array $registeredProviders = []) + /** + * @param string[] $registeredProviders + */ + public static function create(string $providerName, array $registeredProviders = []): self { return new self(sprintf( 'Provider "%s" is not registered, so you cannot use it. Did you forget to register it or made a typo?%s', @@ -26,7 +29,7 @@ public static function create(string $providerName, array $registeredProviders = )); } - public static function noProviderRegistered() + public static function noProviderRegistered(): self { return new self('No provider registered.'); } diff --git a/Location.php b/Location.php index c1148982..fc31f9c6 100644 --- a/Location.php +++ b/Location.php @@ -27,17 +27,13 @@ interface Location { /** * Will always return the coordinates value object. - * - * @return Coordinates|null */ - public function getCoordinates(); + public function getCoordinates(): ?Coordinates; /** * Returns the bounds value object. - * - * @return Bounds|null */ - public function getBounds(); + public function getBounds(): ?Bounds; /** * Returns the street number value. @@ -48,32 +44,24 @@ public function getStreetNumber(); /** * Returns the street name value. - * - * @return string|null */ - public function getStreetName(); + public function getStreetName(): ?string; /** * Returns the city or locality value. - * - * @return string|null */ - public function getLocality(); + public function getLocality(): ?string; /** * Returns the postal code or zipcode value. - * - * @return string|null */ - public function getPostalCode(); + public function getPostalCode(): ?string; /** * Returns the locality district, or * sublocality, or neighborhood. - * - * @return string|null */ - public function getSubLocality(); + public function getSubLocality(): ?string; /** * Returns the administrative levels. @@ -84,22 +72,20 @@ public function getAdminLevels(): AdminLevelCollection; /** * Returns the country value object. - * - * @return Country|null */ - public function getCountry(); + public function getCountry(): ?Country; /** * Returns the timezone for the Location. The timezone MUST be in the list of supported timezones. * * {@link http://php.net/manual/en/timezones.php} - * - * @return string|null */ - public function getTimezone(); + public function getTimezone(): ?string; /** * Returns an array with data indexed by name. + * + * @return array */ public function toArray(): array; diff --git a/Model/Address.php b/Model/Address.php index a5f719d6..49082b7f 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -105,37 +105,37 @@ public function getProvidedBy(): string return $this->providedBy; } - public function getCoordinates() + public function getCoordinates(): ?Coordinates { return $this->coordinates; } - public function getBounds() + public function getBounds(): ?Bounds { return $this->bounds; } - public function getStreetNumber() + public function getStreetNumber(): ?string { return $this->streetNumber; } - public function getStreetName() + public function getStreetName(): ?string { return $this->streetName; } - public function getLocality() + public function getLocality(): ?string { return $this->locality; } - public function getPostalCode() + public function getPostalCode(): ?string { return $this->postalCode; } - public function getSubLocality() + public function getSubLocality(): ?string { return $this->subLocality; } @@ -145,12 +145,12 @@ public function getAdminLevels(): AdminLevelCollection return $this->adminLevels; } - public function getCountry() + public function getCountry(): ?Country { return $this->country; } - public function getTimezone() + public function getTimezone(): ?string { return $this->timezone; } @@ -158,6 +158,8 @@ public function getTimezone() /** * Create an Address with an array. Useful for testing. * + * @param array $data + * * @return static */ public static function createFromArray(array $data) @@ -259,7 +261,7 @@ private static function createCountry($name, $code) * * @return Bounds|null */ - private static function createBounds($south, $west, $north, $east) + private static function createBounds(?float $south, ?float $west, ?float $north, ?float $east) { if (null === $south || null === $west || null === $north || null === $east) { return null; diff --git a/Model/AddressBuilder.php b/Model/AddressBuilder.php index d8b2e257..b1a0834f 100644 --- a/Model/AddressBuilder.php +++ b/Model/AddressBuilder.php @@ -63,7 +63,7 @@ final class AddressBuilder private $subLocality; /** - * @var array + * @var AdminLevel[] */ private $adminLevels = []; @@ -85,7 +85,7 @@ final class AddressBuilder /** * A storage for extra parameters. * - * @var array + * @var array */ private $data = []; @@ -210,7 +210,7 @@ public function setSubLocality($subLocality): self } /** - * @param array $adminLevels + * @param AdminLevel[] $adminLevels */ public function setAdminLevels($adminLevels): self { @@ -249,17 +249,14 @@ public function setTimezone($timezone): self return $this; } - public function setValue(string $name, $value): self + public function setValue(string $name, mixed $value): self { $this->data[$name] = $value; return $this; } - /** - * @param mixed|null $default - */ - public function getValue(string $name, $default = null) + public function getValue(string $name, mixed $default = null): mixed { if ($this->hasValue($name)) { return $this->data[$name]; diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index 84d3296e..6b20fc0a 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -18,6 +18,8 @@ /** * @author Giorgio Premi + * + * @phpstan-implements \IteratorAggregate */ final class AdminLevelCollection implements \IteratorAggregate, \Countable { @@ -111,7 +113,7 @@ public function all(): array /** * @throws \OutOfBoundsException */ - private function checkLevel(int $level) + private function checkLevel(int $level): void { if ($level <= 0 || $level > self::MAX_LEVEL_DEPTH) { throw new OutOfBounds(sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level)); diff --git a/Model/Bounds.php b/Model/Bounds.php index 6bf74343..832ee968 100644 --- a/Model/Bounds.php +++ b/Model/Bounds.php @@ -102,6 +102,8 @@ public function getEast(): float /** * Returns an array with bounds. + * + * @return array{south: float, west: float, north: float, east: float} */ public function toArray(): array { diff --git a/Model/Coordinates.php b/Model/Coordinates.php index 861f374b..1e8ce527 100644 --- a/Model/Coordinates.php +++ b/Model/Coordinates.php @@ -66,6 +66,8 @@ public function getLongitude(): float /** * Returns the coordinates as a tuple. + * + * @return array{float, float} */ public function toArray(): array { diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 2aefd620..331b23df 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -44,7 +44,7 @@ final class GeocodeQuery implements Query private $limit = Geocoder::DEFAULT_RESULT_LIMIT; /** - * @var array + * @var array */ private $data = []; @@ -94,7 +94,7 @@ public function withLimit(int $limit): self return $new; } - public function withData(string $name, $value): self + public function withData(string $name, mixed $value): self { $new = clone $this; $new->data[$name] = $value; @@ -107,18 +107,12 @@ public function getText(): string return $this->text; } - /** - * @return Bounds|null - */ - public function getBounds() + public function getBounds(): ?Bounds { return $this->bounds; } - /** - * @return string|null - */ - public function getLocale() + public function getLocale(): ?string { return $this->locale; } @@ -128,10 +122,7 @@ public function getLimit(): int return $this->limit; } - /** - * @param mixed|null $default - */ - public function getData(string $name, $default = null) + public function getData(string $name, mixed $default = null): mixed { if (!array_key_exists($name, $this->data)) { return $default; @@ -140,6 +131,9 @@ public function getData(string $name, $default = null) return $this->data[$name]; } + /** + * @return array + */ public function getAllData(): array { return $this->data; @@ -147,10 +141,8 @@ public function getAllData(): array /** * String for logging. This is also a unique key for the query. - * - * @return string */ - public function __toString() + public function __toString(): string { return sprintf('GeocodeQuery: %s', json_encode([ 'text' => $this->getText(), diff --git a/Query/Query.php b/Query/Query.php index 8ffbe657..32bb4ba9 100644 --- a/Query/Query.php +++ b/Query/Query.php @@ -17,37 +17,22 @@ */ interface Query { - /** - * @return Query - */ - public function withLocale(string $locale); + public function withLocale(string $locale): Query; - /** - * @return Query - */ - public function withLimit(int $limit); + public function withLimit(int $limit): Query; - /** - * @return Query - */ - public function withData(string $name, $value); + public function withData(string $name, mixed $value): Query; - /** - * @return string|null - */ - public function getLocale(); + public function getLocale(): ?string; public function getLimit(): int; + public function getData(string $name, mixed $default = null): mixed; + /** - * @param mixed|null $default + * @return array */ - public function getData(string $name, $default = null); - public function getAllData(): array; - /** - * @return string - */ - public function __toString(); + public function __toString(): string; } diff --git a/Query/ReverseQuery.php b/Query/ReverseQuery.php index 39db8280..ca28e22e 100644 --- a/Query/ReverseQuery.php +++ b/Query/ReverseQuery.php @@ -36,7 +36,7 @@ final class ReverseQuery implements Query private $limit = Geocoder::DEFAULT_RESULT_LIMIT; /** - * @var array + * @var array */ private $data = []; @@ -86,7 +86,7 @@ public function withLocale(string $locale): self return $new; } - public function withData(string $name, $value): self + public function withData(string $name, mixed $value): self { $new = clone $this; $new->data[$name] = $value; @@ -104,18 +104,12 @@ public function getLimit(): int return $this->limit; } - /** - * @return string - */ - public function getLocale() + public function getLocale(): ?string { return $this->locale; } - /** - * @param mixed|null $default - */ - public function getData(string $name, $default = null) + public function getData(string $name, mixed $default = null): mixed { if (!array_key_exists($name, $this->data)) { return $default; @@ -124,6 +118,9 @@ public function getData(string $name, $default = null) return $this->data[$name]; } + /** + * @return array + */ public function getAllData(): array { return $this->data; @@ -131,10 +128,8 @@ public function getAllData(): array /** * String for logging. This is also a unique key for the query. - * - * @return string */ - public function __toString() + public function __toString(): string { return sprintf('ReverseQuery: %s', json_encode([ 'lat' => $this->getCoordinates()->getLatitude(), diff --git a/Tests/Dumper/GeoArrayTest.php b/Tests/Dumper/GeoArrayTest.php index 800d239d..ac90a3df 100644 --- a/Tests/Dumper/GeoArrayTest.php +++ b/Tests/Dumper/GeoArrayTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $this->dumper = new GeoArray(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = [ @@ -51,7 +51,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -75,7 +75,7 @@ public function testDumpWithData() $this->assertEquals($expected, $result); } - public function testDumpWithBounds() + public function testDumpWithBounds(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -111,7 +111,7 @@ public function testDumpWithBounds() $this->assertEquals($expected, $result); } - public function testDumpWithProperties() + public function testDumpWithProperties(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Dumper/GeoJsonTest.php b/Tests/Dumper/GeoJsonTest.php index eee43a08..c4bfdb2c 100644 --- a/Tests/Dumper/GeoJsonTest.php +++ b/Tests/Dumper/GeoJsonTest.php @@ -32,7 +32,7 @@ public function setUp(): void $this->dumper = new GeoJson(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = [ @@ -52,7 +52,7 @@ public function testDump() $this->assertEquals($expected, json_decode($result, true)); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -76,7 +76,7 @@ public function testDumpWithData() $this->assertEquals($expected, json_decode($result, true)); } - public function testDumpWithBounds() + public function testDumpWithBounds(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -112,7 +112,7 @@ public function testDumpWithBounds() $this->assertEquals($expected, json_decode($result, true)); } - public function testDumpWithProperties() + public function testDumpWithProperties(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Dumper/GpxTest.php b/Tests/Dumper/GpxTest.php index ccd5b06f..a00f4475 100644 --- a/Tests/Dumper/GpxTest.php +++ b/Tests/Dumper/GpxTest.php @@ -32,7 +32,7 @@ public function setUp(): void $this->dumper = new Gpx(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = sprintf(<<<'GPX' @@ -57,7 +57,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -86,7 +86,7 @@ public function testDumpWithData() $this->assertEquals($expected, $result); } - public function testDumpWithBounds() + public function testDumpWithBounds(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -125,7 +125,7 @@ public function testDumpWithBounds() $this->assertEquals($expected, $result); } - public function testDumpWithName() + public function testDumpWithName(): void { $bounds = [ 'south' => 48.8631507, diff --git a/Tests/Dumper/KmlTest.php b/Tests/Dumper/KmlTest.php index 7d1331c0..05eec4a2 100644 --- a/Tests/Dumper/KmlTest.php +++ b/Tests/Dumper/KmlTest.php @@ -32,7 +32,7 @@ public function setUp(): void $this->dumper = new Kml(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = <<<'KML' @@ -56,7 +56,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Dumper/WkbTest.php b/Tests/Dumper/WkbTest.php index 4808632f..14abc04c 100644 --- a/Tests/Dumper/WkbTest.php +++ b/Tests/Dumper/WkbTest.php @@ -32,7 +32,7 @@ public function setUp(): void $this->dumper = new Wkb(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = pack('H*', '010100000000000000000000000000000000000000'); @@ -42,7 +42,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Dumper/WktTest.php b/Tests/Dumper/WktTest.php index 8a135c5b..9fc8982d 100644 --- a/Tests/Dumper/WktTest.php +++ b/Tests/Dumper/WktTest.php @@ -32,7 +32,7 @@ public function setUp(): void $this->dumper = new Wkt(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = sprintf('POINT(%F %F)', 0, 0); @@ -42,7 +42,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Formatter/StringFormatterTest.php b/Tests/Formatter/StringFormatterTest.php index 89b9c3da..3b0359e5 100644 --- a/Tests/Formatter/StringFormatterTest.php +++ b/Tests/Formatter/StringFormatterTest.php @@ -33,8 +33,10 @@ public function setUp(): void /** * @dataProvider dataProviderForTestFormat + * + * @param array $data */ - public function testFormat($data, $format, $expected) + public function testFormat(array $data, string $format, string $expected): void { $address = Address::createFromArray($data); $result = $this->formatter->format($address, $format); @@ -43,7 +45,10 @@ public function testFormat($data, $format, $expected) $this->assertEquals($expected, $result); } - public function dataProviderForTestFormat() + /** + * @return array>|string>|string>> + */ + public function dataProviderForTestFormat(): array { return [ [ diff --git a/Tests/Model/AddressCollectionTest.php b/Tests/Model/AddressCollectionTest.php index 877987f4..6ad6dcd3 100644 --- a/Tests/Model/AddressCollectionTest.php +++ b/Tests/Model/AddressCollectionTest.php @@ -20,7 +20,7 @@ */ class AddressCollectionTest extends TestCase { - public function testFirstOnEmpty() + public function testFirstOnEmpty(): void { $this->expectException(\Geocoder\Exception\CollectionIsEmpty::class); diff --git a/Tests/Model/AddressTest.php b/Tests/Model/AddressTest.php index 15cb5d47..2995be28 100644 --- a/Tests/Model/AddressTest.php +++ b/Tests/Model/AddressTest.php @@ -21,7 +21,7 @@ */ class AddressTest extends TestCase { - public function testDumpEmptyAddress() + public function testDumpEmptyAddress(): void { $expected = [ 'providedBy' => 'n/a', @@ -48,7 +48,7 @@ public function testDumpEmptyAddress() $this->assertEquals($address->toArray(), $expected); } - public function testToArray() + public function testToArray(): void { $data = [ 'providedBy' => 'n/a', diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index 31c748fc..579e568e 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -37,7 +37,7 @@ protected function setUp(): void $this->geocoder = new ProviderAggregator(); } - public function testGeocode() + public function testGeocode(): void { $provider1 = new MockProvider('test1'); $provider1->result = [Address::createFromArray(['providedBy' => 'p1'])]; @@ -51,7 +51,7 @@ public function testGeocode() $this->assertEquals('p1', $result->first()->getProvidedBy()); } - public function testReverse() + public function testReverse(): void { $provider1 = new MockProvider('test1'); $provider1->result = [Address::createFromArray(['providedBy' => 'p1'])]; @@ -66,7 +66,7 @@ public function testReverse() $this->assertEquals('p2', $result->first()->getProvidedBy()); } - public function testRegisterProvider() + public function testRegisterProvider(): void { $provider = new MockProvider('test'); $this->geocoder->registerProvider($provider); @@ -74,7 +74,7 @@ public function testRegisterProvider() $this->assertSame(['test' => $provider], NSA::getProperty($this->geocoder, 'providers')); } - public function testRegisterProviders() + public function testRegisterProviders(): void { $provider = new MockProvider('test'); $this->geocoder->registerProviders([$provider]); @@ -82,7 +82,7 @@ public function testRegisterProviders() $this->assertSame(['test' => $provider], NSA::getProperty($this->geocoder, 'providers')); } - public function testUsingNonExistantProviderShouldThrowAnException() + public function testUsingNonExistantProviderShouldThrowAnException(): void { $this->expectException(\Geocoder\Exception\ProviderNotRegistered::class); $this->expectExceptionMessage('Provider "non_existant" is not registered, so you cannot use it. Did you forget to register it or made a typo? Registered providers are: test1.'); @@ -92,14 +92,14 @@ public function testUsingNonExistantProviderShouldThrowAnException() $this->geocoder->using('non_existant'); } - public function testUsingAnEmptyProviderNameShouldThrowAnException() + public function testUsingAnEmptyProviderNameShouldThrowAnException(): void { $this->expectException(\Geocoder\Exception\ProviderNotRegistered::class); $this->geocoder->using(''); } - public function testGetProviders() + public function testGetProviders(): void { $provider1 = new MockProvider('test1'); $provider2 = new MockProvider('test2'); @@ -117,7 +117,7 @@ public function testGetProviders() $this->assertArrayHasKey('test2', $result); } - public function testGetProvider() + public function testGetProvider(): void { $this->expectException(\RuntimeException::class); @@ -125,7 +125,7 @@ public function testGetProvider() $this->fail('getProvider() should throw an exception'); } - public function testGetProviderWithMultipleProvidersReturnsTheFirstOne() + public function testGetProviderWithMultipleProvidersReturnsTheFirstOne(): void { $providers = [ $provider1 = new MockProvider('test1'), @@ -141,11 +141,14 @@ public function testGetProviderWithMultipleProvidersReturnsTheFirstOne() class MockProvider implements Provider { - protected $name; + protected string $name; - public $result = []; + /** + * @var Address[] + */ + public array $result = []; - public function __construct($name) + public function __construct(string $name) { $this->name = $name; } @@ -165,16 +168,16 @@ public function getName(): string return $this->name; } - public function getLimit() + public function getLimit(): void { } - public function limit($limit) + public function limit(int $limit): self { return $this; } - private function returnResult() + private function returnResult(): AddressCollection { return new AddressCollection($this->result); } diff --git a/Tests/Query/GeocodeQueryTest.php b/Tests/Query/GeocodeQueryTest.php index c14f3481..e224fc3d 100644 --- a/Tests/Query/GeocodeQueryTest.php +++ b/Tests/Query/GeocodeQueryTest.php @@ -18,7 +18,7 @@ */ class GeocodeQueryTest extends TestCase { - public function testToString() + public function testToString(): void { $query = GeocodeQuery::create('foo'); $query = $query->withLocale('en'); diff --git a/Tests/Query/ReverseQueryTest.php b/Tests/Query/ReverseQueryTest.php index 9bb815e0..5c5baa47 100644 --- a/Tests/Query/ReverseQueryTest.php +++ b/Tests/Query/ReverseQueryTest.php @@ -18,7 +18,7 @@ */ class ReverseQueryTest extends TestCase { - public function testToString() + public function testToString(): void { $query = ReverseQuery::fromCoordinates(1, 2); $query = $query->withLocale('en'); diff --git a/Tests/TimedGeocoderTest.php b/Tests/TimedGeocoderTest.php index 318ef408..ca8b130b 100644 --- a/Tests/TimedGeocoderTest.php +++ b/Tests/TimedGeocoderTest.php @@ -43,7 +43,7 @@ protected function setUp(): void $this->geocoder = new TimedGeocoder($this->delegate, $this->stopwatch); } - public function testGeocode() + public function testGeocode(): void { $this->delegate->expects($this->once()) ->method('geocodeQuery') @@ -54,7 +54,7 @@ public function testGeocode() $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__')); } - public function testGeocodeThrowsException() + public function testGeocodeThrowsException(): void { $this->delegate->expects($this->once()) ->method('geocodeQuery') @@ -70,7 +70,7 @@ public function testGeocodeThrowsException() $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__')); } - public function testReverse() + public function testReverse(): void { $this->delegate->expects($this->once()) ->method('reverseQuery') @@ -81,7 +81,7 @@ public function testReverse() $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__')); } - public function testReverseThrowsException() + public function testReverseThrowsException(): void { $this->delegate->expects($this->once()) ->method('reverseQuery') diff --git a/TimedGeocoder.php b/TimedGeocoder.php index 94bac6fa..07186ee3 100644 --- a/TimedGeocoder.php +++ b/TimedGeocoder.php @@ -76,7 +76,7 @@ public function reverseQuery(ReverseQuery $query): Collection return $result; } - public function __call($method, $args) + public function __call(string $method, array $args): mixed { return call_user_func_array([$this->delegate, $method], $args); } From 3ca3b42535c93f41b359a94bd7cc6cd8c52a54aa Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 15 Dec 2023 17:28:59 +0100 Subject: [PATCH 53/61] Replace HTTPlug factories by PSR-17 (#1184) * Replace HTTPlug factories by PSR-17 * minor fix --------- Co-authored-by: Nyholm --- Model/Address.php | 4 ---- Model/Country.php | 4 ---- ProviderAggregator.php | 1 - StatefulGeocoder.php | 3 --- composer.json | 5 +++++ 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Model/Address.php b/Model/Address.php index 49082b7f..a80f7fbc 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -255,10 +255,6 @@ private static function createCountry($name, $code) } /** - * @param float $south - * @param float $west - * @param float $north - * * @return Bounds|null */ private static function createBounds(?float $south, ?float $west, ?float $north, ?float $east) diff --git a/Model/Country.php b/Model/Country.php index 69b65f9a..543637e3 100644 --- a/Model/Country.php +++ b/Model/Country.php @@ -31,10 +31,6 @@ final class Country */ private $code; - /** - * @param string $name - * @param string $code - */ public function __construct(string $name = null, string $code = null) { if (null === $name && null === $code) { diff --git a/ProviderAggregator.php b/ProviderAggregator.php index d42ec7bb..056d75b2 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -131,7 +131,6 @@ public function getProviders(): array * * @param GeocodeQuery|ReverseQuery $query * @param Provider[] $providers - * @param Provider $currentProvider * * @throws ProviderNotRegistered */ diff --git a/StatefulGeocoder.php b/StatefulGeocoder.php index 8610fe3d..5827fa0e 100644 --- a/StatefulGeocoder.php +++ b/StatefulGeocoder.php @@ -42,9 +42,6 @@ final class StatefulGeocoder implements Geocoder */ private $provider; - /** - * @param string $locale - */ public function __construct(Provider $provider, string $locale = null) { $this->provider = $provider; diff --git a/composer.json b/composer.json index 82b9332e..d5d10023 100644 --- a/composer.json +++ b/composer.json @@ -43,5 +43,10 @@ "scripts": { "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" + }, + "config": { + "allow-plugins": { + "php-http/discovery": false + } } } \ No newline at end of file From f1e4dd58e560834a0ecf50b1d1239c191fcabc95 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 2 Mar 2024 11:52:31 +0100 Subject: [PATCH 54/61] chore: bump github action "actions/checkout" 3 => 4 to fix deprecations (#1216) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christopher Georg Co-authored-by: Jonathan Beliën --- .github/workflows/component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index c471a222..483e8c8f 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -15,7 +15,7 @@ jobs: matrix: php-version: ['8.0', '8.1', '8.2'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use PHP ${{ matrix.php-version }} uses: shivammathur/setup-php@v2 with: From 714785094267292f8223eed19245e5f9c0f2120f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 2 Mar 2024 12:00:56 +0100 Subject: [PATCH 55/61] =?UTF-8?q?=F0=9F=9A=A8=20Apply=20PHP=20CS=20Fixer?= =?UTF-8?q?=20fixes=20(#1219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Collection.php | 2 +- Geocoder.php | 4 ++-- Model/Address.php | 18 +++++++++--------- Model/AddressBuilder.php | 2 +- Model/AddressCollection.php | 2 +- Model/AdminLevel.php | 2 +- Model/AdminLevelCollection.php | 2 +- Model/Country.php | 2 +- ProviderAggregator.php | 4 ++-- StatefulGeocoder.php | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Collection.php b/Collection.php index 32e32074..e6ccc86b 100644 --- a/Collection.php +++ b/Collection.php @@ -35,7 +35,7 @@ public function isEmpty(): bool; /** * @return Location[] */ - public function slice(int $offset, int $length = null); + public function slice(int $offset, ?int $length = null); public function has(int $index): bool; diff --git a/Geocoder.php b/Geocoder.php index 82032aef..528396a9 100644 --- a/Geocoder.php +++ b/Geocoder.php @@ -34,14 +34,14 @@ interface Geocoder extends Provider /** * Geocodes a given value. * - * @throws \Geocoder\Exception\Exception + * @throws Exception\Exception */ public function geocode(string $value): Collection; /** * Reverses geocode given latitude and longitude values. * - * @throws \Geocoder\Exception\Exception + * @throws Exception\Exception */ public function reverse(float $latitude, float $longitude): Collection; } diff --git a/Model/Address.php b/Model/Address.php index a80f7fbc..d723c19e 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -77,15 +77,15 @@ class Address implements Location final public function __construct( string $providedBy, AdminLevelCollection $adminLevels, - Coordinates $coordinates = null, - Bounds $bounds = null, - string $streetNumber = null, - string $streetName = null, - string $postalCode = null, - string $locality = null, - string $subLocality = null, - Country $country = null, - string $timezone = null + ?Coordinates $coordinates = null, + ?Bounds $bounds = null, + ?string $streetNumber = null, + ?string $streetName = null, + ?string $postalCode = null, + ?string $locality = null, + ?string $subLocality = null, + ?Country $country = null, + ?string $timezone = null ) { $this->providedBy = $providedBy; $this->adminLevels = $adminLevels; diff --git a/Model/AddressBuilder.php b/Model/AddressBuilder.php index b1a0834f..3534a2ea 100644 --- a/Model/AddressBuilder.php +++ b/Model/AddressBuilder.php @@ -152,7 +152,7 @@ public function setCoordinates($latitude, $longitude): self return $this; } - public function addAdminLevel(int $level, string $name, string $code = null): self + public function addAdminLevel(int $level, string $name, ?string $code = null): self { $this->adminLevels[] = new AdminLevel($level, $name, $code); diff --git a/Model/AddressCollection.php b/Model/AddressCollection.php index a1f50414..83af64aa 100644 --- a/Model/AddressCollection.php +++ b/Model/AddressCollection.php @@ -59,7 +59,7 @@ public function isEmpty(): bool /** * @return Location[] */ - public function slice(int $offset, int $length = null) + public function slice(int $offset, ?int $length = null) { return array_slice($this->locations, $offset, $length); } diff --git a/Model/AdminLevel.php b/Model/AdminLevel.php index 523669da..dab0baf2 100644 --- a/Model/AdminLevel.php +++ b/Model/AdminLevel.php @@ -32,7 +32,7 @@ final class AdminLevel */ private $code; - public function __construct(int $level, string $name, string $code = null) + public function __construct(int $level, string $name, ?string $code = null) { $this->level = $level; $this->name = $name; diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index 6b20fc0a..006e1d7a 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -77,7 +77,7 @@ public function first(): AdminLevel /** * @return AdminLevel[] */ - public function slice(int $offset, int $length = null): array + public function slice(int $offset, ?int $length = null): array { return array_slice($this->adminLevels, $offset, $length, true); } diff --git a/Model/Country.php b/Model/Country.php index 543637e3..b27975f0 100644 --- a/Model/Country.php +++ b/Model/Country.php @@ -31,7 +31,7 @@ final class Country */ private $code; - public function __construct(string $name = null, string $code = null) + public function __construct(?string $name = null, ?string $code = null) { if (null === $name && null === $code) { throw new InvalidArgument('A country must have either a name or a code'); diff --git a/ProviderAggregator.php b/ProviderAggregator.php index 056d75b2..e4d1fe61 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -45,7 +45,7 @@ class ProviderAggregator implements Geocoder */ private $decider; - public function __construct(callable $decider = null, int $limit = Geocoder::DEFAULT_RESULT_LIMIT) + public function __construct(?callable $decider = null, int $limit = Geocoder::DEFAULT_RESULT_LIMIT) { $this->limit = $limit; $this->decider = $decider ?? __CLASS__.'::getProvider'; @@ -134,7 +134,7 @@ public function getProviders(): array * * @throws ProviderNotRegistered */ - private static function getProvider($query, array $providers, Provider $currentProvider = null): Provider + private static function getProvider($query, array $providers, ?Provider $currentProvider = null): Provider { if (null !== $currentProvider) { return $currentProvider; diff --git a/StatefulGeocoder.php b/StatefulGeocoder.php index 5827fa0e..4a2d5704 100644 --- a/StatefulGeocoder.php +++ b/StatefulGeocoder.php @@ -42,7 +42,7 @@ final class StatefulGeocoder implements Geocoder */ private $provider; - public function __construct(Provider $provider, string $locale = null) + public function __construct(Provider $provider, ?string $locale = null) { $this->provider = $provider; $this->locale = $locale; From 67eb8ff18c2e6df582ae11708cc862ba8b3f2f04 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 4 Mar 2024 10:43:01 +0100 Subject: [PATCH 56/61] chore: add testruns for PHP 8.3 (#1222) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christopher Georg Co-authored-by: Jonathan Beliën --- .github/workflows/component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index 483e8c8f..1959046e 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.0', '8.1', '8.2'] + php-version: ['8.0', '8.1', '8.2', '8.3'] steps: - uses: actions/checkout@v4 - name: Use PHP ${{ matrix.php-version }} From 058d51079e53c65e4a2036e1c2180d564cf353d9 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 14 Nov 2024 12:27:14 +0100 Subject: [PATCH 57/61] chore: add testruns for PHP 8.4 (#1235) * feat: bump dev dependencies * chore: add testruns for PHP 8.4 * chore: add testruns for PHP 8.4 * chore: add testruns for PHP 8.4 --------- Co-authored-by: Christopher Georg --- .github/workflows/component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index 1959046e..92d63bf0 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.0', '8.1', '8.2', '8.3'] + php-version: ['8.0', '8.1', '8.2', '8.3', '8.4'] steps: - uses: actions/checkout@v4 - name: Use PHP ${{ matrix.php-version }} From 9ff2234cca1d652f991d8a94afaaaee852ba09f3 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 14 Nov 2024 15:41:38 +0100 Subject: [PATCH 58/61] Feature/fix php cs (#1236) * feat: bump dev dependencies * chore: fix php cs --------- Co-authored-by: Christopher Georg --- Model/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Address.php b/Model/Address.php index d723c19e..250384fd 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -85,7 +85,7 @@ final public function __construct( ?string $locality = null, ?string $subLocality = null, ?Country $country = null, - ?string $timezone = null + ?string $timezone = null, ) { $this->providedBy = $providedBy; $this->adminLevels = $adminLevels; From a749e00819d2929bd0ec40fb79853956332970ba Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 1 Jan 2025 16:52:42 +0100 Subject: [PATCH 59/61] Prepare release of 5.0.0 for willdurand/geocoder (#1209) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Prepare release of 5.0.0 for willdurand/geocoder * Be more restrictrive with PHP versions * minor * Update matrix * minor * minor * cs fixes * Run tests on PHP 8.4 --------- Co-authored-by: Jonathan Beliën <1150563+jbelien@users.noreply.github.com> Co-authored-by: Jonathan Beliën --- .github/workflows/component.yml | 2 +- CHANGELOG.md | 5 +++++ composer.json | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index 92d63bf0..ccc5cc28 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.0', '8.1', '8.2', '8.3', '8.4'] + php-version: ['8.2', '8.3', '8.4'] steps: - uses: actions/checkout@v4 - name: Use PHP ${{ matrix.php-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index e060ede2..a9fe2493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 5.0.0 + +- Drop support for PHP < 8.2 +- Added return values on classes and interfaces + ## 4.6.0 ### Removed diff --git a/composer.json b/composer.json index d5d10023..fd4348f6 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0" + "php": ">=8.2" }, "require-dev": { "nyholm/nsa": "^1.1", @@ -29,7 +29,7 @@ }, "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "5.1-dev" } }, "autoload": { @@ -49,4 +49,4 @@ "php-http/discovery": false } } -} \ No newline at end of file +} From 72bd9e088ff1c17dc5b7df31fa19a91e877d0715 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 19 Jan 2025 12:27:00 +0100 Subject: [PATCH 60/61] Update symfony/stopwatch requirement from ~2.5 || ~5.0 to ~2.5 || ~5.0 || ~7.0 in /src/Common (#1238) Update symfony/stopwatch requirement from ~2.5 || ~5.0 to ~2.5 || ~5.0 || ~7.0 --- updated-dependencies: - dependency-name: symfony/stopwatch dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fd4348f6..122e72ec 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "nyholm/nsa": "^1.1", "phpunit/phpunit": "^9.5", - "symfony/stopwatch": "~2.5 || ~5.0" + "symfony/stopwatch": "~2.5 || ~5.0 || ~7.0" }, "suggest": { "symfony/stopwatch": "If you want to use the TimedGeocoder" From 43f8145c74d3a3808c51e233fba60b68bd033d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Nork=C5=ABnas?= Date: Sat, 7 Jun 2025 11:08:41 +0300 Subject: [PATCH 61/61] Resolve some deprecations and remove igorw/get-in dependency (#1257) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove `igorw/get-in` dependency to simplify code * Fix phpunit deprecation * Simplify phpunit's `->will($this->returnValue())` with `->willReturn()` * Simplify phpunit's `->will($this->returnCallback())` with `->willReturnCallback()` * Fix deprecated mock builder `setMethds` with `createPartialMock` * Remove deprecated phpstan `checkGenericClassInNonGenericObjectType` option * Bump phpunit to 9.6 --------- Co-authored-by: Jonathan Beliën --- Tests/TimedGeocoderTest.php | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/TimedGeocoderTest.php b/Tests/TimedGeocoderTest.php index ca8b130b..4a735a08 100644 --- a/Tests/TimedGeocoderTest.php +++ b/Tests/TimedGeocoderTest.php @@ -47,7 +47,7 @@ public function testGeocode(): void { $this->delegate->expects($this->once()) ->method('geocodeQuery') - ->will($this->returnValue(new AddressCollection([]))); + ->willReturn(new AddressCollection([])); $this->geocoder->geocode('foo'); @@ -74,7 +74,7 @@ public function testReverse(): void { $this->delegate->expects($this->once()) ->method('reverseQuery') - ->will($this->returnValue(new AddressCollection([]))); + ->willReturn(new AddressCollection([])); $this->geocoder->reverse(0, 0); diff --git a/composer.json b/composer.json index 122e72ec..d67a506c 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "nyholm/nsa": "^1.1", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^9.6.11", "symfony/stopwatch": "~2.5 || ~5.0 || ~7.0" }, "suggest": {