From 33a88fcd3946ca97ae5cbca353d06c71665f0677 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] 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 --- GoogleMaps.php | 6 ++-- Model/GoogleAddress.php | 9 +++++- Tests/GoogleMapsTest.php | 66 ++++++++++++++++++++-------------------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/GoogleMaps.php b/GoogleMaps.php index cb9d163..760cc97 100644 --- a/GoogleMaps.php +++ b/GoogleMaps.php @@ -275,7 +275,7 @@ private function fetchUrl(string $url, string $locale = null, int $limit, string * @param string $type Component type * @param object $values The component values */ - private function updateAddressComponent(AddressBuilder $builder, string $type, $values) + private function updateAddressComponent(AddressBuilder $builder, string $type, $values): void { switch ($type) { case 'postal_code': @@ -385,6 +385,8 @@ private function signQuery(string $query): string /** * Serialize the component query parameter. + * + * @param array $components */ private function serializeComponents(array $components): string { @@ -439,7 +441,7 @@ private function validateResponse(string $url, $content) * * @param \Stdclass $result */ - private function parseCoordinates(AddressBuilder $builder, $result) + private function parseCoordinates(AddressBuilder $builder, $result): void { $coordinates = $result->geometry->location; $builder->setCoordinates($coordinates->lat, $coordinates->lng); diff --git a/Model/GoogleAddress.php b/Model/GoogleAddress.php index c53f7b9..e8aa9ff 100644 --- a/Model/GoogleAddress.php +++ b/Model/GoogleAddress.php @@ -32,7 +32,7 @@ final class GoogleAddress extends Address private $locationType; /** - * @var array + * @var string[] */ private $resultType = []; @@ -161,12 +161,17 @@ public function getLocationType() return $this->locationType; } + /** + * @return string[] + */ public function getResultType(): array { return $this->resultType; } /** + * @param string[] $resultType + * * @return GoogleAddress */ public function withResultType(array $resultType) @@ -473,6 +478,8 @@ public function getSubLocalityLevels() } /** + * @param array $subLocalityLevel + * * @return $this */ public function withSubLocalityLevels(array $subLocalityLevel) diff --git a/Tests/GoogleMapsTest.php b/Tests/GoogleMapsTest.php index df03ded..6b5ba25 100644 --- a/Tests/GoogleMapsTest.php +++ b/Tests/GoogleMapsTest.php @@ -29,7 +29,7 @@ class GoogleMapsTest extends BaseTestCase */ private $testAPIKey = 'fake_key'; - protected function getCacheDir() + protected function getCacheDir(): ?string { if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) { return __DIR__.'/.cached_responses'; @@ -38,13 +38,13 @@ protected function getCacheDir() return null; } - public function testGetName() + public function testGetName(): void { $provider = new GoogleMaps($this->getMockedHttpClient(), null, 'mock-api-key'); $this->assertEquals('google_maps', $provider->getName()); } - public function testGeocodeWithLocalhostIPv4() + public function testGeocodeWithLocalhostIPv4(): void { $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('The GoogleMaps provider does not support IP addresses, only street addresses.'); @@ -53,7 +53,7 @@ public function testGeocodeWithLocalhostIPv4() $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); } - public function testGeocodeWithLocalhostIPv6() + public function testGeocodeWithLocalhostIPv6(): void { $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('The GoogleMaps provider does not support IP addresses, only street addresses.'); @@ -62,7 +62,7 @@ public function testGeocodeWithLocalhostIPv6() $provider->geocodeQuery(GeocodeQuery::create('::1')); } - public function testGeocodeWithRealIp() + public function testGeocodeWithRealIp(): void { $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('The GoogleMaps provider does not support IP addresses, only street addresses.'); @@ -71,7 +71,7 @@ public function testGeocodeWithRealIp() $provider->geocodeQuery(GeocodeQuery::create('74.200.247.59')); } - public function testGeocodeWithQuotaExceeded() + public function testGeocodeWithQuotaExceeded(): void { $this->expectException(\Geocoder\Exception\QuotaExceeded::class); $this->expectExceptionMessage('Daily quota exceeded https://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France'); @@ -80,7 +80,7 @@ public function testGeocodeWithQuotaExceeded() $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')); } - public function testGeocodeWithRealAddress() + public function testGeocodeWithRealAddress(): void { if (!isset($_SERVER['GOOGLE_GEOCODING_KEY'])) { $this->markTestSkipped('You need to configure the GOOGLE_GEOCODING_KEY value in phpunit.xml'); @@ -119,7 +119,7 @@ public function testGeocodeWithRealAddress() $this->assertNull($result->getPostalCodeSuffix()); } - public function testGeocodeBoundsWithRealAddressForNonRooftopLocation() + public function testGeocodeBoundsWithRealAddressForNonRooftopLocation(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('Paris, France')); @@ -139,7 +139,7 @@ public function testGeocodeBoundsWithRealAddressForNonRooftopLocation() $this->assertEquals(false, $result->isPartialMatch()); } - public function testReverse() + public function testReverse(): void { $this->expectException(\Geocoder\Exception\InvalidServerResponse::class); @@ -147,7 +147,7 @@ public function testReverse() $provider->reverseQuery(ReverseQuery::fromCoordinates(1, 2)); } - public function testReverseWithRealCoordinates() + public function testReverseWithRealCoordinates(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8631507, 2.388911)); @@ -171,7 +171,7 @@ public function testReverseWithRealCoordinates() $this->assertEquals(false, $result->isPartialMatch()); } - public function testReverseWithRealCoordinatesAndLocale() + public function testReverseWithRealCoordinatesAndLocale(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8631507, 2.388911)->withLocale('fr-FR')); @@ -195,7 +195,7 @@ public function testReverseWithRealCoordinatesAndLocale() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeWithCityDistrict() + public function testGeocodeWithCityDistrict(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany')); @@ -210,7 +210,7 @@ public function testGeocodeWithCityDistrict() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeWithInvalidApiKey() + public function testGeocodeWithInvalidApiKey(): void { $this->expectException(\Geocoder\Exception\InvalidCredentials::class); $this->expectExceptionMessage('API key is invalid https://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France'); @@ -219,7 +219,7 @@ public function testGeocodeWithInvalidApiKey() $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')); } - public function testGeocodeWithRealValidApiKey() + public function testGeocodeWithRealValidApiKey(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('Columbia University')); @@ -237,7 +237,7 @@ public function testGeocodeWithRealValidApiKey() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeWithComponentFiltering() + public function testGeocodeWithComponentFiltering(): void { $provider = $this->getGoogleMapsProvider(); $query = GeocodeQuery::create('Sankt Petri')->withData('components', [ @@ -259,7 +259,7 @@ public function testGeocodeWithComponentFiltering() $this->assertEquals(false, $result->isPartialMatch()); } - public function testCorrectlySerializesComponents() + public function testCorrectlySerializesComponents(): void { $uri = ''; @@ -292,7 +292,7 @@ function (RequestInterface $request) use (&$uri) { ); } - public function testCorrectlySetsComponents() + public function testCorrectlySetsComponents(): void { $uri = ''; @@ -322,7 +322,7 @@ function (RequestInterface $request) use (&$uri) { ); } - public function testGeocodeWithRealInvalidApiKey() + public function testGeocodeWithRealInvalidApiKey(): void { $this->expectException(\Geocoder\Exception\InvalidCredentials::class); $this->expectExceptionMessage('API key is invalid https://maps.googleapis.com/maps/api/geocode/json?address=Columbia&key=fake_key'); @@ -331,7 +331,7 @@ public function testGeocodeWithRealInvalidApiKey() $provider->geocodeQuery(GeocodeQuery::create('Columbia')); } - public function testGeocodePostalTown() + public function testGeocodePostalTown(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('CF37, United Kingdom')); @@ -346,7 +346,7 @@ public function testGeocodePostalTown() $this->assertEquals(false, $result->isPartialMatch()); } - public function testBusinessQueryWithoutPrivateKey() + public function testBusinessQueryWithoutPrivateKey(): void { $uri = ''; @@ -366,7 +366,7 @@ function (RequestInterface $request) use (&$uri) { $this->assertEquals('https://maps.googleapis.com/maps/api/geocode/json?address=blah&client=foo', $uri); } - public function testBusinessQueryWithPrivateKey() + public function testBusinessQueryWithPrivateKey(): void { $uri = ''; @@ -390,7 +390,7 @@ function (RequestInterface $request) use (&$uri) { ); } - public function testBusinessQueryWithPrivateKeyAndChannel() + public function testBusinessQueryWithPrivateKeyAndChannel(): void { $uri = ''; @@ -417,7 +417,7 @@ function (RequestInterface $request) use (&$uri) { ); } - public function testGeocodeWithInvalidClientIdAndKey() + public function testGeocodeWithInvalidClientIdAndKey(): void { $this->expectException(\Geocoder\Exception\InvalidCredentials::class); @@ -425,7 +425,7 @@ public function testGeocodeWithInvalidClientIdAndKey() $provider->geocodeQuery(GeocodeQuery::create('Columbia University')); } - public function testGeocodeWithInvalidClientIdAndKeyNoSsl() + public function testGeocodeWithInvalidClientIdAndKeyNoSsl(): void { $this->expectException(\Geocoder\Exception\InvalidCredentials::class); @@ -433,7 +433,7 @@ public function testGeocodeWithInvalidClientIdAndKeyNoSsl() $provider->geocodeQuery(GeocodeQuery::create('Columbia University')); } - public function testGeocodeWithSupremise() + public function testGeocodeWithSupremise(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('2123 W Mineral Ave Apt 61,Littleton,CO8 0120')); @@ -448,7 +448,7 @@ public function testGeocodeWithSupremise() $this->assertEquals(true, $result->isPartialMatch()); // 2123 W Mineral Ave #61, Littleton, CO 80120, USA } - public function testGeocodeWithNaturalFeatureComponent() + public function testGeocodeWithNaturalFeatureComponent(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('Durmitor Nacionalni Park')); @@ -467,7 +467,7 @@ public function testGeocodeWithNaturalFeatureComponent() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeWithAirportComponent() + public function testGeocodeWithAirportComponent(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('Brisbane Airport')); @@ -484,7 +484,7 @@ public function testGeocodeWithAirportComponent() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeWithPremiseComponent() + public function testGeocodeWithPremiseComponent(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('1125 17th St, Denver, CO 80202')); @@ -502,7 +502,7 @@ public function testGeocodeWithPremiseComponent() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeWithColloquialAreaComponent() + public function testGeocodeWithColloquialAreaComponent(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('darwin')); @@ -517,7 +517,7 @@ public function testGeocodeWithColloquialAreaComponent() $this->assertEquals(false, $result->isPartialMatch()); } - public function testReverseWithSubLocalityLevels() + public function testReverseWithSubLocalityLevels(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(36.2745084, 136.9003169)); @@ -533,7 +533,7 @@ public function testReverseWithSubLocalityLevels() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeWithPostalCodeSuffixComponent() + public function testGeocodeWithPostalCodeSuffixComponent(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('900 S Oak Park Ave, Oak Park, IL 60304')); @@ -549,7 +549,7 @@ public function testGeocodeWithPostalCodeSuffixComponent() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeBoundsWithRealAddressWithViewportOnly() + public function testGeocodeBoundsWithRealAddressWithViewportOnly(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('Sibbe, Netherlands')); @@ -568,7 +568,7 @@ public function testGeocodeBoundsWithRealAddressWithViewportOnly() $this->assertEquals(false, $result->isPartialMatch()); } - public function testGeocodeDuplicateSubLocalityLevel() + public function testGeocodeDuplicateSubLocalityLevel(): void { $provider = $this->getGoogleMapsProvider(); $results = $provider->geocodeQuery(GeocodeQuery::create('Rue de Pont-A-Migneloux, 6210 Wayaux, Belgique'));