From ade0019bc60e6851e964b05eff3edf22aeca1e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 15:52:50 +0200 Subject: [PATCH 01/26] Add PHPStan --- composer.json | 3 ++- phpstan.neon | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 4b9d413c6..a39fc75c2 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "php-http/message": "^1.0", "php-http/mock-client": "^1.0", "phpunit/phpunit": "^9.5", - "symfony/stopwatch": "~2.5 || ~5.0" + "symfony/stopwatch": "~2.5 || ~5.0", + "phpstan/phpstan": "^1.10" }, "suggest": { "ext-geoip": "Enabling the geoip extension allows you to use the MaxMindProvider.", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..2f4dc7f1b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 0 + paths: + - src From 1fc4c1ae2769ce6f017b1d719ccdba3baa40ad02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 15:52:57 +0200 Subject: [PATCH 02/26] Update php.yml --- .github/workflows/php.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 95cb522e7..22ed05fbf 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -8,29 +8,22 @@ on: jobs: test: - runs-on: ubuntu-latest - strategy: fail-fast: false matrix: php-version: ['7.4', '8.0', '8.1', '8.2'] deps: ['low', 'high'] - name: PHP ${{ matrix.php-version }} (${{ matrix.deps }}) - steps: - uses: actions/checkout@v3 - - 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 - - name: Install dependencies if: ${{ matrix.deps == null }} run: composer update --no-progress --prefer-dist @@ -40,6 +33,20 @@ jobs: - name: Install dependencies (high) if: ${{ matrix.deps == 'high' }} run: composer update --no-progress - - name: Run test suite run: composer run-script test + + phpstan: + runs-on: ubuntu-latest + name: PHPStan + steps: + - uses: actions/checkout@v3 + - name: Use PHP 8.2 + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: curl + - name: Install dependencies + run: composer install --no-progress + - name: Run PHPStan + run: composer run-script phpstan \ No newline at end of file From 142df1f749dec913609277a3ba5adf9acde4bb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 15:58:19 +0200 Subject: [PATCH 03/26] Update composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a39fc75c2..781e85f05 100644 --- a/composer.json +++ b/composer.json @@ -72,6 +72,7 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "test": "vendor/bin/phpunit" + "test": "vendor/bin/phpunit", + "phpstan": "vendor/bin/phpstan analyse" } } From b0c182349d78c23e61dd2dc908c06404e3fd36f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 16:27:59 +0200 Subject: [PATCH 04/26] Fix PHPStan level 0 --- src/Common/Model/Address.php | 2 +- src/Provider/HostIp/AbstractHostIp.php | 4 +++- src/Provider/HostIp/HostIp.php | 8 ++++++++ src/Provider/HostIp/HostIpXml.php | 8 ++++++++ src/Provider/IP2LocationBinary/IP2LocationBinary.php | 4 ++-- src/Provider/IP2LocationBinary/Tests/IntegrationTest.php | 2 +- src/Provider/IpInfo/Tests/IntegrationTest.php | 1 + src/Provider/MaxMindBinary/MaxMindBinary.php | 8 ++++---- 8 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Common/Model/Address.php b/src/Common/Model/Address.php index a0ff0e33e..2adba83ea 100644 --- a/src/Common/Model/Address.php +++ b/src/Common/Model/Address.php @@ -247,7 +247,7 @@ public static function createFromArray(array $data) $adminLevels[] = new AdminLevel($adminLevel['level'], $name, $adminLevel['code'] ?? null); } - return new static( + return new self( $data['providedBy'], new AdminLevelCollection($adminLevels), self::createCoordinates( diff --git a/src/Provider/HostIp/AbstractHostIp.php b/src/Provider/HostIp/AbstractHostIp.php index c4cf4890b..7d6aa592e 100644 --- a/src/Provider/HostIp/AbstractHostIp.php +++ b/src/Provider/HostIp/AbstractHostIp.php @@ -29,6 +29,8 @@ abstract class AbstractHostIp extends AbstractHttpProvider implements Provider { abstract protected function executeQuery(string $url): AddressCollection; + abstract protected function getEndpointURL(): string; + /** * {@inheritdoc} */ @@ -48,7 +50,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection return new AddressCollection([$this->getLocationForLocalhost()]); } - $url = sprintf(static::ENDPOINT_URL, $address); + $url = sprintf($this->getEndpointURL(), $address); return $this->executeQuery($url); } diff --git a/src/Provider/HostIp/HostIp.php b/src/Provider/HostIp/HostIp.php index 1c0fc85ed..e893cb50f 100644 --- a/src/Provider/HostIp/HostIp.php +++ b/src/Provider/HostIp/HostIp.php @@ -34,6 +34,14 @@ public function getName(): string return 'host_ip'; } + /** + * @return string + */ + public function getEndpointURL(): string + { + return self::ENDPOINT_URL; + } + /** * @param string $url * diff --git a/src/Provider/HostIp/HostIpXml.php b/src/Provider/HostIp/HostIpXml.php index edf64e5fc..224448c0b 100644 --- a/src/Provider/HostIp/HostIpXml.php +++ b/src/Provider/HostIp/HostIpXml.php @@ -34,6 +34,14 @@ public function getName(): string return 'host_ip_xml'; } + /** + * @return string + */ + public function getEndpointURL(): string + { + return self::ENDPOINT_URL; + } + /** * @param string $url * diff --git a/src/Provider/IP2LocationBinary/IP2LocationBinary.php b/src/Provider/IP2LocationBinary/IP2LocationBinary.php index 64f6ef2ed..695795b3b 100644 --- a/src/Provider/IP2LocationBinary/IP2LocationBinary.php +++ b/src/Provider/IP2LocationBinary/IP2LocationBinary.php @@ -70,8 +70,8 @@ public function geocodeQuery(GeocodeQuery $query): Collection throw new UnsupportedOperation('The IP2LocationBinary provider does not support street addresses.'); } - $db = new \IP2Location\Database($this->binFile, $this->openFlag); - $records = $db->lookup($address, \IP2Location\Database::ALL); + $db = new \IP2Location\Database($this->binFile, $this->openFlag); // @phpstan-ignore-line + $records = $db->lookup($address, \IP2Location\Database::ALL); // @phpstan-ignore-line if (false === $records) { return new AddressCollection([]); diff --git a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php index ec64b0a4a..835588d56 100644 --- a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php +++ b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php @@ -44,7 +44,7 @@ public static function setUpBeforeClass(): void protected function createProvider(ClientInterface $httpClient) { // Download this BIN database from https://lite.ip2location.com/database/ip-country-region-city-latitude-longitude-zipcode - return new IP2LocationBinary(__DIR__.'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN', \IP2Location\Database::FILE_IO); + return new IP2LocationBinary(__DIR__.'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN', \IP2Location\Database::FILE_IO); // @phpstan-ignore-line } protected function getCacheDir() diff --git a/src/Provider/IpInfo/Tests/IntegrationTest.php b/src/Provider/IpInfo/Tests/IntegrationTest.php index fc7a1d064..58becfae8 100644 --- a/src/Provider/IpInfo/Tests/IntegrationTest.php +++ b/src/Provider/IpInfo/Tests/IntegrationTest.php @@ -39,5 +39,6 @@ protected function getCacheDir() protected function getApiKey() { + return ''; } } diff --git a/src/Provider/MaxMindBinary/MaxMindBinary.php b/src/Provider/MaxMindBinary/MaxMindBinary.php index 5cc9d41d2..5a628de24 100644 --- a/src/Provider/MaxMindBinary/MaxMindBinary.php +++ b/src/Provider/MaxMindBinary/MaxMindBinary.php @@ -79,12 +79,12 @@ public function geocodeQuery(GeocodeQuery $query): Collection throw new UnsupportedOperation('The MaxMindBinary provider does not support IPv6 addresses.'); } - $geoIp = geoip_open($this->datFile, $this->openFlag); - $geoIpRecord = GeoIP_record_by_addr($geoIp, $address); + $geoIp = geoip_open($this->datFile, $this->openFlag); // @phpstan-ignore-line + $geoIpRecord = GeoIP_record_by_addr($geoIp, $address); // @phpstan-ignore-line - geoip_close($geoIp); + geoip_close($geoIp); // @phpstan-ignore-line - if (false === $geoIpRecord instanceof \GeoIpRecord) { + if (false === $geoIpRecord instanceof \GeoIpRecord) { // @phpstan-ignore-line return new AddressCollection([]); } From 7c63968be4ae2c709dffc971320d1271596c4aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 16:36:36 +0200 Subject: [PATCH 05/26] Fix PHPStan level 1 --- src/Provider/BingMaps/Tests/BingMapsTest.php | 2 +- .../FreeGeoIp/Tests/FreeGeoIpTest.php | 12 +++++----- src/Provider/GeoIPs/Tests/GeoIPsTest.php | 8 +++---- .../GeoPlugin/Tests/GeoPluginTest.php | 4 ++-- src/Provider/HostIp/Tests/HostIpXmlTest.php | 4 ++-- .../Tests/IP2LocationBinaryTest.php | 12 +++++----- src/Provider/IpInfo/Tests/IpInfoTest.php | 8 +++---- src/Provider/IpInfoDb/Tests/IpInfoDbTest.php | 4 ++-- src/Provider/Ipstack/Tests/IpstackTest.php | 8 +++---- src/Provider/MapTiler/Tests/MapTilerTest.php | 12 +++++----- src/Provider/Mapbox/Tests/MapboxTest.php | 12 +++++----- src/Provider/Mapzen/Tests/MapzenTest.php | 2 +- src/Provider/MaxMind/Tests/MaxMindTest.php | 24 +++++++++---------- src/Provider/MaxMindBinary/MaxMindBinary.php | 2 +- .../MaxMindBinary/Tests/MaxMindBinaryTest.php | 8 +++---- src/Provider/Photon/Photon.php | 2 +- src/Provider/Photon/Tests/IntegrationTest.php | 2 +- src/Provider/Photon/Tests/PhotonTest.php | 8 +++---- 18 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/Provider/BingMaps/Tests/BingMapsTest.php b/src/Provider/BingMaps/Tests/BingMapsTest.php index 0123dc84d..f9c46f3cf 100644 --- a/src/Provider/BingMaps/Tests/BingMapsTest.php +++ b/src/Provider/BingMaps/Tests/BingMapsTest.php @@ -67,7 +67,7 @@ public function testGeocodeReturnsMultipleResults() {"authenticationResultCode":"ValidCredentials","brandLogoUri":"https:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2013 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":3,"resources":[{"__type":"Location:https:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","bbox":[48.859354042429317,2.3809438666389395,48.86707947757067,2.3966003933610596],"name":"10 Avenue Gambetta, 75020 Paris","point":{"type":"Point","coordinates":[48.863216759999993,2.3887721299999995]},"address":{"addressLine":"10 Avenue Gambetta","adminDistrict":"IdF","adminDistrict2":"Paris","countryRegion":"France","countryRegionIso2":"FR","formattedAddress":"10 Avenue Gambetta, 75020 Paris","locality":"Paris","postalCode":"75020"},"confidence":"Medium","entityType":"Address","geocodePoints":[{"type":"Point","coordinates":[48.863216759999993,2.3887721299999995],"calculationMethod":"Interpolation","usageTypes":["Display","Route"]}],"matchCodes":["Ambiguous","Good"]},{"__type":"Location:https:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","bbox":[48.809565092429317,2.3172171827738461,48.81729052757067,2.3328581572261538],"name":"10 Avenue Léon Gambetta, 92120 Montrouge","point":{"type":"Point","coordinates":[48.813427809999993,2.32503767]},"address":{"addressLine":"10 Avenue Léon Gambetta","adminDistrict":"IdF","adminDistrict2":"Hauts-de-Seine","countryRegion":"France","countryRegionIso2":"FR","formattedAddress":"10 Avenue Léon Gambetta, 92120 Montrouge","locality":"Montrouge","postalCode":"92120"},"confidence":"Medium","entityType":"Address","geocodePoints":[{"type":"Point","coordinates":[48.813427809999993,2.32503767],"calculationMethod":"Interpolation","usageTypes":["Display","Route"]}],"matchCodes":["Ambiguous","Good"]},{"__type":"Location:https:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","bbox":[48.806278752429328,2.4278605052896745,48.814004187570681,2.4435004547103261],"name":"10 Avenue Gambetta, 94700 Maisons-Alfort","point":{"type":"Point","coordinates":[48.810141470000005,2.4356804800000003]},"address":{"addressLine":"10 Avenue Gambetta","adminDistrict":"IdF","adminDistrict2":"Val-De-Marne","countryRegion":"France","countryRegionIso2":"FR","formattedAddress":"10 Avenue Gambetta, 94700 Maisons-Alfort","locality":"Maisons-Alfort","postalCode":"94700"},"confidence":"Medium","entityType":"Address","geocodePoints":[{"type":"Point","coordinates":[48.810141470000005,2.4356804800000003],"calculationMethod":"Interpolation","usageTypes":["Display","Route"]}],"matchCodes":["Ambiguous","Good"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"fd9b0b8fe1a34ad384923b5d0937bfb2|AMSM001404|02.00.139.700|AMSMSNVM002409, AMSMSNVM001862, AMSMSNVM001322, AMSMSNVM000044"} JSON; - $provider = new BingMaps($this->getMockedHttpClient($json), 'api_key', 'fr_FR'); + $provider = new BingMaps($this->getMockedHttpClient($json), 'api_key'); $results = $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); diff --git a/src/Provider/FreeGeoIp/Tests/FreeGeoIpTest.php b/src/Provider/FreeGeoIp/Tests/FreeGeoIpTest.php index f93fbda42..5119c15b6 100644 --- a/src/Provider/FreeGeoIp/Tests/FreeGeoIpTest.php +++ b/src/Provider/FreeGeoIp/Tests/FreeGeoIpTest.php @@ -81,8 +81,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.751, $result->getCoordinates()->getLatitude(), '', 0.01); - $this->assertEquals(-97.822, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertEqualsWithDelta(37.751, $result->getCoordinates()->getLatitude(), 0.01); + $this->assertEqualsWithDelta(-97.822, $result->getCoordinates()->getLongitude(), 0.01); $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); } @@ -99,8 +99,8 @@ public function testGeocodeWithRealIPv6() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.751, $result->getCoordinates()->getLatitude(), '', 0.01); - $this->assertEquals(-97.822, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertEqualsWithDelta(37.751, $result->getCoordinates()->getLatitude(), 0.01); + $this->assertEqualsWithDelta(-97.822, $result->getCoordinates()->getLongitude(), 0.01); $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); } @@ -117,8 +117,8 @@ public function testGeocodeWithUSIPv4() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.7263, $result->getCoordinates()->getLatitude(), '', 0.01); - $this->assertEquals(-73.9819, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertEqualsWithDelta(40.7263, $result->getCoordinates()->getLatitude(), 0.01); + $this->assertEqualsWithDelta(-73.9819, $result->getCoordinates()->getLongitude(), 0.01); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('NY', $result->getAdminLevels()->get(1)->getCode()); diff --git a/src/Provider/GeoIPs/Tests/GeoIPsTest.php b/src/Provider/GeoIPs/Tests/GeoIPsTest.php index d56d10720..2860c0156 100644 --- a/src/Provider/GeoIPs/Tests/GeoIPsTest.php +++ b/src/Provider/GeoIPs/Tests/GeoIPsTest.php @@ -160,8 +160,8 @@ public function testGeocodeWithRealIPv4GetsFakeContent() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.3402, $result->getCoordinates()->getLatitude(), '', 0.0001); - $this->assertEquals(-111.6073, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertEqualsWithDelta(40.3402, $result->getCoordinates()->getLatitude(), 0.0001); + $this->assertEqualsWithDelta(-111.6073, $result->getCoordinates()->getLongitude(), 0.0001); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); $this->assertEquals('PROVO', $result->getLocality()); @@ -314,8 +314,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.3402, $result->getCoordinates()->getLatitude(), '', 0.0001); - $this->assertEquals(-111.6073, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertEqualsWithDelta(40.3402, $result->getCoordinates()->getLatitude(), 0.0001); + $this->assertEqualsWithDelta(-111.6073, $result->getCoordinates()->getLongitude(), 0.0001); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); $this->assertEquals('PROVO', $result->getLocality()); diff --git a/src/Provider/GeoPlugin/Tests/GeoPluginTest.php b/src/Provider/GeoPlugin/Tests/GeoPluginTest.php index 6cd25a33e..8ca86ad38 100644 --- a/src/Provider/GeoPlugin/Tests/GeoPluginTest.php +++ b/src/Provider/GeoPlugin/Tests/GeoPluginTest.php @@ -75,8 +75,8 @@ public function testGeocodeWithRealIPv4() $result = $results->first(); - $this->assertEquals(40.711101999999997, $result->getCoordinates()->getLatitude(), '', 0.0001); - $this->assertEquals(-73.946899000000002, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertEqualsWithDelta(40.711101999999997, $result->getCoordinates()->getLatitude(), 0.0001); + $this->assertEqualsWithDelta(-73.946899000000002, $result->getCoordinates()->getLongitude(), 0.0001); $this->assertNull($result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName()); diff --git a/src/Provider/HostIp/Tests/HostIpXmlTest.php b/src/Provider/HostIp/Tests/HostIpXmlTest.php index 56da5e977..e3c119680 100644 --- a/src/Provider/HostIp/Tests/HostIpXmlTest.php +++ b/src/Provider/HostIp/Tests/HostIpXmlTest.php @@ -81,8 +81,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(56.8833, $result->getCoordinates()->getLatitude(), '', 0.0001); - $this->assertEquals(24.0833, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertEqualsWithDelta(56.8833, $result->getCoordinates()->getLatitude(), 0.0001); + $this->assertEqualsWithDelta(24.0833, $result->getCoordinates()->getLongitude(), 0.0001); $this->assertNull($result->getPostalCode()); $this->assertEquals('Riga', $result->getLocality()); $this->assertEmpty($result->getAdminLevels()); diff --git a/src/Provider/IP2LocationBinary/Tests/IP2LocationBinaryTest.php b/src/Provider/IP2LocationBinary/Tests/IP2LocationBinaryTest.php index 67b61ce56..cb8029d09 100644 --- a/src/Provider/IP2LocationBinary/Tests/IP2LocationBinaryTest.php +++ b/src/Provider/IP2LocationBinary/Tests/IP2LocationBinaryTest.php @@ -68,8 +68,8 @@ public function testLocationResultContainsExpectedFieldsForAnAmericanIp() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals('37.405990600586', $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals('-122.07851409912', $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(37.405990600586, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-122.07851409912, $result->getCoordinates()->getLongitude(), 0.001); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -96,8 +96,8 @@ public function testLocationResultContainsExpectedFieldsForAChinaIp() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals('39.907501220703', $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals('116.39723205566', $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(39.907501220703, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(116.39723205566, $result->getCoordinates()->getLongitude(), 0.001); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -124,8 +124,8 @@ public function testGeocodeWithRealIPv6() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals('37.386051', $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals('-122.083847', $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(37.386051, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-122.083847, $result->getCoordinates()->getLongitude(), 0.001); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); diff --git a/src/Provider/IpInfo/Tests/IpInfoTest.php b/src/Provider/IpInfo/Tests/IpInfoTest.php index e59d2cc0d..cda446700 100644 --- a/src/Provider/IpInfo/Tests/IpInfoTest.php +++ b/src/Provider/IpInfo/Tests/IpInfoTest.php @@ -96,8 +96,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(36.154, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(-95.9928, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(36.154, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-95.9928, $result->getCoordinates()->getLongitude(), 0.001); $this->assertEquals(74102, $result->getPostalCode()); $this->assertEquals('Tulsa', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); @@ -118,8 +118,8 @@ public function testGeocodeWithRealIPv6() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(39.934, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(-74.891, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(39.934, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-74.891, $result->getCoordinates()->getLongitude(), 0.001); $this->assertEquals('08054', $result->getPostalCode()); $this->assertEquals('Mount Laurel', $result->getLocality()); $this->assertNull($result->getCountry()->getName()); diff --git a/src/Provider/IpInfoDb/Tests/IpInfoDbTest.php b/src/Provider/IpInfoDb/Tests/IpInfoDbTest.php index d32d7e7ec..b62a2bb91 100644 --- a/src/Provider/IpInfoDb/Tests/IpInfoDbTest.php +++ b/src/Provider/IpInfoDb/Tests/IpInfoDbTest.php @@ -118,8 +118,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(36.154, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(-95.9928, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(36.154, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-95.9928, $result->getCoordinates()->getLongitude(), 0.001); $this->assertEquals(74101, $result->getPostalCode()); $this->assertEquals('Tulsa', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); diff --git a/src/Provider/Ipstack/Tests/IpstackTest.php b/src/Provider/Ipstack/Tests/IpstackTest.php index 6ebeecd18..1e86d0153 100644 --- a/src/Provider/Ipstack/Tests/IpstackTest.php +++ b/src/Provider/Ipstack/Tests/IpstackTest.php @@ -91,8 +91,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.751, $result->getCoordinates()->getLatitude(), '', 0.01); - $this->assertEquals(-97.822, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertEqualsWithDelta(37.751, $result->getCoordinates()->getLatitude(), 0.01); + $this->assertEqualsWithDelta(-97.822, $result->getCoordinates()->getLongitude(), 0.01); $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); } @@ -108,8 +108,8 @@ public function testGeocodeWithRealIPv4InFrench() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.751, $result->getCoordinates()->getLatitude(), '', 0.01); - $this->assertEquals(-97.822, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertEqualsWithDelta(37.751, $result->getCoordinates()->getLatitude(), 0.01); + $this->assertEqualsWithDelta(-97.822, $result->getCoordinates()->getLongitude(), 0.01); $this->assertEquals('États-Unis', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); } diff --git a/src/Provider/MapTiler/Tests/MapTilerTest.php b/src/Provider/MapTiler/Tests/MapTilerTest.php index 5027c4efc..fa5976058 100644 --- a/src/Provider/MapTiler/Tests/MapTilerTest.php +++ b/src/Provider/MapTiler/Tests/MapTilerTest.php @@ -85,8 +85,8 @@ public function testGeocodeQueryStreet() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.8658863, $result->getCoordinates()->getLatitude(), '', 0.00001); - $this->assertEquals(2.3993232, $result->getCoordinates()->getLongitude(), '', 0.00001); + $this->assertEqualsWithDelta(48.8658863, $result->getCoordinates()->getLatitude(), 0.00001); + $this->assertEqualsWithDelta(2.3993232, $result->getCoordinates()->getLongitude(), 0.00001); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('France', $result->getCountry()); @@ -109,8 +109,8 @@ public function testGeocodeQueryCity() /** @var \Geocoder\Model\Address $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.85881, $result->getCoordinates()->getLatitude(), '', 0.00001); - $this->assertEquals(2.320031, $result->getCoordinates()->getLongitude(), '', 0.00001); + $this->assertEqualsWithDelta(48.85881, $result->getCoordinates()->getLatitude(), 0.00001); + $this->assertEqualsWithDelta(2.320031, $result->getCoordinates()->getLongitude(), 0.00001); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('France', $result->getCountry()); } @@ -132,8 +132,8 @@ public function testReverseQuery() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(47.3774434, $result->getCoordinates()->getLatitude(), '', 0.00001); - $this->assertEquals(8.528509, $result->getCoordinates()->getLongitude(), '', 0.00001); + $this->assertEqualsWithDelta(47.3774434, $result->getCoordinates()->getLatitude(), 0.00001); + $this->assertEqualsWithDelta(8.528509, $result->getCoordinates()->getLongitude(), 0.00001); $this->assertEquals('Zurich', $result->getLocality()); $this->assertEquals('Switzerland', $result->getCountry()); } diff --git a/src/Provider/Mapbox/Tests/MapboxTest.php b/src/Provider/Mapbox/Tests/MapboxTest.php index 9c1097309..411e1c259 100644 --- a/src/Provider/Mapbox/Tests/MapboxTest.php +++ b/src/Provider/Mapbox/Tests/MapboxTest.php @@ -102,8 +102,8 @@ public function testGeocodePlaceWithNoCountryShortCode() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf(Address::class, $result); - $this->assertEquals(43.73125, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(7.41974, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(43.73125, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(7.41974, $result->getCoordinates()->getLongitude(), 0.001); $this->assertEquals('Principato di Monaco', $result->getStreetName()); $this->assertEquals('Principato di Monaco', $result->getCountry()->getName()); $this->assertEquals('place.4899176537126140', $result->getId()); @@ -131,8 +131,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf(Address::class, $result); - $this->assertEquals(37.77572, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(-122.41362, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(37.77572, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-122.41362, $result->getCoordinates()->getLongitude(), 0.001); $this->assertNull($result->getBounds()); $this->assertEquals(149, $result->getStreetNumber()); $this->assertEquals('9th Street', $result->getStreetName()); @@ -215,8 +215,8 @@ public function testGeocodeWithRealValidApiKey() $this->assertEquals('address.2431617896783536', $result->getId()); $this->assertNotNull($result->getCoordinates()->getLatitude()); $this->assertNotNull($result->getCoordinates()->getLongitude()); - $this->assertEquals(40.786596, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(-73.851157, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(40.786596, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-73.851157, $result->getCoordinates()->getLongitude(), 0.001); $this->assertEquals('New York', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName()); diff --git a/src/Provider/Mapzen/Tests/MapzenTest.php b/src/Provider/Mapzen/Tests/MapzenTest.php index 88984a344..41e6f777a 100644 --- a/src/Provider/Mapzen/Tests/MapzenTest.php +++ b/src/Provider/Mapzen/Tests/MapzenTest.php @@ -45,7 +45,7 @@ public function testGeocode() public function testSslSchema() { - $provider = new Mapzen($this->getMockedHttpClient('{}'), 'api_key', true); + $provider = new Mapzen($this->getMockedHttpClient('{}'), 'api_key'); $result = $provider->geocodeQuery(GeocodeQuery::create('foobar')); $this->assertInstanceOf(Collection::class, $result); diff --git a/src/Provider/MaxMind/Tests/MaxMindTest.php b/src/Provider/MaxMind/Tests/MaxMindTest.php index 8824dcbe3..cad15b2f1 100644 --- a/src/Provider/MaxMind/Tests/MaxMindTest.php +++ b/src/Provider/MaxMind/Tests/MaxMindTest.php @@ -125,8 +125,8 @@ public function testGeocodeWithRealIPv4GetsFakeContent() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.034698486328, $result->getCoordinates()->getLatitude(), '', 0.0001); - $this->assertEquals(-96.813400268555, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertEqualsWithDelta(33.034698486328, $result->getCoordinates()->getLatitude(), 0.0001); + $this->assertEqualsWithDelta(-96.813400268555, $result->getCoordinates()->getLongitude(), 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(75093, $result->getPostalCode()); @@ -157,8 +157,8 @@ public function testGeocodeWithRealIPv4GetsFakeContent() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.748402, $result->getCoordinates()->getLatitude(), '', 0.0001); - $this->assertEquals(-122.415604, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertEqualsWithDelta(37.748402, $result->getCoordinates()->getLatitude(), 0.0001); + $this->assertEqualsWithDelta(-122.415604, $result->getCoordinates()->getLongitude(), 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(94110, $result->getPostalCode()); @@ -269,8 +269,8 @@ public function testGeocodeServiceWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.034698, $result->getCoordinates()->getLatitude(), '', 0.1); - $this->assertEquals(-96.813400, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertEqualsWithDelta(33.034698, $result->getCoordinates()->getLatitude(), 0.1); + $this->assertEqualsWithDelta(-96.813400, $result->getCoordinates()->getLongitude(), 0.1); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -304,8 +304,8 @@ public function testGeocodeOmniServiceWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.0347, $result->getCoordinates()->getLatitude(), '', 0.1); - $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertEqualsWithDelta(33.0347, $result->getCoordinates()->getLatitude(), 0.1); + $this->assertEqualsWithDelta(-96.8134, $result->getCoordinates()->getLongitude(), 0.1); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -339,8 +339,8 @@ public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(-27.5833, $result->getCoordinates()->getLatitude(), '', 0.1); - $this->assertEquals(-48.5666, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertEqualsWithDelta(-27.5833, $result->getCoordinates()->getLatitude(), 0.1); + $this->assertEqualsWithDelta(-48.5666, $result->getCoordinates()->getLongitude(), 0.1); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -374,8 +374,8 @@ public function testGeocodeOmniServiceWithRealIPv6WithSsl() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.2181, $result->getCoordinates()->getLatitude(), '', 0.1); - $this->assertEquals(-111.6133, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertEqualsWithDelta(40.2181, $result->getCoordinates()->getLatitude(), 0.1); + $this->assertEqualsWithDelta(-111.6133, $result->getCoordinates()->getLongitude(), 0.1); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); diff --git a/src/Provider/MaxMindBinary/MaxMindBinary.php b/src/Provider/MaxMindBinary/MaxMindBinary.php index 5a628de24..9a86c5c96 100644 --- a/src/Provider/MaxMindBinary/MaxMindBinary.php +++ b/src/Provider/MaxMindBinary/MaxMindBinary.php @@ -61,7 +61,7 @@ public function __construct(string $datFile, int $openFlag = null) } $this->datFile = $datFile; - $this->openFlag = null === $openFlag ? GEOIP_STANDARD : $openFlag; + $this->openFlag = null === $openFlag ? GEOIP_STANDARD : $openFlag; // @phpstan-ignore-line } /** diff --git a/src/Provider/MaxMindBinary/Tests/MaxMindBinaryTest.php b/src/Provider/MaxMindBinary/Tests/MaxMindBinaryTest.php index 02506dae7..57c360bf9 100644 --- a/src/Provider/MaxMindBinary/Tests/MaxMindBinaryTest.php +++ b/src/Provider/MaxMindBinary/Tests/MaxMindBinaryTest.php @@ -72,8 +72,8 @@ public function testLocationResultContainsExpectedFieldsForAnAmericanIp() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals('43.089200000000005', $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals('-76.025000000000006', $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(43.089200000000005, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(-76.025000000000006, $result->getCoordinates()->getLongitude(), 0.001); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -100,8 +100,8 @@ public function testLocationResultContainsExpectedFieldsForASpanishIp() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals('41.543299999999988', $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals('2.1093999999999937', $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertEqualsWithDelta(41.543299999999988, $result->getCoordinates()->getLatitude(), 0.001); + $this->assertEqualsWithDelta(2.1093999999999937, $result->getCoordinates()->getLongitude(), 0.001); $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index f805bbbb7..5cdd4d2ad 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -77,7 +77,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection 'lang' => $query->getLocale(), ]); - $json = $this->executeQuery($url, $query->getLocale()); + $json = $this->executeQuery($url); if (!isset($json->features) || empty($json->features)) { return new AddressCollection([]); diff --git a/src/Provider/Photon/Tests/IntegrationTest.php b/src/Provider/Photon/Tests/IntegrationTest.php index f6aa43fdb..29ff83545 100644 --- a/src/Provider/Photon/Tests/IntegrationTest.php +++ b/src/Provider/Photon/Tests/IntegrationTest.php @@ -34,7 +34,7 @@ class IntegrationTest extends ProviderIntegrationTest protected function createProvider(ClientInterface $httpClient) { - return Photon::withKomootServer($httpClient, 'Geocoder PHP/Photon Provider/Integration Test'); + return Photon::withKomootServer($httpClient); } protected function getCacheDir() diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index b579a8c40..03f0812d5 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -62,8 +62,8 @@ public function testGeocodeQuery() /** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.8631927, $result->getCoordinates()->getLatitude(), '', 0.00001); - $this->assertEquals(2.3890894, $result->getCoordinates()->getLongitude(), '', 0.00001); + $this->assertEqualsWithDelta(48.8631927, $result->getCoordinates()->getLatitude(), 0.00001); + $this->assertEqualsWithDelta(2.3890894, $result->getCoordinates()->getLongitude(), 0.00001); $this->assertEquals('10', $result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals('75020', $result->getPostalCode()); @@ -105,8 +105,8 @@ public function testReverseQuery() /** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.9982968, $result->getCoordinates()->getLatitude(), '', 0.00001); - $this->assertEquals(9.998645, $result->getCoordinates()->getLongitude(), '', 0.00001); + $this->assertEqualsWithDelta(51.9982968, $result->getCoordinates()->getLatitude(), 0.00001); + $this->assertEqualsWithDelta(9.998645, $result->getCoordinates()->getLongitude(), 0.00001); $this->assertEquals('31195', $result->getPostalCode()); $this->assertEquals('Lamspringe', $result->getLocality()); $this->assertEquals('Deutschland', $result->getCountry()->getName()); From ac4b89e1b76cd724f7331a1dc135fc89769ab07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 16:36:45 +0200 Subject: [PATCH 06/26] Update phpstan.neon --- phpstan.neon | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 2f4dc7f1b..5cbc6de53 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,6 @@ parameters: - level: 0 + level: 1 paths: - src + excludePaths: + - **/vendor/** From 47611f0478bf4c90ec5ff2521df2c8ec31ed7d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:13:23 +0200 Subject: [PATCH 07/26] Fix PHPStan level 2 --- composer.json | 4 +++- phpstan.neon | 10 +++++----- src/Common/Tests/TimedGeocoderTest.php | 3 ++- src/Plugin/PluginProvider.php | 5 +---- .../AlgoliaPlaces/Tests/AlgoliaPlacesTest.php | 2 +- src/Provider/Cache/Tests/ProviderCacheTest.php | 15 +++------------ src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php | 5 +++-- src/Provider/GeoIP2/Tests/GeoIP2Test.php | 3 ++- src/Provider/Geonames/Geonames.php | 2 +- src/Provider/Geonames/Model/CountryInfo.php | 4 ++-- src/Provider/Geonames/Model/GeonamesAddress.php | 2 +- .../GoogleMapsPlaces/Model/GooglePlace.php | 8 ++++---- src/Provider/GraphHopper/GraphHopper.php | 2 -- src/Provider/Here/Model/HereAddress.php | 6 +++--- src/Provider/Here/Tests/HereTest.php | 7 +++++-- src/Provider/HostIp/HostIp.php | 2 -- src/Provider/HostIp/HostIpXml.php | 2 -- src/Provider/IP2Location/IP2Location.php | 2 -- src/Provider/IpInfo/IpInfo.php | 2 -- src/Provider/IpInfoDb/IpInfoDb.php | 2 -- src/Provider/Ipstack/Tests/IpstackTest.php | 1 + src/Provider/MapQuest/MapQuest.php | 3 ++- src/Provider/MapTiler/MapTiler.php | 2 +- src/Provider/Mapbox/Tests/MapboxTest.php | 17 +++++++++-------- src/Provider/Mapzen/Mapzen.php | 2 -- src/Provider/MaxMind/MaxMind.php | 2 -- src/Provider/MaxMindBinary/MaxMindBinary.php | 16 ++++++++-------- src/Provider/Nominatim/Tests/NominatimTest.php | 5 ++++- src/Provider/Pelias/Pelias.php | 2 -- src/Provider/Photon/Photon.php | 4 +++- src/Provider/Yandex/Model/YandexAddress.php | 2 +- src/Provider/Yandex/Tests/YandexTest.php | 2 +- 32 files changed, 66 insertions(+), 80 deletions(-) diff --git a/composer.json b/composer.json index 781e85f05..11d15bc07 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,9 @@ "php-http/mock-client": "^1.0", "phpunit/phpunit": "^9.5", "symfony/stopwatch": "~2.5 || ~5.0", - "phpstan/phpstan": "^1.10" + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^1.3", + "phpstan/extension-installer": "^1.3" }, "suggest": { "ext-geoip": "Enabling the geoip extension allows you to use the MaxMindProvider.", diff --git a/phpstan.neon b/phpstan.neon index 5cbc6de53..0d171ca46 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ parameters: - level: 1 - paths: - - src - excludePaths: - - **/vendor/** + level: 2 + paths: + - src + excludePaths: + - **/vendor/** diff --git a/src/Common/Tests/TimedGeocoderTest.php b/src/Common/Tests/TimedGeocoderTest.php index c46a82fba..e317cb206 100644 --- a/src/Common/Tests/TimedGeocoderTest.php +++ b/src/Common/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; diff --git a/src/Plugin/PluginProvider.php b/src/Plugin/PluginProvider.php index c138cbd95..7dc3bbd7f 100644 --- a/src/Plugin/PluginProvider.php +++ b/src/Plugin/PluginProvider.php @@ -49,10 +49,7 @@ class PluginProvider implements Provider /** * @param Provider $provider * @param Plugin[] $plugins - * @param array $options { - * - * @var int $max_restarts - * } + * @param array $options */ public function __construct(Provider $provider, array $plugins = [], array $options = []) { diff --git a/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php b/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php index 6041a245b..c4be0cc18 100644 --- a/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php +++ b/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php @@ -32,7 +32,7 @@ protected function getCacheDir() /** * Get a real HTTP client. If a cache dir is set to a path it will use cached responses. * - * @return HttpClient + * @return HttplugClient|CachedResponseClient */ protected function getHttpClient($apiKey = null, $appCode = null) { diff --git a/src/Provider/Cache/Tests/ProviderCacheTest.php b/src/Provider/Cache/Tests/ProviderCacheTest.php index 9b1c3559a..9e47f48a5 100644 --- a/src/Provider/Cache/Tests/ProviderCacheTest.php +++ b/src/Provider/Cache/Tests/ProviderCacheTest.php @@ -18,6 +18,7 @@ use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\SimpleCache\CacheInterface; @@ -27,12 +28,12 @@ class ProviderCacheTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|Provider + * @var Provider|MockObject */ private $providerMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject|CacheInterface + * @var CacheInterface|MockObject */ private $cacheMock; @@ -60,16 +61,6 @@ public function testName() $this->assertEquals('foo (cache)', $providerCache->getName()); } - public function testMagicFunction() - { - $this->providerMock->expects($this->once()) - ->method('getFoo') - ->willReturn('foo'); - - $providerCache = new ProviderCache($this->providerMock, $this->cacheMock); - $this->assertEquals('foo', $providerCache->getFoo()); - } - public function testGeocodeMiss() { $query = GeocodeQuery::create('foo'); diff --git a/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php b/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php index 19272f02f..358270a10 100644 --- a/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php +++ b/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php @@ -14,6 +14,7 @@ use Geocoder\Provider\GeoIP2\GeoIP2Adapter; use RuntimeException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -121,7 +122,7 @@ public function testReaderResponseIsJsonEncoded() } /** - * @return \PHPUnit_Framework_MockObject_MockObject + * @return MockObject */ protected function getGeoIP2ProviderMock() { @@ -133,7 +134,7 @@ protected function getGeoIP2ProviderMock() /** * @param int $geoIP2Model (e.g. GeoIP2Adapter::GEOIP2_MODEL_CITY, ...) * - * @return \PHPUnit_Framework_MockObject_MockObject + * @return MockObject */ protected function getGeoIP2ModelMock($geoIP2Model) { diff --git a/src/Provider/GeoIP2/Tests/GeoIP2Test.php b/src/Provider/GeoIP2/Tests/GeoIP2Test.php index decbca209..4038874a6 100644 --- a/src/Provider/GeoIP2/Tests/GeoIP2Test.php +++ b/src/Provider/GeoIP2/Tests/GeoIP2Test.php @@ -24,6 +24,7 @@ use GeoIp2\Exception\OutOfQueriesException; use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\QuotaExceeded; +use PHPUnit\Framework\MockObject\MockObject; /** * @author Jens Wiese @@ -261,7 +262,7 @@ public static function provideDataForTestingExceptions(): array /** * @param mixed $returnValue * - * @return \PHPUnit_Framework_MockObject_MockObject|GeoIP2Adapter + * @return GeoIP2Adapter|MockObject */ private function getGeoIP2AdapterMock($returnValue = '') { diff --git a/src/Provider/Geonames/Geonames.php b/src/Provider/Geonames/Geonames.php index 8ef2539f1..8430d1521 100644 --- a/src/Provider/Geonames/Geonames.php +++ b/src/Provider/Geonames/Geonames.php @@ -228,7 +228,7 @@ private function executeQuery(string $url, string $locale = null): AddressCollec $address = $address->withAsciiName($item->asciiName ?? null); $address = $address->withFclName($item->fclName ?? null); $address = $address->withAlternateNames($item->alternateNames ?? []); - $address = $address->withPopulation($item->population ?? null); + $address = $address->withPopulation((int) $item->population ?? null); $address = $address->withGeonameId($item->geonameId ?? null); $address = $address->withFcode($item->fcode ?? null); diff --git a/src/Provider/Geonames/Model/CountryInfo.php b/src/Provider/Geonames/Model/CountryInfo.php index b62065543..807b8bbd5 100644 --- a/src/Provider/Geonames/Model/CountryInfo.php +++ b/src/Provider/Geonames/Model/CountryInfo.php @@ -258,10 +258,10 @@ public function getPopulation() * * @return CountryInfo */ - public function withPopulation(string $population = null): self + public function withPopulation(int $population = null): self { $new = clone $this; - $new->population = null === $population ? null : (int) $population; + $new->population = null === $population ? null : $population; return $new; } diff --git a/src/Provider/Geonames/Model/GeonamesAddress.php b/src/Provider/Geonames/Model/GeonamesAddress.php index af176ef53..22d10cc2c 100644 --- a/src/Provider/Geonames/Model/GeonamesAddress.php +++ b/src/Provider/Geonames/Model/GeonamesAddress.php @@ -61,7 +61,7 @@ final class GeonamesAddress extends Address /** * @return string|null */ - public function getName(): string + public function getName() { return $this->name; } diff --git a/src/Provider/GoogleMapsPlaces/Model/GooglePlace.php b/src/Provider/GoogleMapsPlaces/Model/GooglePlace.php index 477abebe0..58d6d4a7d 100644 --- a/src/Provider/GoogleMapsPlaces/Model/GooglePlace.php +++ b/src/Provider/GoogleMapsPlaces/Model/GooglePlace.php @@ -204,7 +204,7 @@ public function withVicinity(string $vicinity = null) /** * @return string|null */ - public function getIcon(): string + public function getIcon() { return $this->icon; } @@ -236,7 +236,7 @@ public function withPlusCode(PlusCode $plusCode = null) /** * @return Photo[]|null */ - public function getPhotos(): array + public function getPhotos() { return $this->photos; } @@ -260,7 +260,7 @@ public function withPhotos(array $photos = null) * * @return int|null */ - public function getPriceLevel(): int + public function getPriceLevel() { return $this->priceLevel; } @@ -276,7 +276,7 @@ public function withPriceLevel(int $priceLevel = null) /** * @return float|null */ - public function getRating(): float + public function getRating() { return $this->rating; } diff --git a/src/Provider/GraphHopper/GraphHopper.php b/src/Provider/GraphHopper/GraphHopper.php index 28793dfd2..3d1442251 100644 --- a/src/Provider/GraphHopper/GraphHopper.php +++ b/src/Provider/GraphHopper/GraphHopper.php @@ -104,8 +104,6 @@ public function getName(): string /** * @param $url - * - * @return Collection */ private function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/Here/Model/HereAddress.php b/src/Provider/Here/Model/HereAddress.php index 03d9bef15..ff4c324b3 100644 --- a/src/Provider/Here/Model/HereAddress.php +++ b/src/Provider/Here/Model/HereAddress.php @@ -53,7 +53,7 @@ public function getLocationId() } /** - * @param string|null $LocationId + * @param string|null $locationId * * @return HereAddress */ @@ -74,7 +74,7 @@ public function getLocationType() } /** - * @param string|null $LocationType + * @param string|null $locationType * * @return HereAddress */ @@ -95,7 +95,7 @@ public function getLocationName() } /** - * @param string|null $LocationName + * @param string|null $locationName * * @return HereAddress */ diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 6f17e95cf..774fb8e52 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -21,6 +21,7 @@ use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; use Geocoder\Provider\Here\Here; +use Geocoder\Provider\Here\Model\HereAddress; class HereTest extends BaseTestCase { @@ -81,7 +82,7 @@ public function testGeocodeWithDefaultAdditionalData() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Location $result */ + /** @var HereAddress $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); @@ -127,7 +128,7 @@ public function testGeocodeWithAdditionalData() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Location $result */ + /** @var HereAddress $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEqualsWithDelta(41.37854, $result->getCoordinates()->getLatitude(), 0.01); @@ -250,7 +251,9 @@ public function testGeocodeWithExtraFilterCounty() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $resultsRegion1); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $resultsRegion2); + /** @var HereAddress $resultRegion1 */ $resultRegion1 = $resultsRegion1->first(); + /** @var HereAddress $resultRegion2 */ $resultRegion2 = $resultsRegion2->first(); $this->assertEquals('Cabanes', $resultRegion1->getLocality()); diff --git a/src/Provider/HostIp/HostIp.php b/src/Provider/HostIp/HostIp.php index e893cb50f..aeed62a42 100644 --- a/src/Provider/HostIp/HostIp.php +++ b/src/Provider/HostIp/HostIp.php @@ -44,8 +44,6 @@ public function getEndpointURL(): string /** * @param string $url - * - * @return Collection */ protected function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/HostIp/HostIpXml.php b/src/Provider/HostIp/HostIpXml.php index 224448c0b..4b7efe2eb 100644 --- a/src/Provider/HostIp/HostIpXml.php +++ b/src/Provider/HostIp/HostIpXml.php @@ -44,8 +44,6 @@ public function getEndpointURL(): string /** * @param string $url - * - * @return Collection */ protected function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/IP2Location/IP2Location.php b/src/Provider/IP2Location/IP2Location.php index d082a29f1..6be638fb9 100644 --- a/src/Provider/IP2Location/IP2Location.php +++ b/src/Provider/IP2Location/IP2Location.php @@ -97,8 +97,6 @@ public function getName(): string /** * @param string $url - * - * @return Collection */ private function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/IpInfo/IpInfo.php b/src/Provider/IpInfo/IpInfo.php index a03199aba..9fd4e17dd 100644 --- a/src/Provider/IpInfo/IpInfo.php +++ b/src/Provider/IpInfo/IpInfo.php @@ -67,8 +67,6 @@ public function getName(): string /** * @param string $url - * - * @return Collection */ private function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/IpInfoDb/IpInfoDb.php b/src/Provider/IpInfoDb/IpInfoDb.php index 6fed72b0c..5d95bc491 100644 --- a/src/Provider/IpInfoDb/IpInfoDb.php +++ b/src/Provider/IpInfoDb/IpInfoDb.php @@ -123,8 +123,6 @@ public function getName(): string /** * @param string $url - * - * @return Collection */ private function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/Ipstack/Tests/IpstackTest.php b/src/Provider/Ipstack/Tests/IpstackTest.php index 1e86d0153..d9b05554c 100644 --- a/src/Provider/Ipstack/Tests/IpstackTest.php +++ b/src/Provider/Ipstack/Tests/IpstackTest.php @@ -13,6 +13,7 @@ namespace Geocoder\Provider\Ipstack\Tests; use Geocoder\IntegrationTest\BaseTestCase; +use Geocoder\Location; use Geocoder\Provider\Ipstack\Ipstack; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; diff --git a/src/Provider/MapQuest/MapQuest.php b/src/Provider/MapQuest/MapQuest.php index 325f8f983..1291e346f 100644 --- a/src/Provider/MapQuest/MapQuest.php +++ b/src/Provider/MapQuest/MapQuest.php @@ -253,7 +253,8 @@ private function executePostQuery(string $endpoint, array $params) } /** - * @param string $url + * @param string $endpoint + * @param array $params * * @return AddressCollection */ diff --git a/src/Provider/MapTiler/MapTiler.php b/src/Provider/MapTiler/MapTiler.php index 4569ee1e2..337b299a3 100644 --- a/src/Provider/MapTiler/MapTiler.php +++ b/src/Provider/MapTiler/MapTiler.php @@ -42,7 +42,7 @@ final class MapTiler extends AbstractHttpProvider implements Provider /** * @param ClientInterface $client an HTTP client - * @param string $key API key + * @param string $apiKey API key */ public function __construct(ClientInterface $client, string $apiKey) { diff --git a/src/Provider/Mapbox/Tests/MapboxTest.php b/src/Provider/Mapbox/Tests/MapboxTest.php index 411e1c259..8c18898a2 100644 --- a/src/Provider/Mapbox/Tests/MapboxTest.php +++ b/src/Provider/Mapbox/Tests/MapboxTest.php @@ -20,6 +20,7 @@ use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; use Geocoder\Provider\Mapbox\Mapbox; +use Geocoder\Provider\Mapbox\Model\MapboxAddress; class MapboxTest extends BaseTestCase { @@ -99,9 +100,9 @@ public function testGeocodePlaceWithNoCountryShortCode() $this->assertInstanceOf(AddressCollection::class, $results); $this->assertCount(1, $results); - /** @var Location $result */ + /** @var MapboxAddress $result */ $result = $results->first(); - $this->assertInstanceOf(Address::class, $result); + $this->assertInstanceOf(MapboxAddress::class, $result); $this->assertEqualsWithDelta(43.73125, $result->getCoordinates()->getLatitude(), 0.001); $this->assertEqualsWithDelta(7.41974, $result->getCoordinates()->getLongitude(), 0.001); $this->assertEquals('Principato di Monaco', $result->getStreetName()); @@ -128,9 +129,9 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf(AddressCollection::class, $results); $this->assertCount(5, $results); - /** @var Location $result */ + /** @var MapboxAddress $result */ $result = $results->first(); - $this->assertInstanceOf(Address::class, $result); + $this->assertInstanceOf(MapboxAddress::class, $result); $this->assertEqualsWithDelta(37.77572, $result->getCoordinates()->getLatitude(), 0.001); $this->assertEqualsWithDelta(-122.41362, $result->getCoordinates()->getLongitude(), 0.001); $this->assertNull($result->getBounds()); @@ -169,9 +170,9 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf(AddressCollection::class, $results); $this->assertCount(4, $results); - /** @var Location $result */ + /** @var MapboxAddress $result */ $result = $results->first(); - $this->assertInstanceOf(Address::class, $result); + $this->assertInstanceOf(MapboxAddress::class, $result); $this->assertEquals(8, $result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); @@ -204,9 +205,9 @@ public function testGeocodeWithRealValidApiKey() $this->assertInstanceOf(AddressCollection::class, $results); $this->assertCount(5, $results); - /** @var Location $result */ + /** @var MapboxAddress $result */ $result = $results->first(); - $this->assertInstanceOf(Address::class, $result); + $this->assertInstanceOf(MapboxAddress::class, $result); $this->assertEquals('116th Street', $result->getStreetName()); $this->assertEquals(11356, $result->getPostalCode()); $this->assertCount(2, $result->getAdminLevels()); diff --git a/src/Provider/Mapzen/Mapzen.php b/src/Provider/Mapzen/Mapzen.php index fbeea8f15..4deec5411 100644 --- a/src/Provider/Mapzen/Mapzen.php +++ b/src/Provider/Mapzen/Mapzen.php @@ -104,8 +104,6 @@ public function getName(): string /** * @param $url - * - * @return Collection */ private function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/MaxMind/MaxMind.php b/src/Provider/MaxMind/MaxMind.php index 379fcd68a..55833a46e 100644 --- a/src/Provider/MaxMind/MaxMind.php +++ b/src/Provider/MaxMind/MaxMind.php @@ -108,8 +108,6 @@ public function getName(): string /** * @param string $url - * - * @return Collection */ private function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/MaxMindBinary/MaxMindBinary.php b/src/Provider/MaxMindBinary/MaxMindBinary.php index 9a86c5c96..09452b384 100644 --- a/src/Provider/MaxMindBinary/MaxMindBinary.php +++ b/src/Provider/MaxMindBinary/MaxMindBinary.php @@ -90,20 +90,20 @@ public function geocodeQuery(GeocodeQuery $query): Collection $adminLevels = []; - if ($geoIpRecord->region) { - $adminLevels[] = ['name' => $geoIpRecord->region, 'level' => 1]; + if ($geoIpRecord->region) { // @phpstan-ignore-line + $adminLevels[] = ['name' => $geoIpRecord->region, 'level' => 1]; // @phpstan-ignore-line } return new AddressCollection([ Address::createFromArray([ 'providedBy' => $this->getName(), - 'countryCode' => $geoIpRecord->country_code, - 'country' => null === $geoIpRecord->country_name ? null : utf8_encode($geoIpRecord->country_name), + 'countryCode' => $geoIpRecord->country_code, // @phpstan-ignore-line + 'country' => null === $geoIpRecord->country_name ? null : utf8_encode($geoIpRecord->country_name), // @phpstan-ignore-line 'adminLevels' => $adminLevels, - 'locality' => null === $geoIpRecord->city ? null : utf8_encode($geoIpRecord->city), - 'latitude' => $geoIpRecord->latitude, - 'longitude' => $geoIpRecord->longitude, - 'postalCode' => $geoIpRecord->postal_code, + 'locality' => null === $geoIpRecord->city ? null : utf8_encode($geoIpRecord->city), // @phpstan-ignore-line + 'latitude' => $geoIpRecord->latitude, // @phpstan-ignore-line + 'longitude' => $geoIpRecord->longitude, // @phpstan-ignore-line + 'postalCode' => $geoIpRecord->postal_code, // @phpstan-ignore-line ]), ]); } diff --git a/src/Provider/Nominatim/Tests/NominatimTest.php b/src/Provider/Nominatim/Tests/NominatimTest.php index c318ca552..937a235a8 100644 --- a/src/Provider/Nominatim/Tests/NominatimTest.php +++ b/src/Provider/Nominatim/Tests/NominatimTest.php @@ -121,7 +121,10 @@ public function testGeocodeWithRealAddressThatReturnsOptionalQuarter() $this->assertCount(1, $results); - $this->assertEquals('Ksawerów', $results->first()->getQuarter()); + /** @var \Geocoder\Provider\Nominatim\Model\NominatimAddress $result */ + $result = $results->first(); + + $this->assertEquals('Ksawerów', $result->getQuarter()); } public function testGeocodeWithRealAddressAndExtraTags() diff --git a/src/Provider/Pelias/Pelias.php b/src/Provider/Pelias/Pelias.php index 8eb2da718..b66d42f2f 100644 --- a/src/Provider/Pelias/Pelias.php +++ b/src/Provider/Pelias/Pelias.php @@ -123,8 +123,6 @@ public function getName(): string /** * @param $url - * - * @return Collection */ protected function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index 5cdd4d2ad..3ab2b15d8 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -149,7 +149,9 @@ private function featureToAddress(\stdClass $feature): Location } /** @var PhotonAddress $address */ - $address = $builder->build(PhotonAddress::class) + $address = $builder->build(PhotonAddress::class); + + $address = $address ->withOSMId($properties->osm_id ?? null) ->withOSMType($properties->osm_type ?? null) ->withOSMTag( diff --git a/src/Provider/Yandex/Model/YandexAddress.php b/src/Provider/Yandex/Model/YandexAddress.php index dd28e47ee..d891fffa0 100644 --- a/src/Provider/Yandex/Model/YandexAddress.php +++ b/src/Provider/Yandex/Model/YandexAddress.php @@ -83,7 +83,7 @@ public function withName(string $name = null): self /** * @return string|null */ - public function getKind(): string + public function getKind() { return $this->kind; } diff --git a/src/Provider/Yandex/Tests/YandexTest.php b/src/Provider/Yandex/Tests/YandexTest.php index 67d70e18f..08e6d4dbb 100644 --- a/src/Provider/Yandex/Tests/YandexTest.php +++ b/src/Provider/Yandex/Tests/YandexTest.php @@ -408,7 +408,7 @@ public function testReverseMetroStationToGetName() $provider = new Yandex($this->getHttpClient(), 'metro'); $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(60.036843, 30.324285)); - /** @var YandexAddress $first */ + /** @var YandexAddress $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Provider\Yandex\Model\YandexAddress', $result); $this->assertEquals('other', $result->getPrecision()); From abacbb7e0eb7fe9b506ab4e302dc68618c4ef6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:19:35 +0200 Subject: [PATCH 08/26] Update composer.json --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 11d15bc07..f8f11f3e5 100644 --- a/composer.json +++ b/composer.json @@ -76,5 +76,10 @@ "scripts": { "test": "vendor/bin/phpunit", "phpstan": "vendor/bin/phpstan analyse" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } } } From 5b86282b2948947583694e9bd8d10d2dd00a3ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:19:44 +0200 Subject: [PATCH 09/26] Fix PHPStan level 3 --- phpstan.neon | 2 +- src/Common/Model/Address.php | 4 ++-- src/Provider/ArcGISOnline/Tests/IntegrationTest.php | 2 +- src/Provider/FreeGeoIp/Tests/IntegrationTest.php | 2 +- src/Provider/GeoIP2/Tests/IntegrationTest.php | 2 +- src/Provider/GeoPlugin/Tests/IntegrationTest.php | 2 +- src/Provider/Geoip/Tests/IntegrationTest.php | 2 +- src/Provider/HostIp/Tests/IntegrationTest.php | 2 +- src/Provider/IP2LocationBinary/Tests/IntegrationTest.php | 2 +- src/Provider/MaxMindBinary/Tests/IntegrationTest.php | 2 +- src/Provider/Nominatim/Tests/IntegrationTest.php | 2 +- src/Provider/Pelias/Tests/IntegrationTest.php | 2 +- src/Provider/Photon/Tests/IntegrationTest.php | 2 +- src/Provider/Yandex/Tests/IntegrationTest.php | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 0d171ca46..4e76639d4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 2 + level: 3 paths: - src excludePaths: diff --git a/src/Common/Model/Address.php b/src/Common/Model/Address.php index 2adba83ea..e22872c8b 100644 --- a/src/Common/Model/Address.php +++ b/src/Common/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, @@ -247,7 +247,7 @@ public static function createFromArray(array $data) $adminLevels[] = new AdminLevel($adminLevel['level'], $name, $adminLevel['code'] ?? null); } - return new self( + return new static( $data['providedBy'], new AdminLevelCollection($adminLevels), self::createCoordinates( diff --git a/src/Provider/ArcGISOnline/Tests/IntegrationTest.php b/src/Provider/ArcGISOnline/Tests/IntegrationTest.php index 0d7885cfb..71e67e135 100644 --- a/src/Provider/ArcGISOnline/Tests/IntegrationTest.php +++ b/src/Provider/ArcGISOnline/Tests/IntegrationTest.php @@ -41,6 +41,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/FreeGeoIp/Tests/IntegrationTest.php b/src/Provider/FreeGeoIp/Tests/IntegrationTest.php index e85852211..93b2a97a1 100644 --- a/src/Provider/FreeGeoIp/Tests/IntegrationTest.php +++ b/src/Provider/FreeGeoIp/Tests/IntegrationTest.php @@ -37,6 +37,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/GeoIP2/Tests/IntegrationTest.php b/src/Provider/GeoIP2/Tests/IntegrationTest.php index e0cac8642..65d2b8585 100644 --- a/src/Provider/GeoIP2/Tests/IntegrationTest.php +++ b/src/Provider/GeoIP2/Tests/IntegrationTest.php @@ -45,6 +45,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/GeoPlugin/Tests/IntegrationTest.php b/src/Provider/GeoPlugin/Tests/IntegrationTest.php index 312ef851b..d28f11359 100644 --- a/src/Provider/GeoPlugin/Tests/IntegrationTest.php +++ b/src/Provider/GeoPlugin/Tests/IntegrationTest.php @@ -37,6 +37,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/Geoip/Tests/IntegrationTest.php b/src/Provider/Geoip/Tests/IntegrationTest.php index fa5fc111c..8db7b7e12 100644 --- a/src/Provider/Geoip/Tests/IntegrationTest.php +++ b/src/Provider/Geoip/Tests/IntegrationTest.php @@ -48,6 +48,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/HostIp/Tests/IntegrationTest.php b/src/Provider/HostIp/Tests/IntegrationTest.php index 530ca08f0..22370899e 100644 --- a/src/Provider/HostIp/Tests/IntegrationTest.php +++ b/src/Provider/HostIp/Tests/IntegrationTest.php @@ -43,6 +43,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php index 835588d56..a74fbe552 100644 --- a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php +++ b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php @@ -54,6 +54,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/MaxMindBinary/Tests/IntegrationTest.php b/src/Provider/MaxMindBinary/Tests/IntegrationTest.php index c13986e49..6469b0a94 100644 --- a/src/Provider/MaxMindBinary/Tests/IntegrationTest.php +++ b/src/Provider/MaxMindBinary/Tests/IntegrationTest.php @@ -57,6 +57,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/Nominatim/Tests/IntegrationTest.php b/src/Provider/Nominatim/Tests/IntegrationTest.php index 7ee37b8e7..c3b614c4d 100644 --- a/src/Provider/Nominatim/Tests/IntegrationTest.php +++ b/src/Provider/Nominatim/Tests/IntegrationTest.php @@ -43,6 +43,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/Pelias/Tests/IntegrationTest.php b/src/Provider/Pelias/Tests/IntegrationTest.php index fd905fa7a..25e714607 100644 --- a/src/Provider/Pelias/Tests/IntegrationTest.php +++ b/src/Provider/Pelias/Tests/IntegrationTest.php @@ -44,6 +44,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/Photon/Tests/IntegrationTest.php b/src/Provider/Photon/Tests/IntegrationTest.php index 29ff83545..07a826ce4 100644 --- a/src/Provider/Photon/Tests/IntegrationTest.php +++ b/src/Provider/Photon/Tests/IntegrationTest.php @@ -44,6 +44,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } diff --git a/src/Provider/Yandex/Tests/IntegrationTest.php b/src/Provider/Yandex/Tests/IntegrationTest.php index 2d88327db..672951a3e 100644 --- a/src/Provider/Yandex/Tests/IntegrationTest.php +++ b/src/Provider/Yandex/Tests/IntegrationTest.php @@ -46,6 +46,6 @@ protected function getCacheDir() protected function getApiKey() { - return null; + return ''; } } From 44e4ff3df3b1f3f4654c7565064532e516c11b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:24:35 +0200 Subject: [PATCH 10/26] Fix tests --- src/Provider/GeoPlugin/Tests/IntegrationTest.php | 2 +- src/Provider/Geonames/Geonames.php | 2 +- src/Provider/Geonames/Model/CountryInfo.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Provider/GeoPlugin/Tests/IntegrationTest.php b/src/Provider/GeoPlugin/Tests/IntegrationTest.php index d28f11359..f8fc450c3 100644 --- a/src/Provider/GeoPlugin/Tests/IntegrationTest.php +++ b/src/Provider/GeoPlugin/Tests/IntegrationTest.php @@ -27,7 +27,7 @@ class IntegrationTest extends ProviderIntegrationTest protected function createProvider(ClientInterface $httpClient) { - return new GeoPlugin($httpClient, $this->getApiKey()); + return new GeoPlugin($httpClient); } protected function getCacheDir() diff --git a/src/Provider/Geonames/Geonames.php b/src/Provider/Geonames/Geonames.php index 8430d1521..8ef2539f1 100644 --- a/src/Provider/Geonames/Geonames.php +++ b/src/Provider/Geonames/Geonames.php @@ -228,7 +228,7 @@ private function executeQuery(string $url, string $locale = null): AddressCollec $address = $address->withAsciiName($item->asciiName ?? null); $address = $address->withFclName($item->fclName ?? null); $address = $address->withAlternateNames($item->alternateNames ?? []); - $address = $address->withPopulation((int) $item->population ?? null); + $address = $address->withPopulation($item->population ?? null); $address = $address->withGeonameId($item->geonameId ?? null); $address = $address->withFcode($item->fcode ?? null); diff --git a/src/Provider/Geonames/Model/CountryInfo.php b/src/Provider/Geonames/Model/CountryInfo.php index 807b8bbd5..5a1a56085 100644 --- a/src/Provider/Geonames/Model/CountryInfo.php +++ b/src/Provider/Geonames/Model/CountryInfo.php @@ -254,14 +254,14 @@ public function getPopulation() } /** - * @param int|null $population + * @param int|string|null $population * * @return CountryInfo */ - public function withPopulation(int $population = null): self + public function withPopulation($population = null): self { $new = clone $this; - $new->population = null === $population ? null : $population; + $new->population = null === $population ? null : (is_string($population) ? (int) $population : $population); return $new; } From 29c0f581c8b3a499daeece88ebe046928cf5980e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:40:54 +0200 Subject: [PATCH 11/26] Fix PHPStan level 4 --- phpstan.neon | 3 ++- src/Common/ProviderAggregator.php | 10 +--------- src/Common/StatefulGeocoder.php | 2 +- src/Provider/AlgoliaPlaces/AlgoliaPlaces.php | 4 ---- .../GoogleMapsPlaces/Tests/GoogleMapsPlacesTest.php | 12 ++++++------ src/Provider/HostIp/AbstractHostIp.php | 6 ++---- src/Provider/Mapbox/Mapbox.php | 10 ++-------- src/Provider/MaxMind/Tests/MaxMindTest.php | 1 - src/Provider/Pelias/Pelias.php | 6 ------ 9 files changed, 14 insertions(+), 40 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 4e76639d4..51e9ec40f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,7 @@ parameters: - level: 3 + level: 4 paths: - src excludePaths: - **/vendor/** + treatPhpDocTypesAsCertain: false diff --git a/src/Common/ProviderAggregator.php b/src/Common/ProviderAggregator.php index c3e269403..c442bd53d 100644 --- a/src/Common/ProviderAggregator.php +++ b/src/Common/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); } @@ -174,7 +166,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 // @phpstan-ignore-line { if (null !== $currentProvider) { return $currentProvider; diff --git a/src/Common/StatefulGeocoder.php b/src/Common/StatefulGeocoder.php index ebf5e4c96..73c724631 100644 --- a/src/Common/StatefulGeocoder.php +++ b/src/Common/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/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php b/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php index 1a6d9e6a7..366ceedaf 100644 --- a/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php +++ b/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php @@ -53,15 +53,11 @@ class AlgoliaPlaces extends AbstractHttpProvider implements Provider /** @var GeocodeQuery */ private $query; - /** @var ClientInterface */ - private $client; - public function __construct(ClientInterface $client, string $apiKey = null, string $appId = null) { parent::__construct($client); $this->apiKey = $apiKey; - $this->client = $client; $this->appId = $appId; } diff --git a/src/Provider/GoogleMapsPlaces/Tests/GoogleMapsPlacesTest.php b/src/Provider/GoogleMapsPlaces/Tests/GoogleMapsPlacesTest.php index f2f106614..025f61521 100644 --- a/src/Provider/GoogleMapsPlaces/Tests/GoogleMapsPlacesTest.php +++ b/src/Provider/GoogleMapsPlaces/Tests/GoogleMapsPlacesTest.php @@ -298,14 +298,14 @@ public function testReverseGeocodePlaceSearchWithEmptyOpeningHours() $this->markTestIncomplete('Test is giving irregular results. Marking incomplete for now.'); - /** @var GooglePlace $resultOne */ - $resultOne = $results->get(13); - $this->assertNull($resultOne->getOpeningHours()->isOpenNow()); + // /** @var GooglePlace $resultOne */ + // $resultOne = $results->get(13); + // $this->assertNull($resultOne->getOpeningHours()->isOpenNow()); // sometimes giving: Error: Call to a member function isOpenNow() on null - /** @var GooglePlace $resultTwo */ - $resultTwo = $results->first(); - $this->assertNull($resultTwo->getOpeningHours()); + // /** @var GooglePlace $resultTwo */ + // $resultTwo = $results->first(); + // $this->assertNull($resultTwo->getOpeningHours()); // sometimes giving: Failed asserting that Object ['openNow' => null, 'periods' => [], 'weekdayText' => []] is null } diff --git a/src/Provider/HostIp/AbstractHostIp.php b/src/Provider/HostIp/AbstractHostIp.php index 7d6aa592e..2adcda05f 100644 --- a/src/Provider/HostIp/AbstractHostIp.php +++ b/src/Provider/HostIp/AbstractHostIp.php @@ -73,8 +73,7 @@ protected function isUnknownLocation(array $data): bool return empty($data['lat']) && empty($data['lng']) && '(Unknown City?)' === $data['city'] - && '(Unknown Country?)' === $data['country_name'] - && 'XX' === $data; + && '(Unknown Country?)' === $data['country_name']; } /** @@ -87,8 +86,7 @@ protected function isPrivateLocation(array $data): bool return empty($data['lat']) && empty($data['lng']) && '(Private Address)' === $data['city'] - && '(Private Address)' === $data['country_name'] - && 'XX' === $data; + && '(Private Address)' === $data['country_name']; } /** diff --git a/src/Provider/Mapbox/Mapbox.php b/src/Provider/Mapbox/Mapbox.php index a99ecdae7..04587d1a9 100644 --- a/src/Provider/Mapbox/Mapbox.php +++ b/src/Provider/Mapbox/Mapbox.php @@ -123,11 +123,6 @@ final class Mapbox extends AbstractHttpProvider implements Provider const DEFAULT_TYPE = self::TYPE_ADDRESS; - /** - * @var ClientInterface - */ - private $client; - /** * @var string */ @@ -161,7 +156,6 @@ public function __construct( throw new InvalidArgument('The Mapbox geocoding mode should be either mapbox.places or mapbox.places-permanent.'); } - $this->client = $client; $this->accessToken = $accessToken; $this->country = $country; $this->geocodingMode = $geocodingMode; @@ -199,7 +193,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection $urlParameters['fuzzyMatch'] = $fuzzyMatch ? 'true' : 'false'; } - if ($urlParameters) { + if (count($urlParameters) > 0) { $url .= '?'.http_build_query($urlParameters); } @@ -222,7 +216,7 @@ public function reverseQuery(ReverseQuery $query): Collection $urlParameters['types'] = self::DEFAULT_TYPE; } - if ($urlParameters) { + if (count($urlParameters) > 0) { $url .= '?'.http_build_query($urlParameters); } diff --git a/src/Provider/MaxMind/Tests/MaxMindTest.php b/src/Provider/MaxMind/Tests/MaxMindTest.php index cad15b2f1..1e0d69793 100644 --- a/src/Provider/MaxMind/Tests/MaxMindTest.php +++ b/src/Provider/MaxMind/Tests/MaxMindTest.php @@ -278,7 +278,6 @@ public function testGeocodeServiceWithRealIPv4() $this->assertEquals('Plano', $result->getLocality()); $this->assertNull($result->getSubLocality()); $this->assertCount(1, $result->getAdminLevels()); - $this->assertNull($result->getAdminLevels()->get(1)->getName()); $this->assertEquals('TX', $result->getAdminLevels()->get(1)->getCode()); $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); diff --git a/src/Provider/Pelias/Pelias.php b/src/Provider/Pelias/Pelias.php index b66d42f2f..19e71b679 100644 --- a/src/Provider/Pelias/Pelias.php +++ b/src/Provider/Pelias/Pelias.php @@ -31,11 +31,6 @@ class Pelias extends AbstractHttpProvider implements Provider */ protected $root; - /** - * @var int - */ - private $version; - /** * @param ClientInterface $client an HTTP adapter * @param string $root url of Pelias API @@ -44,7 +39,6 @@ class Pelias extends AbstractHttpProvider implements Provider public function __construct(ClientInterface $client, string $root, int $version = 1) { $this->root = sprintf('%s/v%d', rtrim($root, '/'), $version); - $this->version = $version; parent::__construct($client); } From b37b17a7398989e03ee1358a83704436fe1cbc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:42:13 +0200 Subject: [PATCH 12/26] Update src/Common/Tests/TimedGeocoderTest.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomas Norkūnas --- src/Common/Tests/TimedGeocoderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/Tests/TimedGeocoderTest.php b/src/Common/Tests/TimedGeocoderTest.php index e317cb206..318ef4082 100644 --- a/src/Common/Tests/TimedGeocoderTest.php +++ b/src/Common/Tests/TimedGeocoderTest.php @@ -27,7 +27,7 @@ class TimedGeocoderTest extends TestCase private $stopwatch; /** - * @var Provider|MockObject + * @var Provider&MockObject */ private $delegate; From 943181faeb79b811e99a547881b21332793fdc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:42:19 +0200 Subject: [PATCH 13/26] Update src/Provider/Cache/Tests/ProviderCacheTest.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomas Norkūnas --- src/Provider/Cache/Tests/ProviderCacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Cache/Tests/ProviderCacheTest.php b/src/Provider/Cache/Tests/ProviderCacheTest.php index 9e47f48a5..030985d55 100644 --- a/src/Provider/Cache/Tests/ProviderCacheTest.php +++ b/src/Provider/Cache/Tests/ProviderCacheTest.php @@ -28,7 +28,7 @@ class ProviderCacheTest extends TestCase { /** - * @var Provider|MockObject + * @var Provider&MockObject */ private $providerMock; From 63e3a395164eb68a9bcb2e69f92c7d32f98a7bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:42:25 +0200 Subject: [PATCH 14/26] Update src/Provider/Cache/Tests/ProviderCacheTest.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomas Norkūnas --- src/Provider/Cache/Tests/ProviderCacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Cache/Tests/ProviderCacheTest.php b/src/Provider/Cache/Tests/ProviderCacheTest.php index 030985d55..cec3f6ec1 100644 --- a/src/Provider/Cache/Tests/ProviderCacheTest.php +++ b/src/Provider/Cache/Tests/ProviderCacheTest.php @@ -33,7 +33,7 @@ class ProviderCacheTest extends TestCase private $providerMock; /** - * @var CacheInterface|MockObject + * @var CacheInterface&MockObject */ private $cacheMock; From 43d91453c503b3e4bea604ff14ff3e62d74f0938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 17:42:30 +0200 Subject: [PATCH 15/26] Update src/Provider/GeoIP2/Tests/GeoIP2Test.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomas Norkūnas --- src/Provider/GeoIP2/Tests/GeoIP2Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/GeoIP2/Tests/GeoIP2Test.php b/src/Provider/GeoIP2/Tests/GeoIP2Test.php index 4038874a6..aee420354 100644 --- a/src/Provider/GeoIP2/Tests/GeoIP2Test.php +++ b/src/Provider/GeoIP2/Tests/GeoIP2Test.php @@ -262,7 +262,7 @@ public static function provideDataForTestingExceptions(): array /** * @param mixed $returnValue * - * @return GeoIP2Adapter|MockObject + * @return GeoIP2Adapter&MockObject */ private function getGeoIP2AdapterMock($returnValue = '') { From 8fb105a8d0c08e6c686444d4ad10fecb57f2bb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 18:01:29 +0200 Subject: [PATCH 16/26] Fix PHPStan level 5 --- phpstan.neon | 2 +- src/Plugin/Plugin/CachePlugin.php | 4 ++-- src/Plugin/Plugin/LoggerPlugin.php | 3 ++- src/Provider/AzureMaps/AzureMaps.php | 10 +++++----- src/Provider/Chain/Tests/ChainTest.php | 4 ++-- src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php | 10 +++++----- src/Provider/LocationIQ/LocationIQ.php | 4 ++-- src/Provider/MapQuest/Tests/MapQuestTest.php | 2 +- src/Provider/PickPoint/PickPoint.php | 4 ++-- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 51e9ec40f..807cbf8d4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 5 paths: - src excludePaths: diff --git a/src/Plugin/Plugin/CachePlugin.php b/src/Plugin/Plugin/CachePlugin.php index edb956462..649531eda 100644 --- a/src/Plugin/Plugin/CachePlugin.php +++ b/src/Plugin/Plugin/CachePlugin.php @@ -79,8 +79,8 @@ private function getCacheKey(Query $query): string { if (null !== $this->precision && $query instanceof ReverseQuery) { $query = $query->withCoordinates(new Coordinates( - number_format($query->getCoordinates()->getLatitude(), $this->precision), - number_format($query->getCoordinates()->getLongitude(), $this->precision) + (float) number_format($query->getCoordinates()->getLatitude(), $this->precision), + (float) number_format($query->getCoordinates()->getLongitude(), $this->precision) )); } diff --git a/src/Plugin/Plugin/LoggerPlugin.php b/src/Plugin/Plugin/LoggerPlugin.php index 1c5515f1c..894ee5e61 100644 --- a/src/Plugin/Plugin/LoggerPlugin.php +++ b/src/Plugin/Plugin/LoggerPlugin.php @@ -14,6 +14,7 @@ use Geocoder\Collection; use Geocoder\Exception\Exception; +use Geocoder\Plugin\Plugin; use Geocoder\Query\Query; use Psr\Log\LoggerInterface; @@ -22,7 +23,7 @@ * * @author Tobias Nyholm */ -class LoggerPlugin +class LoggerPlugin implements Plugin { /** * @var LoggerInterface diff --git a/src/Provider/AzureMaps/AzureMaps.php b/src/Provider/AzureMaps/AzureMaps.php index 1020cd11e..d91373d60 100644 --- a/src/Provider/AzureMaps/AzureMaps.php +++ b/src/Provider/AzureMaps/AzureMaps.php @@ -238,12 +238,12 @@ private function formatReverseGeocodeResponse(stdClass $response): array $east = array_shift($northEast); $builder = new AddressBuilder($this->getName()); - $builder->setCoordinates($latitude, $longitude); + $builder->setCoordinates((float) $latitude, (float) $longitude); $builder->setBounds( - $south, - $west, - $north, - $east + (float) $south, + (float) $west, + (float) $north, + (float) $east ); $builder->setStreetName($address->address->streetName ?? null); diff --git a/src/Provider/Chain/Tests/ChainTest.php b/src/Provider/Chain/Tests/ChainTest.php index de37d7c9e..2fb147dae 100644 --- a/src/Provider/Chain/Tests/ChainTest.php +++ b/src/Provider/Chain/Tests/ChainTest.php @@ -50,7 +50,7 @@ public function testReverse() })); $mockTwo = $this->getMockBuilder('Geocoder\\Provider\\Provider')->getMock(); - $result = new AddressCollection(['foo' => 'bar']); + $result = new AddressCollection(['foo' => 'bar']); // @phpstan-ignore-line $mockTwo->expects($this->once()) ->method('reverseQuery') ->will($this->returnValue($result)); @@ -71,7 +71,7 @@ public function testGeocode() })); $mockTwo = $this->getMockBuilder('Geocoder\\Provider\\Provider')->getMock(); - $result = new AddressCollection(['foo' => 'bar']); + $result = new AddressCollection(['foo' => 'bar']); // @phpstan-ignore-line $mockTwo->expects($this->once()) ->method('geocodeQuery') ->with($query) diff --git a/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php b/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php index 358270a10..c462667d7 100644 --- a/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php +++ b/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php @@ -41,7 +41,7 @@ public static function setUpBeforeClass(): void public function setUp(): void { - $this->adapter = new GeoIP2Adapter($this->getGeoIP2ProviderMock()); + $this->adapter = new GeoIP2Adapter($this->getGeoIP2ProviderMock()); // @phpstan-ignore-line } public function testGetName() @@ -90,7 +90,7 @@ public function testIpAddressIsPassedCorrectToReader($geoIp2Model) $this->getGeoIP2ModelMock($geoIp2Model) )); - $adapter = new GeoIP2Adapter($geoIp2Provider, $geoIp2Model); + $adapter = new GeoIP2Adapter($geoIp2Provider, $geoIp2Model); // @phpstan-ignore-line $adapter->getContent('file://geoip?127.0.0.1'); } @@ -99,7 +99,7 @@ public function testNotSupportedGeoIP2ModelLeadsToException() $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('Model "unsupported_model" is not available.'); - new GeoIP2Adapter($this->getGeoIP2ProviderMock(), 'unsupported_model'); + new GeoIP2Adapter($this->getGeoIP2ProviderMock(), 'unsupported_model'); // @phpstan-ignore-line } public function testReaderResponseIsJsonEncoded() @@ -112,7 +112,7 @@ public function testReaderResponseIsJsonEncoded() ->method('city') ->will($this->returnValue($cityModel)); - $adapter = new GeoIP2Adapter($geoIp2Provider); + $adapter = new GeoIP2Adapter($geoIp2Provider); // @phpstan-ignore-line $result = $adapter->getContent('file://database?127.0.0.1'); $this->assertJson($result); @@ -132,7 +132,7 @@ protected function getGeoIP2ProviderMock() } /** - * @param int $geoIP2Model (e.g. GeoIP2Adapter::GEOIP2_MODEL_CITY, ...) + * @param string $geoIP2Model (e.g. GeoIP2Adapter::GEOIP2_MODEL_CITY, ...) * * @return MockObject */ diff --git a/src/Provider/LocationIQ/LocationIQ.php b/src/Provider/LocationIQ/LocationIQ.php index 24f6ded67..eafb0a068 100644 --- a/src/Provider/LocationIQ/LocationIQ.php +++ b/src/Provider/LocationIQ/LocationIQ.php @@ -155,7 +155,7 @@ private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressN $builder->setLocality($this->getNodeValue($addressNode->getElementsByTagName('city'))); $builder->setSubLocality($this->getNodeValue($addressNode->getElementsByTagName('suburb'))); $builder->setCountry($this->getNodeValue($addressNode->getElementsByTagName('country'))); - $builder->setCoordinates($resultNode->getAttribute('lat'), $resultNode->getAttribute('lon')); + $builder->setCoordinates((float) $resultNode->getAttribute('lat'), (float) $resultNode->getAttribute('lon')); $countryCode = $this->getNodeValue($addressNode->getElementsByTagName('country_code')); if (!is_null($countryCode)) { @@ -166,7 +166,7 @@ private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressN if ($boundsAttr) { $bounds = []; list($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']) = explode(',', $boundsAttr); - $builder->setBounds($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']); + $builder->setBounds((float) $bounds['south'], (float) $bounds['north'], (float) $bounds['west'], (float) $bounds['east']); } return $builder->build(); diff --git a/src/Provider/MapQuest/Tests/MapQuestTest.php b/src/Provider/MapQuest/Tests/MapQuestTest.php index 478f9b858..e731c9491 100644 --- a/src/Provider/MapQuest/Tests/MapQuestTest.php +++ b/src/Provider/MapQuest/Tests/MapQuestTest.php @@ -358,7 +358,7 @@ public function testGeocodeWithSpecificCityAndBounds() $query = GeocodeQuery::create('foobar'); $query = $query->withData(MapQuest::DATA_KEY_ADDRESS, $address); - $query = $query->withBounds(new Bounds('39', '-77', '41', '-75')); + $query = $query->withBounds(new Bounds(39, -77, 41, -75)); $results = $provider->geocodeQuery($query); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); diff --git a/src/Provider/PickPoint/PickPoint.php b/src/Provider/PickPoint/PickPoint.php index 987342ba5..94099beb7 100644 --- a/src/Provider/PickPoint/PickPoint.php +++ b/src/Provider/PickPoint/PickPoint.php @@ -134,13 +134,13 @@ private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressN $builder->setSubLocality($this->getNodeValue($addressNode->getElementsByTagName('suburb'))); $builder->setCountry($this->getNodeValue($addressNode->getElementsByTagName('country'))); $builder->setCountryCode(strtoupper($this->getNodeValue($addressNode->getElementsByTagName('country_code')))); - $builder->setCoordinates($resultNode->getAttribute('lat'), $resultNode->getAttribute('lon')); + $builder->setCoordinates((float) $resultNode->getAttribute('lat'), (float) $resultNode->getAttribute('lon')); $boundsAttr = $resultNode->getAttribute('boundingbox'); if ($boundsAttr) { $bounds = []; list($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']) = explode(',', $boundsAttr); - $builder->setBounds($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']); + $builder->setBounds((float) $bounds['south'], (float) $bounds['north'], (float) $bounds['west'], (float) $bounds['east']); } return $builder->build(); From 0e789fbda80d0d8186390c3305f3da99f57c9538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 18:36:25 +0200 Subject: [PATCH 17/26] Normalize composer.json --- composer.json | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index f8f11f3e5..bb74b0518 100644 --- a/composer.json +++ b/composer.json @@ -1,21 +1,21 @@ { "name": "geocoder-php/geocoder", - "type": "library", "description": "A development package for all providers", + "license": "MIT", + "type": "library", "keywords": [ "geocoder", "geocoding", "abstraction", "geoip" ], - "homepage": "http://geocoder-php.org", - "license": "MIT", "authors": [ { "name": "William Durand", "email": "william.durand1@gmail.com" } ], + "homepage": "http://geocoder-php.org", "require": { "php": "^7.4 || ^8.0", "igorw/get-in": "^1.0", @@ -25,8 +25,8 @@ "psr/http-client": "^1.0", "psr/http-client-implementation": "^1.0", "psr/http-message-implementation": "^1.0", - "psr/log": "^1.0|^2.0|^3.0", - "psr/simple-cache": "^1.0|^2.0|^3.0" + "psr/log": "^1.0 || ^2.0 || ^3.0", + "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" }, "require-dev": { "cache/array-adapter": "^1.0", @@ -39,25 +39,22 @@ "php-http/curl-client": "^2.2", "php-http/message": "^1.0", "php-http/mock-client": "^1.0", - "phpunit/phpunit": "^9.5", - "symfony/stopwatch": "~2.5 || ~5.0", + "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.10", "phpstan/phpstan-phpunit": "^1.3", - "phpstan/extension-installer": "^1.3" + "phpunit/phpunit": "^9.5", + "symfony/stopwatch": "~2.5 || ~5.0" }, "suggest": { "ext-geoip": "Enabling the geoip extension allows you to use the MaxMindProvider.", + "ext-json": "If you want to use HostIp", + "ext-simplexml": "If you want to use HostIpXml", "geoip/geoip": "If you are going to use the MaxMindBinaryProvider (conflict with geoip extension).", "geoip2/geoip2": "If you are going to use the GeoIP2DatabaseProvider.", - "symfony/stopwatch": "If you want to use the TimedGeocoder", - "ext-simplexml": "If you want to use HostIpXml", - "ext-json": "If you want to use HostIp" - }, - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" - } + "symfony/stopwatch": "If you want to use the TimedGeocoder" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Geocoder\\": [ @@ -71,15 +68,21 @@ "Geocoder\\Tests\\": "tests/" } }, - "minimum-stability": "dev", - "prefer-stable": true, - "scripts": { - "test": "vendor/bin/phpunit", - "phpstan": "vendor/bin/phpstan analyse" - }, "config": { "allow-plugins": { - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "php-http/discovery": true + }, + "optimize-autoloader": true, + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" } + }, + "scripts": { + "phpstan": "vendor/bin/phpstan analyse", + "test": "vendor/bin/phpunit" } } From 8f457442462f2b59d2b73618ef1f580e8cd99e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 19:07:56 +0200 Subject: [PATCH 18/26] Rename analyse script --- .github/workflows/php.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 22ed05fbf..28a2059a5 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -49,4 +49,4 @@ jobs: - name: Install dependencies run: composer install --no-progress - name: Run PHPStan - run: composer run-script phpstan \ No newline at end of file + run: composer run-script analyse \ No newline at end of file diff --git a/composer.json b/composer.json index bb74b0518..959055414 100644 --- a/composer.json +++ b/composer.json @@ -82,7 +82,7 @@ } }, "scripts": { - "phpstan": "vendor/bin/phpstan analyse", + "analyse": "vendor/bin/phpstan analyse", "test": "vendor/bin/phpunit" } } From 7301d3ff41e231ff5d8b5e2c6679784e6e57bc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 19:55:59 +0200 Subject: [PATCH 19/26] Update composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 959055414..a9dca9983 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,6 @@ "phpstan/extension-installer": true, "php-http/discovery": true }, - "optimize-autoloader": true, "sort-packages": true }, "extra": { From ce4171c8e0d0d39a5a750578c17d35170cb7fe88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 20:32:58 +0200 Subject: [PATCH 20/26] Update IntegrationTest --- .../AlgoliaPlaces/Tests/IntegrationTest.php | 22 ++++++++--------- .../ArcGISOnline/Tests/IntegrationTest.php | 10 ++++---- .../AzureMaps/Tests/IntegrationTest.php | 6 ++--- .../BingMaps/Tests/IntegrationTest.php | 10 ++++---- .../FreeGeoIp/Tests/IntegrationTest.php | 8 +++---- src/Provider/GeoIP2/Tests/IntegrationTest.php | 12 +++++----- src/Provider/GeoIPs/Tests/IntegrationTest.php | 10 ++++---- .../GeoPlugin/Tests/IntegrationTest.php | 8 +++---- .../GeocodeEarth/Tests/IntegrationTest.php | 10 ++++---- src/Provider/Geoip/Tests/IntegrationTest.php | 12 +++++----- .../Geonames/Tests/IntegrationTest.php | 10 ++++---- .../GoogleMaps/Tests/IntegrationTest.php | 8 +++---- .../Tests/IntegrationTest.php | 12 +++++----- .../GraphHopper/Tests/IntegrationTest.php | 10 ++++---- src/Provider/Here/Tests/IntegrationTest.php | 24 +++++++++---------- src/Provider/HostIp/Tests/IntegrationTest.php | 12 +++++----- .../IP2Location/Tests/IntegrationTest.php | 8 +++---- .../Tests/IntegrationTest.php | 15 ++++++------ src/Provider/IpInfo/Tests/IntegrationTest.php | 10 ++++---- .../IpInfoDb/Tests/IntegrationTest.php | 10 ++++---- .../Ipstack/Tests/IntegrationTest.php | 8 +++---- .../LocationIQ/Tests/IntegrationTest.php | 10 ++++---- .../MapQuest/Tests/IntegrationTest.php | 8 +++---- .../MapTiler/Tests/IntegrationTest.php | 14 +++++------ src/Provider/Mapbox/Tests/IntegrationTest.php | 8 +++---- src/Provider/Mapzen/Tests/IntegrationTest.php | 10 ++++---- .../MaxMind/Tests/IntegrationTest.php | 8 +++---- .../MaxMindBinary/Tests/IntegrationTest.php | 15 ++++++------ .../Nominatim/Tests/IntegrationTest.php | 14 +++++------ .../OpenCage/Tests/IntegrationTest.php | 10 ++++---- .../Tests/IntegrationTest.php | 10 ++++---- src/Provider/Pelias/Tests/IntegrationTest.php | 10 ++++---- src/Provider/Photon/Tests/IntegrationTest.php | 14 +++++------ .../PickPoint/Tests/IntegrationTest.php | 4 ++-- src/Provider/TomTom/Tests/IntegrationTest.php | 10 ++++---- src/Provider/Yandex/Tests/IntegrationTest.php | 14 +++++------ 36 files changed, 196 insertions(+), 198 deletions(-) diff --git a/src/Provider/AlgoliaPlaces/Tests/IntegrationTest.php b/src/Provider/AlgoliaPlaces/Tests/IntegrationTest.php index aec24c383..6fa7a0e21 100644 --- a/src/Provider/AlgoliaPlaces/Tests/IntegrationTest.php +++ b/src/Provider/AlgoliaPlaces/Tests/IntegrationTest.php @@ -29,18 +29,18 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $testReverse = false; + protected bool $testReverse = false; protected function createProvider(ClientInterface $httpClient) { return new AlgoliaPlaces($httpClient, $this->getApiKey(), $this->getAppId()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } @@ -66,17 +66,17 @@ private function getCachedHttpClient() return new CachedResponseClient($client, $this->getCacheDir(), $this->getAppId()); } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['ALGOLIA_API_KEY']; } - protected function getAppId() + protected function getAppId(): string { return $_SERVER['ALGOLIA_APP_ID']; } - public function testGeocodeQuery() + public function testGeocodeQuery(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -101,7 +101,7 @@ public function testGeocodeQuery() } } - public function testGeocodeQueryWithNoResults() + public function testGeocodeQueryWithNoResults(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -117,7 +117,7 @@ public function testGeocodeQueryWithNoResults() $this->assertEquals(0, $result->count()); } - public function testReverseQuery() + public function testReverseQuery(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -133,7 +133,7 @@ public function testReverseQuery() $this->assertWellFormattedResult($result); } - public function testReverseQueryWithNoResults() + public function testReverseQueryWithNoResults(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -155,7 +155,7 @@ public function testReverseQueryWithNoResults() * * @param $result */ - private function assertWellFormattedResult(Collection $result) + private function assertWellFormattedResult(Collection $result): void { $this->assertInstanceOf( Collection::class, diff --git a/src/Provider/ArcGISOnline/Tests/IntegrationTest.php b/src/Provider/ArcGISOnline/Tests/IntegrationTest.php index 71e67e135..a2bd1b4b7 100644 --- a/src/Provider/ArcGISOnline/Tests/IntegrationTest.php +++ b/src/Provider/ArcGISOnline/Tests/IntegrationTest.php @@ -21,11 +21,11 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'ArcGIS REST API returns "אצטדיון כדורגל עירוני" for reverse query at 0,0.', ]; @@ -34,12 +34,12 @@ protected function createProvider(ClientInterface $httpClient) return new ArcGISOnline($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/AzureMaps/Tests/IntegrationTest.php b/src/Provider/AzureMaps/Tests/IntegrationTest.php index 60756015a..9dc2e3664 100644 --- a/src/Provider/AzureMaps/Tests/IntegrationTest.php +++ b/src/Provider/AzureMaps/Tests/IntegrationTest.php @@ -13,7 +13,7 @@ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'AzureMaps API returns "position":"0.000000,0.000000" for reverse query at 0,0.', ]; @@ -28,7 +28,7 @@ protected function createProvider(ClientInterface $httpClient) /** * @return string the directory where cached responses are stored */ - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } @@ -36,7 +36,7 @@ protected function getCacheDir() /** * @return string the API key or substring to be removed from cache */ - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['AZURE_MAPS_SUBSCRIPTION_KEY']; } diff --git a/src/Provider/BingMaps/Tests/IntegrationTest.php b/src/Provider/BingMaps/Tests/IntegrationTest.php index 8eaa15cad..877915cdb 100644 --- a/src/Provider/BingMaps/Tests/IntegrationTest.php +++ b/src/Provider/BingMaps/Tests/IntegrationTest.php @@ -19,25 +19,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeQuery' => 'Bing classifies this as Landmarks. They do not have addresses. ', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new BingMaps($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['BINGMAPS_API_KEY']; } diff --git a/src/Provider/FreeGeoIp/Tests/IntegrationTest.php b/src/Provider/FreeGeoIp/Tests/IntegrationTest.php index 93b2a97a1..1abe7dfb2 100644 --- a/src/Provider/FreeGeoIp/Tests/IntegrationTest.php +++ b/src/Provider/FreeGeoIp/Tests/IntegrationTest.php @@ -21,21 +21,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; protected function createProvider(ClientInterface $httpClient) { return new FreeGeoIp($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/GeoIP2/Tests/IntegrationTest.php b/src/Provider/GeoIP2/Tests/IntegrationTest.php index 65d2b8585..b3251d3e1 100644 --- a/src/Provider/GeoIP2/Tests/IntegrationTest.php +++ b/src/Provider/GeoIP2/Tests/IntegrationTest.php @@ -23,13 +23,13 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $testHttpProvider = false; + protected bool $testHttpProvider = false; protected function createProvider(ClientInterface $httpClient) { @@ -38,12 +38,12 @@ protected function createProvider(ClientInterface $httpClient) return new GeoIP2(new GeoIP2Adapter($reader)); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/GeoIPs/Tests/IntegrationTest.php b/src/Provider/GeoIPs/Tests/IntegrationTest.php index 729ade8a7..4b6610153 100644 --- a/src/Provider/GeoIPs/Tests/IntegrationTest.php +++ b/src/Provider/GeoIPs/Tests/IntegrationTest.php @@ -21,23 +21,23 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new GeoIPs($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['GEOIPS_API_KEY']; } diff --git a/src/Provider/GeoPlugin/Tests/IntegrationTest.php b/src/Provider/GeoPlugin/Tests/IntegrationTest.php index f8fc450c3..b7507faa5 100644 --- a/src/Provider/GeoPlugin/Tests/IntegrationTest.php +++ b/src/Provider/GeoPlugin/Tests/IntegrationTest.php @@ -21,21 +21,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; protected function createProvider(ClientInterface $httpClient) { return new GeoPlugin($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/GeocodeEarth/Tests/IntegrationTest.php b/src/Provider/GeocodeEarth/Tests/IntegrationTest.php index ee203c608..882cd73a4 100644 --- a/src/Provider/GeocodeEarth/Tests/IntegrationTest.php +++ b/src/Provider/GeocodeEarth/Tests/IntegrationTest.php @@ -21,25 +21,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'We weirdly find stuff here...', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new GeocodeEarth($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['GEOCODE_EARTH_API_KEY']; } diff --git a/src/Provider/Geoip/Tests/IntegrationTest.php b/src/Provider/Geoip/Tests/IntegrationTest.php index 8db7b7e12..3b87a1880 100644 --- a/src/Provider/Geoip/Tests/IntegrationTest.php +++ b/src/Provider/Geoip/Tests/IntegrationTest.php @@ -21,13 +21,13 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $testHttpProvider = false; + protected bool $testHttpProvider = false; protected function setUp(): void { @@ -41,12 +41,12 @@ protected function createProvider(ClientInterface $httpClient) return new Geoip(); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/Geonames/Tests/IntegrationTest.php b/src/Provider/Geonames/Tests/IntegrationTest.php index 7a162dafd..d51b49c8d 100644 --- a/src/Provider/Geonames/Tests/IntegrationTest.php +++ b/src/Provider/Geonames/Tests/IntegrationTest.php @@ -19,25 +19,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeQuery' => 'This address is not found..', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new Geonames($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['GEONAMES_USERNAME']; } diff --git a/src/Provider/GoogleMaps/Tests/IntegrationTest.php b/src/Provider/GoogleMaps/Tests/IntegrationTest.php index 080949ef3..34fef81de 100644 --- a/src/Provider/GoogleMaps/Tests/IntegrationTest.php +++ b/src/Provider/GoogleMaps/Tests/IntegrationTest.php @@ -21,21 +21,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new GoogleMaps($httpClient, null, $_SERVER['GOOGLE_GEOCODING_KEY']); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['GOOGLE_GEOCODING_KEY']; } diff --git a/src/Provider/GoogleMapsPlaces/Tests/IntegrationTest.php b/src/Provider/GoogleMapsPlaces/Tests/IntegrationTest.php index bc9af9eb7..e361a77bd 100644 --- a/src/Provider/GoogleMapsPlaces/Tests/IntegrationTest.php +++ b/src/Provider/GoogleMapsPlaces/Tests/IntegrationTest.php @@ -21,25 +21,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new GoogleMapsPlaces($httpClient, $_SERVER['GOOGLE_GEOCODING_KEY']); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['GOOGLE_GEOCODING_KEY']; } diff --git a/src/Provider/GraphHopper/Tests/IntegrationTest.php b/src/Provider/GraphHopper/Tests/IntegrationTest.php index 6abb2cc70..01ef15239 100644 --- a/src/Provider/GraphHopper/Tests/IntegrationTest.php +++ b/src/Provider/GraphHopper/Tests/IntegrationTest.php @@ -21,26 +21,26 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeQuery' => 'We get "Great George Street" as first result.', 'testReverseQueryWithNoResults' => 'We get "Atlas Buoy 0.00E 0.00N" monitoring station.', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new GraphHopper($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['GRAPHHOPPER_API_KEY']; } diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index 5ba496905..1717bd911 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -29,16 +29,16 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient, bool $useCIT = false) { return Here::createUsingApiKey($httpClient, $this->getApiKey(), $useCIT); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } @@ -64,12 +64,12 @@ private function getCachedHttpClient() return new CachedResponseClient($client, $this->getCacheDir(), $this->getApiKey()); } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['HERE_APP_ID']; } - protected function getAppId() + protected function getAppId(): string { return $_SERVER['HERE_APP_ID']; } @@ -77,12 +77,12 @@ protected function getAppId() /** * @return string the Here AppCode or substring to be removed from cache */ - protected function getAppCode() + protected function getAppCode(): string { return $_SERVER['HERE_APP_CODE']; } - public function testGeocodeQuery() + public function testGeocodeQuery(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -107,7 +107,7 @@ public function testGeocodeQuery() } } - public function testGeocodeQueryCIT() + public function testGeocodeQueryCIT(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -132,7 +132,7 @@ public function testGeocodeQueryCIT() } } - public function testGeocodeQueryWithNoResults() + public function testGeocodeQueryWithNoResults(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -148,7 +148,7 @@ public function testGeocodeQueryWithNoResults() $this->assertEquals(0, $result->count()); } - public function testReverseQuery() + public function testReverseQuery(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -164,7 +164,7 @@ public function testReverseQuery() $this->assertWellFormattedResult($result); } - public function testReverseQueryCIT() + public function testReverseQueryCIT(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); @@ -180,7 +180,7 @@ public function testReverseQueryCIT() $this->assertWellFormattedResult($result); } - public function testReverseQueryWithNoResults() + public function testReverseQueryWithNoResults(): void { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); diff --git a/src/Provider/HostIp/Tests/IntegrationTest.php b/src/Provider/HostIp/Tests/IntegrationTest.php index 22370899e..cb6da672e 100644 --- a/src/Provider/HostIp/Tests/IntegrationTest.php +++ b/src/Provider/HostIp/Tests/IntegrationTest.php @@ -21,27 +21,27 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeIpv4' => 'api.hostip.info does not resolve..', ]; - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new HostIp($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/IP2Location/Tests/IntegrationTest.php b/src/Provider/IP2Location/Tests/IntegrationTest.php index d06774043..2c8a071a2 100644 --- a/src/Provider/IP2Location/Tests/IntegrationTest.php +++ b/src/Provider/IP2Location/Tests/IntegrationTest.php @@ -19,21 +19,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; protected function createProvider(ClientInterface $httpClient) { return new IP2Location($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { if (!isset($_SERVER['IP2Location_API_KEY'])) { $this->markTestSkipped('No IP2Location API key'); diff --git a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php index a74fbe552..356f0dfc6 100644 --- a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php +++ b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php @@ -21,16 +21,15 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ - ]; + protected array $skippedTests = []; - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $testHttpProvider = false; + protected bool $testHttpProvider = false; public static function setUpBeforeClass(): void { @@ -47,12 +46,12 @@ protected function createProvider(ClientInterface $httpClient) return new IP2LocationBinary(__DIR__.'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN', \IP2Location\Database::FILE_IO); // @phpstan-ignore-line } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/IpInfo/Tests/IntegrationTest.php b/src/Provider/IpInfo/Tests/IntegrationTest.php index 58becfae8..1a8d59462 100644 --- a/src/Provider/IpInfo/Tests/IntegrationTest.php +++ b/src/Provider/IpInfo/Tests/IntegrationTest.php @@ -21,23 +21,23 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = true; + protected bool $testIpv6 = true; protected function createProvider(ClientInterface $httpClient) { return new IpInfo($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/IpInfoDb/Tests/IntegrationTest.php b/src/Provider/IpInfoDb/Tests/IntegrationTest.php index d6677384d..84f9836e4 100644 --- a/src/Provider/IpInfoDb/Tests/IntegrationTest.php +++ b/src/Provider/IpInfoDb/Tests/IntegrationTest.php @@ -21,23 +21,23 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new IpInfoDb($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['IPINFODB_API_KEY']; } diff --git a/src/Provider/Ipstack/Tests/IntegrationTest.php b/src/Provider/Ipstack/Tests/IntegrationTest.php index f8d40ec3c..e6c25a98f 100644 --- a/src/Provider/Ipstack/Tests/IntegrationTest.php +++ b/src/Provider/Ipstack/Tests/IntegrationTest.php @@ -21,21 +21,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; protected function createProvider(ClientInterface $httpClient) { return new Ipstack($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['IPSTACK_API_KEY']; } diff --git a/src/Provider/LocationIQ/Tests/IntegrationTest.php b/src/Provider/LocationIQ/Tests/IntegrationTest.php index fe45fc20b..53277b154 100644 --- a/src/Provider/LocationIQ/Tests/IntegrationTest.php +++ b/src/Provider/LocationIQ/Tests/IntegrationTest.php @@ -19,25 +19,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'We weirdly find stuff here...', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new LocationIQ($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['LOCATIONIQ_API_KEY']; } diff --git a/src/Provider/MapQuest/Tests/IntegrationTest.php b/src/Provider/MapQuest/Tests/IntegrationTest.php index cb36b3a06..27a023861 100644 --- a/src/Provider/MapQuest/Tests/IntegrationTest.php +++ b/src/Provider/MapQuest/Tests/IntegrationTest.php @@ -21,21 +21,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new MapQuest($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['MAPQUEST_API_KEY']; } diff --git a/src/Provider/MapTiler/Tests/IntegrationTest.php b/src/Provider/MapTiler/Tests/IntegrationTest.php index cff43d89b..1f664a415 100644 --- a/src/Provider/MapTiler/Tests/IntegrationTest.php +++ b/src/Provider/MapTiler/Tests/IntegrationTest.php @@ -19,27 +19,27 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = true; + protected bool $testAddress = true; - protected $testReverse = true; + protected bool $testReverse = true; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $skippedTests = []; + protected array $skippedTests = []; protected function createProvider(ClientInterface $httpClient) { return new MapTiler($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['MAPTILER_KEY']; } diff --git a/src/Provider/Mapbox/Tests/IntegrationTest.php b/src/Provider/Mapbox/Tests/IntegrationTest.php index c1b9e46ab..c9c4a9219 100644 --- a/src/Provider/Mapbox/Tests/IntegrationTest.php +++ b/src/Provider/Mapbox/Tests/IntegrationTest.php @@ -21,21 +21,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new Mapbox($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['MAPBOX_GEOCODING_KEY']; } diff --git a/src/Provider/Mapzen/Tests/IntegrationTest.php b/src/Provider/Mapzen/Tests/IntegrationTest.php index 4bee9e49f..c7be4d300 100644 --- a/src/Provider/Mapzen/Tests/IntegrationTest.php +++ b/src/Provider/Mapzen/Tests/IntegrationTest.php @@ -21,26 +21,26 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeQuery' => 'We get wrongs cords', 'testReverseQueryWithNoResults' => 'We weirdly find stuff here...', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new Mapzen($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['MAPZEN_API_KEY']; } diff --git a/src/Provider/MaxMind/Tests/IntegrationTest.php b/src/Provider/MaxMind/Tests/IntegrationTest.php index e14e7daf0..1914dd8e7 100644 --- a/src/Provider/MaxMind/Tests/IntegrationTest.php +++ b/src/Provider/MaxMind/Tests/IntegrationTest.php @@ -19,21 +19,21 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; protected function createProvider(ClientInterface $httpClient) { return new MaxMind($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { if (!isset($_SERVER['MAXMIND_API_KEY'])) { $this->markTestSkipped('No MaxMind API key'); diff --git a/src/Provider/MaxMindBinary/Tests/IntegrationTest.php b/src/Provider/MaxMindBinary/Tests/IntegrationTest.php index 6469b0a94..e92bd7229 100644 --- a/src/Provider/MaxMindBinary/Tests/IntegrationTest.php +++ b/src/Provider/MaxMindBinary/Tests/IntegrationTest.php @@ -21,16 +21,15 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ - ]; + protected array $skippedTests = []; - protected $testAddress = false; + protected bool $testAddress = false; - protected $testReverse = false; + protected bool $testReverse = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $testHttpProvider = false; + protected bool $testHttpProvider = false; public static function setUpBeforeClass(): void { @@ -50,12 +49,12 @@ protected function createProvider(ClientInterface $httpClient) return new MaxMindBinary(__DIR__.'/fixtures/GeoLiteCity.dat'); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/Nominatim/Tests/IntegrationTest.php b/src/Provider/Nominatim/Tests/IntegrationTest.php index c3b614c4d..0fb074917 100644 --- a/src/Provider/Nominatim/Tests/IntegrationTest.php +++ b/src/Provider/Nominatim/Tests/IntegrationTest.php @@ -19,29 +19,29 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'There is "Soul Buoy"', ]; - protected $testAddress = true; + protected bool $testAddress = true; - protected $testReverse = true; + protected bool $testReverse = true; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return Nominatim::withOpenStreetMapServer($httpClient, 'Geocoder PHP/Nominatim Provider/Integration Test'); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/OpenCage/Tests/IntegrationTest.php b/src/Provider/OpenCage/Tests/IntegrationTest.php index 895ea6d78..3ad4930c7 100644 --- a/src/Provider/OpenCage/Tests/IntegrationTest.php +++ b/src/Provider/OpenCage/Tests/IntegrationTest.php @@ -21,25 +21,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'There is a null island', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new OpenCage($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['OPENCAGE_API_KEY']; } diff --git a/src/Provider/OpenRouteService/Tests/IntegrationTest.php b/src/Provider/OpenRouteService/Tests/IntegrationTest.php index 06eac1573..a9c3bbaf8 100644 --- a/src/Provider/OpenRouteService/Tests/IntegrationTest.php +++ b/src/Provider/OpenRouteService/Tests/IntegrationTest.php @@ -21,25 +21,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'We weirdly find stuff here...', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new OpenRouteService($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['OPEN_ROUTE_SERVICE_API_KEY']; } diff --git a/src/Provider/Pelias/Tests/IntegrationTest.php b/src/Provider/Pelias/Tests/IntegrationTest.php index 25e714607..01592f670 100644 --- a/src/Provider/Pelias/Tests/IntegrationTest.php +++ b/src/Provider/Pelias/Tests/IntegrationTest.php @@ -21,28 +21,28 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeQuery' => 'No Pelias "default" instance.', 'testGeocodeQueryWithNoResults' => 'No Pelias "default" instance.', 'testReverseQuery' => 'No Pelias "default" instance.', 'testReverseQueryWithNoResults' => 'No Pelias "default" instance.', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new Pelias($httpClient, 'http://localhost/'); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/Photon/Tests/IntegrationTest.php b/src/Provider/Photon/Tests/IntegrationTest.php index 07a826ce4..cc9200e16 100644 --- a/src/Provider/Photon/Tests/IntegrationTest.php +++ b/src/Provider/Photon/Tests/IntegrationTest.php @@ -19,15 +19,15 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = true; + protected bool $testAddress = true; - protected $testReverse = true; + protected bool $testReverse = true; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeQuery' => 'Photon API returns "Great George Street" for "10 Downing St, London, UK" query.', 'testReverseQueryWithNoResults' => 'Photon API returns "Atlas Buoy 0.00E 0.00N" for reverse query at 0,0.', ]; @@ -37,12 +37,12 @@ protected function createProvider(ClientInterface $httpClient) return Photon::withKomootServer($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } diff --git a/src/Provider/PickPoint/Tests/IntegrationTest.php b/src/Provider/PickPoint/Tests/IntegrationTest.php index d19e397fe..b7f91bc65 100644 --- a/src/Provider/PickPoint/Tests/IntegrationTest.php +++ b/src/Provider/PickPoint/Tests/IntegrationTest.php @@ -24,12 +24,12 @@ protected function createProvider(ClientInterface $httpClient) return new PickPoint($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['PICKPOINT_API_KEY']; } diff --git a/src/Provider/TomTom/Tests/IntegrationTest.php b/src/Provider/TomTom/Tests/IntegrationTest.php index 155e75735..f3be19540 100644 --- a/src/Provider/TomTom/Tests/IntegrationTest.php +++ b/src/Provider/TomTom/Tests/IntegrationTest.php @@ -21,25 +21,25 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testReverseQueryWithNoResults' => 'Null island exists. ', ]; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new TomTom($httpClient, $this->getApiKey()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return $_SERVER['TOMTOM_MAP_KEY']; } diff --git a/src/Provider/Yandex/Tests/IntegrationTest.php b/src/Provider/Yandex/Tests/IntegrationTest.php index 672951a3e..80f69c850 100644 --- a/src/Provider/Yandex/Tests/IntegrationTest.php +++ b/src/Provider/Yandex/Tests/IntegrationTest.php @@ -21,30 +21,30 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $skippedTests = [ + protected array $skippedTests = [ 'testGeocodeQuery' => 'Wrong cords', 'testReverseQueryWithNoResults' => 'Has Result', ]; - protected $testAddress = true; + protected bool $testAddress = true; - protected $testReverse = true; + protected bool $testReverse = true; - protected $testIpv4 = false; + protected bool $testIpv4 = false; - protected $testIpv6 = false; + protected bool $testIpv6 = false; protected function createProvider(ClientInterface $httpClient) { return new Yandex($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { return ''; } From 6a19f915cd5f1ac5ad8f47a118fd5ce186d1172e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 20:33:07 +0200 Subject: [PATCH 21/26] Update AlgoliaPlacesTest --- src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php b/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php index c4be0cc18..a7924f5f2 100644 --- a/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php +++ b/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php @@ -18,6 +18,7 @@ use Geocoder\Query\GeocodeQuery; use Geocoder\Provider\AlgoliaPlaces\AlgoliaPlaces; use Http\Client\Curl\Client as HttplugClient; +use Psr\Http\Client\ClientInterface; /** * @author Sébastien Barré @@ -31,10 +32,8 @@ protected function getCacheDir() /** * Get a real HTTP client. If a cache dir is set to a path it will use cached responses. - * - * @return HttplugClient|CachedResponseClient */ - protected function getHttpClient($apiKey = null, $appCode = null) + protected function getHttpClient($apiKey = null, $appCode = null): ClientInterface { if (null !== $cacheDir = $this->getCacheDir()) { return new CachedResponseClient(new HttplugClient(), $cacheDir, $apiKey, $appCode); From 807bf4c01e0e8921d3e6941ee770d8918f6c0c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 20:45:10 +0200 Subject: [PATCH 22/26] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a9dca9983..4e41c7043 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "cache/array-adapter": "^1.0", "cache/simple-cache-bridge": "^1.0", "cache/void-adapter": "^1.0", - "geocoder-php/provider-integration-tests": "^1.0", + "geocoder-php/provider-integration-tests": "^1.6.2", "geoip2/geoip2": "~2.0", "nyholm/nsa": "^1.1", "nyholm/psr7": "^1.0", From 0bf5e0fb9f75100716c903ad1ed77e69cee113fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 9 Jul 2023 20:51:07 +0200 Subject: [PATCH 23/26] Update RequestInterface vs. getParsedResponse() --- src/Provider/AlgoliaPlaces/AlgoliaPlaces.php | 2 +- src/Provider/FreeGeoIp/FreeGeoIp.php | 2 ++ src/Provider/Nominatim/Nominatim.php | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php b/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php index 366ceedaf..6cc7653f5 100644 --- a/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php +++ b/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php @@ -75,7 +75,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection $this->query = $query; $request = $this->getRequest(self::ENDPOINT_URL_SSL); - $jsonParsed = AbstractHttpProvider::getParsedResponse($request); + $jsonParsed = $this->getParsedResponse($request); $jsonResponse = json_decode($jsonParsed, true); if (is_null($jsonResponse)) { diff --git a/src/Provider/FreeGeoIp/FreeGeoIp.php b/src/Provider/FreeGeoIp/FreeGeoIp.php index da93ceef8..6a0d86526 100644 --- a/src/Provider/FreeGeoIp/FreeGeoIp.php +++ b/src/Provider/FreeGeoIp/FreeGeoIp.php @@ -21,6 +21,7 @@ use Geocoder\Http\Provider\AbstractHttpProvider; use Geocoder\Provider\Provider; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestInterface; /** * @author William Durand @@ -61,6 +62,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection $request = $this->getRequest(sprintf($this->baseUrl, $address)); if (null !== $query->getLocale()) { + /** @var RequestInterface $request */ $request = $request->withHeader('Accept-Language', $query->getLocale()); } diff --git a/src/Provider/Nominatim/Nominatim.php b/src/Provider/Nominatim/Nominatim.php index f0c09ce70..2bd995c09 100644 --- a/src/Provider/Nominatim/Nominatim.php +++ b/src/Provider/Nominatim/Nominatim.php @@ -25,6 +25,7 @@ use Geocoder\Provider\Provider; use Geocoder\Provider\Nominatim\Model\NominatimAddress; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestInterface; /** * @author Niklas Närhinen @@ -285,9 +286,11 @@ private function executeQuery(string $url, string $locale = null): string } $request = $this->getRequest($url); + /** @var RequestInterface $request */ $request = $request->withHeader('User-Agent', $this->userAgent); if (!empty($this->referer)) { + /** @var RequestInterface $request */ $request = $request->withHeader('Referer', $this->referer); } From 3ad7f18bca65a616362c0d13f7fe1be1ea88b42c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Mon, 10 Jul 2023 09:21:39 +0200 Subject: [PATCH 24/26] Update src/Plugin/PluginProvider.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomas Norkūnas --- src/Plugin/PluginProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/PluginProvider.php b/src/Plugin/PluginProvider.php index 7dc3bbd7f..c29dedda6 100644 --- a/src/Plugin/PluginProvider.php +++ b/src/Plugin/PluginProvider.php @@ -49,7 +49,7 @@ class PluginProvider implements Provider /** * @param Provider $provider * @param Plugin[] $plugins - * @param array $options + * @param array{max_restarts: int<0, max>} $options */ public function __construct(Provider $provider, array $plugins = [], array $options = []) { From 0bcbc76f81746626972e85f53b6199bf94daa4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Mon, 10 Jul 2023 10:21:09 +0200 Subject: [PATCH 25/26] Update src/Plugin/PluginProvider.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomas Norkūnas --- src/Plugin/PluginProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/PluginProvider.php b/src/Plugin/PluginProvider.php index c29dedda6..50f376cef 100644 --- a/src/Plugin/PluginProvider.php +++ b/src/Plugin/PluginProvider.php @@ -49,7 +49,7 @@ class PluginProvider implements Provider /** * @param Provider $provider * @param Plugin[] $plugins - * @param array{max_restarts: int<0, max>} $options + * @param array{max_restarts?: int<0, max>} $options */ public function __construct(Provider $provider, array $plugins = [], array $options = []) { From b3ce75f5759678df5535726c4daf5920d979dec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sun, 16 Jul 2023 16:31:18 +0200 Subject: [PATCH 26/26] Use PHPStan baseline instead of ignore See https://phpstan.org/user-guide/baseline --- phpstan-baseline.neon | 61 +++++++++++++++++++ phpstan.neon | 2 + src/Common/ProviderAggregator.php | 2 +- src/Provider/Chain/Tests/ChainTest.php | 4 +- .../GeoIP2/Tests/GeoIP2AdapterTest.php | 8 +-- .../IP2LocationBinary/IP2LocationBinary.php | 4 +- .../Tests/IntegrationTest.php | 2 +- src/Provider/MaxMindBinary/MaxMindBinary.php | 26 ++++---- 8 files changed, 86 insertions(+), 23 deletions(-) create mode 100644 phpstan-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 000000000..92658952e --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,61 @@ +parameters: + ignoreErrors: + - + message: "#^Static method Geocoder\\\\ProviderAggregator\\:\\:getProvider\\(\\) is unused\\.$#" + count: 1 + path: src/Common/ProviderAggregator.php + + - + message: "#^Parameter \\#1 \\$locations of class Geocoder\\\\Model\\\\AddressCollection constructor expects array\\, array\\ given\\.$#" + count: 2 + path: src/Provider/Chain/Tests/ChainTest.php + + - + message: "#^Parameter \\#1 \\$geoIpProvider of class Geocoder\\\\Provider\\\\GeoIP2\\\\GeoIP2Adapter constructor expects GeoIp2\\\\ProviderInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#" + count: 4 + path: src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php + + - + message: "#^Access to constant ALL on an unknown class IP2Location\\\\Database\\.$#" + count: 1 + path: src/Provider/IP2LocationBinary/IP2LocationBinary.php + + - + message: "#^Call to method lookup\\(\\) on an unknown class IP2Location\\\\Database\\.$#" + count: 1 + path: src/Provider/IP2LocationBinary/IP2LocationBinary.php + + - + message: "#^Instantiated class IP2Location\\\\Database not found\\.$#" + count: 1 + path: src/Provider/IP2LocationBinary/IP2LocationBinary.php + + - + message: "#^Access to constant FILE_IO on an unknown class IP2Location\\\\Database\\.$#" + count: 1 + path: src/Provider/IP2LocationBinary/Tests/IntegrationTest.php + + - + message: "#^Access to property \\$[a-zA-Z_]+ on an unknown class GeoIpRecord\\.$#" + count: 10 + path: src/Provider/MaxMindBinary/MaxMindBinary.php + + - + message: "#^Class GeoIpRecord not found\\.$#" + count: 1 + path: src/Provider/MaxMindBinary/MaxMindBinary.php + + - + message: "#^Constant GEOIP_STANDARD not found\\.$#" + count: 1 + path: src/Provider/MaxMindBinary/MaxMindBinary.php + + - + message: "#^Function GeoIP_record_by_addr not found\\.$#" + count: 1 + path: src/Provider/MaxMindBinary/MaxMindBinary.php + + - + message: "#^Function geoip_(open|close) not found\\.$#" + count: 2 + path: src/Provider/MaxMindBinary/MaxMindBinary.php diff --git a/phpstan.neon b/phpstan.neon index 807cbf8d4..d7c0221a4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,5 @@ +includes: + - phpstan-baseline.neon parameters: level: 5 paths: diff --git a/src/Common/ProviderAggregator.php b/src/Common/ProviderAggregator.php index c442bd53d..ae7a78a83 100644 --- a/src/Common/ProviderAggregator.php +++ b/src/Common/ProviderAggregator.php @@ -166,7 +166,7 @@ public function getProviders(): array * * @throws ProviderNotRegistered */ - private static function getProvider($query, array $providers, Provider $currentProvider = null): Provider // @phpstan-ignore-line + private static function getProvider($query, array $providers, Provider $currentProvider = null): Provider { if (null !== $currentProvider) { return $currentProvider; diff --git a/src/Provider/Chain/Tests/ChainTest.php b/src/Provider/Chain/Tests/ChainTest.php index 2fb147dae..de37d7c9e 100644 --- a/src/Provider/Chain/Tests/ChainTest.php +++ b/src/Provider/Chain/Tests/ChainTest.php @@ -50,7 +50,7 @@ public function testReverse() })); $mockTwo = $this->getMockBuilder('Geocoder\\Provider\\Provider')->getMock(); - $result = new AddressCollection(['foo' => 'bar']); // @phpstan-ignore-line + $result = new AddressCollection(['foo' => 'bar']); $mockTwo->expects($this->once()) ->method('reverseQuery') ->will($this->returnValue($result)); @@ -71,7 +71,7 @@ public function testGeocode() })); $mockTwo = $this->getMockBuilder('Geocoder\\Provider\\Provider')->getMock(); - $result = new AddressCollection(['foo' => 'bar']); // @phpstan-ignore-line + $result = new AddressCollection(['foo' => 'bar']); $mockTwo->expects($this->once()) ->method('geocodeQuery') ->with($query) diff --git a/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php b/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php index c462667d7..a15f85085 100644 --- a/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php +++ b/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php @@ -41,7 +41,7 @@ public static function setUpBeforeClass(): void public function setUp(): void { - $this->adapter = new GeoIP2Adapter($this->getGeoIP2ProviderMock()); // @phpstan-ignore-line + $this->adapter = new GeoIP2Adapter($this->getGeoIP2ProviderMock()); } public function testGetName() @@ -90,7 +90,7 @@ public function testIpAddressIsPassedCorrectToReader($geoIp2Model) $this->getGeoIP2ModelMock($geoIp2Model) )); - $adapter = new GeoIP2Adapter($geoIp2Provider, $geoIp2Model); // @phpstan-ignore-line + $adapter = new GeoIP2Adapter($geoIp2Provider, $geoIp2Model); $adapter->getContent('file://geoip?127.0.0.1'); } @@ -99,7 +99,7 @@ public function testNotSupportedGeoIP2ModelLeadsToException() $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('Model "unsupported_model" is not available.'); - new GeoIP2Adapter($this->getGeoIP2ProviderMock(), 'unsupported_model'); // @phpstan-ignore-line + new GeoIP2Adapter($this->getGeoIP2ProviderMock(), 'unsupported_model'); } public function testReaderResponseIsJsonEncoded() @@ -112,7 +112,7 @@ public function testReaderResponseIsJsonEncoded() ->method('city') ->will($this->returnValue($cityModel)); - $adapter = new GeoIP2Adapter($geoIp2Provider); // @phpstan-ignore-line + $adapter = new GeoIP2Adapter($geoIp2Provider); $result = $adapter->getContent('file://database?127.0.0.1'); $this->assertJson($result); diff --git a/src/Provider/IP2LocationBinary/IP2LocationBinary.php b/src/Provider/IP2LocationBinary/IP2LocationBinary.php index 695795b3b..64f6ef2ed 100644 --- a/src/Provider/IP2LocationBinary/IP2LocationBinary.php +++ b/src/Provider/IP2LocationBinary/IP2LocationBinary.php @@ -70,8 +70,8 @@ public function geocodeQuery(GeocodeQuery $query): Collection throw new UnsupportedOperation('The IP2LocationBinary provider does not support street addresses.'); } - $db = new \IP2Location\Database($this->binFile, $this->openFlag); // @phpstan-ignore-line - $records = $db->lookup($address, \IP2Location\Database::ALL); // @phpstan-ignore-line + $db = new \IP2Location\Database($this->binFile, $this->openFlag); + $records = $db->lookup($address, \IP2Location\Database::ALL); if (false === $records) { return new AddressCollection([]); diff --git a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php index 356f0dfc6..503a17c3e 100644 --- a/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php +++ b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php @@ -43,7 +43,7 @@ public static function setUpBeforeClass(): void protected function createProvider(ClientInterface $httpClient) { // Download this BIN database from https://lite.ip2location.com/database/ip-country-region-city-latitude-longitude-zipcode - return new IP2LocationBinary(__DIR__.'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN', \IP2Location\Database::FILE_IO); // @phpstan-ignore-line + return new IP2LocationBinary(__DIR__.'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN', \IP2Location\Database::FILE_IO); } protected function getCacheDir(): string diff --git a/src/Provider/MaxMindBinary/MaxMindBinary.php b/src/Provider/MaxMindBinary/MaxMindBinary.php index 09452b384..5cc9d41d2 100644 --- a/src/Provider/MaxMindBinary/MaxMindBinary.php +++ b/src/Provider/MaxMindBinary/MaxMindBinary.php @@ -61,7 +61,7 @@ public function __construct(string $datFile, int $openFlag = null) } $this->datFile = $datFile; - $this->openFlag = null === $openFlag ? GEOIP_STANDARD : $openFlag; // @phpstan-ignore-line + $this->openFlag = null === $openFlag ? GEOIP_STANDARD : $openFlag; } /** @@ -79,31 +79,31 @@ public function geocodeQuery(GeocodeQuery $query): Collection throw new UnsupportedOperation('The MaxMindBinary provider does not support IPv6 addresses.'); } - $geoIp = geoip_open($this->datFile, $this->openFlag); // @phpstan-ignore-line - $geoIpRecord = GeoIP_record_by_addr($geoIp, $address); // @phpstan-ignore-line + $geoIp = geoip_open($this->datFile, $this->openFlag); + $geoIpRecord = GeoIP_record_by_addr($geoIp, $address); - geoip_close($geoIp); // @phpstan-ignore-line + geoip_close($geoIp); - if (false === $geoIpRecord instanceof \GeoIpRecord) { // @phpstan-ignore-line + if (false === $geoIpRecord instanceof \GeoIpRecord) { return new AddressCollection([]); } $adminLevels = []; - if ($geoIpRecord->region) { // @phpstan-ignore-line - $adminLevels[] = ['name' => $geoIpRecord->region, 'level' => 1]; // @phpstan-ignore-line + if ($geoIpRecord->region) { + $adminLevels[] = ['name' => $geoIpRecord->region, 'level' => 1]; } return new AddressCollection([ Address::createFromArray([ 'providedBy' => $this->getName(), - 'countryCode' => $geoIpRecord->country_code, // @phpstan-ignore-line - 'country' => null === $geoIpRecord->country_name ? null : utf8_encode($geoIpRecord->country_name), // @phpstan-ignore-line + 'countryCode' => $geoIpRecord->country_code, + 'country' => null === $geoIpRecord->country_name ? null : utf8_encode($geoIpRecord->country_name), 'adminLevels' => $adminLevels, - 'locality' => null === $geoIpRecord->city ? null : utf8_encode($geoIpRecord->city), // @phpstan-ignore-line - 'latitude' => $geoIpRecord->latitude, // @phpstan-ignore-line - 'longitude' => $geoIpRecord->longitude, // @phpstan-ignore-line - 'postalCode' => $geoIpRecord->postal_code, // @phpstan-ignore-line + 'locality' => null === $geoIpRecord->city ? null : utf8_encode($geoIpRecord->city), + 'latitude' => $geoIpRecord->latitude, + 'longitude' => $geoIpRecord->longitude, + 'postalCode' => $geoIpRecord->postal_code, ]), ]); }