diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 95cb522e7..28a2059a5 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 analyse \ No newline at end of file diff --git a/composer.json b/composer.json index 4b9d413c6..4e41c7043 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,36 +25,36 @@ "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", "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", "php-http/curl-client": "^2.2", "php-http/message": "^1.0", "php-http/mock-client": "^1.0", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^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\\": [ @@ -68,9 +68,20 @@ "Geocoder\\Tests\\": "tests/" } }, - "minimum-stability": "dev", - "prefer-stable": true, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true, + "php-http/discovery": true + }, + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, "scripts": { + "analyse": "vendor/bin/phpstan analyse", "test": "vendor/bin/phpunit" } } 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 new file mode 100644 index 000000000..d7c0221a4 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +includes: + - phpstan-baseline.neon +parameters: + level: 5 + paths: + - src + excludePaths: + - **/vendor/** + treatPhpDocTypesAsCertain: false diff --git a/src/Common/Model/Address.php b/src/Common/Model/Address.php index a0ff0e33e..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, diff --git a/src/Common/ProviderAggregator.php b/src/Common/ProviderAggregator.php index c3e269403..ae7a78a83 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); } 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/Common/Tests/TimedGeocoderTest.php b/src/Common/Tests/TimedGeocoderTest.php index c46a82fba..318ef4082 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/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/Plugin/PluginProvider.php b/src/Plugin/PluginProvider.php index c138cbd95..50f376cef 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{max_restarts?: int<0, max>} $options */ public function __construct(Provider $provider, array $plugins = [], array $options = []) { diff --git a/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php b/src/Provider/AlgoliaPlaces/AlgoliaPlaces.php index 1a6d9e6a7..6cc7653f5 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; } @@ -79,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/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php b/src/Provider/AlgoliaPlaces/Tests/AlgoliaPlacesTest.php index 6041a245b..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 HttpClient */ - 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); 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 0d7885cfb..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,13 +34,13 @@ 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 null; + return ''; } } 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/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/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/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/Cache/Tests/ProviderCacheTest.php b/src/Provider/Cache/Tests/ProviderCacheTest.php index 9b1c3559a..cec3f6ec1 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/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/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/FreeGeoIp/Tests/IntegrationTest.php b/src/Provider/FreeGeoIp/Tests/IntegrationTest.php index e85852211..1abe7dfb2 100644 --- a/src/Provider/FreeGeoIp/Tests/IntegrationTest.php +++ b/src/Provider/FreeGeoIp/Tests/IntegrationTest.php @@ -21,22 +21,22 @@ */ 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 null; + return ''; } } diff --git a/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php b/src/Provider/GeoIP2/Tests/GeoIP2AdapterTest.php index 19272f02f..a15f85085 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() { @@ -131,9 +132,9 @@ protected function getGeoIP2ProviderMock() } /** - * @param int $geoIP2Model (e.g. GeoIP2Adapter::GEOIP2_MODEL_CITY, ...) + * @param string $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..aee420354 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/GeoIP2/Tests/IntegrationTest.php b/src/Provider/GeoIP2/Tests/IntegrationTest.php index e0cac8642..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,13 +38,13 @@ 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 null; + return ''; } } 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/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/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/GeoPlugin/Tests/IntegrationTest.php b/src/Provider/GeoPlugin/Tests/IntegrationTest.php index 312ef851b..b7507faa5 100644 --- a/src/Provider/GeoPlugin/Tests/IntegrationTest.php +++ b/src/Provider/GeoPlugin/Tests/IntegrationTest.php @@ -21,22 +21,22 @@ */ 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, $this->getApiKey()); + return new GeoPlugin($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { - return null; + 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 fa5fc111c..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,13 +41,13 @@ 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 null; + return ''; } } diff --git a/src/Provider/Geonames/Model/CountryInfo.php b/src/Provider/Geonames/Model/CountryInfo.php index b62065543..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(string $population = null): self + public function withPopulation($population = null): self { $new = clone $this; - $new->population = null === $population ? null : (int) $population; + $new->population = null === $population ? null : (is_string($population) ? (int) $population : $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/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/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/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/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/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/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/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/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/AbstractHostIp.php b/src/Provider/HostIp/AbstractHostIp.php index c4cf4890b..2adcda05f 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); } @@ -71,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']; } /** @@ -85,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/HostIp/HostIp.php b/src/Provider/HostIp/HostIp.php index 1c0fc85ed..aeed62a42 100644 --- a/src/Provider/HostIp/HostIp.php +++ b/src/Provider/HostIp/HostIp.php @@ -34,10 +34,16 @@ public function getName(): string return 'host_ip'; } + /** + * @return string + */ + public function getEndpointURL(): string + { + return self::ENDPOINT_URL; + } + /** * @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 edf64e5fc..4b7efe2eb 100644 --- a/src/Provider/HostIp/HostIpXml.php +++ b/src/Provider/HostIp/HostIpXml.php @@ -34,10 +34,16 @@ public function getName(): string return 'host_ip_xml'; } + /** + * @return string + */ + public function getEndpointURL(): string + { + return self::ENDPOINT_URL; + } + /** * @param string $url - * - * @return Collection */ protected function executeQuery(string $url): AddressCollection { 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/HostIp/Tests/IntegrationTest.php b/src/Provider/HostIp/Tests/IntegrationTest.php index 530ca08f0..cb6da672e 100644 --- a/src/Provider/HostIp/Tests/IntegrationTest.php +++ b/src/Provider/HostIp/Tests/IntegrationTest.php @@ -21,28 +21,28 @@ */ 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 null; + return ''; } } 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/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/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/IP2LocationBinary/Tests/IntegrationTest.php b/src/Provider/IP2LocationBinary/Tests/IntegrationTest.php index ec64b0a4a..503a17c3e 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,13 +46,13 @@ protected function createProvider(ClientInterface $httpClient) return new IP2LocationBinary(__DIR__.'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN', \IP2Location\Database::FILE_IO); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { - return null; + return ''; } } 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/IpInfo/Tests/IntegrationTest.php b/src/Provider/IpInfo/Tests/IntegrationTest.php index fc7a1d064..1a8d59462 100644 --- a/src/Provider/IpInfo/Tests/IntegrationTest.php +++ b/src/Provider/IpInfo/Tests/IntegrationTest.php @@ -21,23 +21,24 @@ */ 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/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/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/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/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/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/Ipstack/Tests/IpstackTest.php b/src/Provider/Ipstack/Tests/IpstackTest.php index 6ebeecd18..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; @@ -91,8 +92,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 +109,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/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/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/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/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/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/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/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/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/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/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/Mapbox/Tests/MapboxTest.php b/src/Provider/Mapbox/Tests/MapboxTest.php index 9c1097309..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,11 +100,11 @@ 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->assertEquals(43.73125, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(7.41974, $result->getCoordinates()->getLongitude(), '', 0.001); + $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()); $this->assertEquals('Principato di Monaco', $result->getCountry()->getName()); $this->assertEquals('place.4899176537126140', $result->getId()); @@ -128,11 +129,11 @@ 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->assertEquals(37.77572, $result->getCoordinates()->getLatitude(), '', 0.001); - $this->assertEquals(-122.41362, $result->getCoordinates()->getLongitude(), '', 0.001); + $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()); $this->assertEquals(149, $result->getStreetNumber()); $this->assertEquals('9th Street', $result->getStreetName()); @@ -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()); @@ -215,8 +216,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/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/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/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/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/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/MaxMind/Tests/MaxMindTest.php b/src/Provider/MaxMind/Tests/MaxMindTest.php index 8824dcbe3..1e0d69793 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()); @@ -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()); @@ -304,8 +303,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 +338,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 +373,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/Tests/IntegrationTest.php b/src/Provider/MaxMindBinary/Tests/IntegrationTest.php index c13986e49..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,13 +49,13 @@ 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 null; + return ''; } } 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/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); } diff --git a/src/Provider/Nominatim/Tests/IntegrationTest.php b/src/Provider/Nominatim/Tests/IntegrationTest.php index 7ee37b8e7..0fb074917 100644 --- a/src/Provider/Nominatim/Tests/IntegrationTest.php +++ b/src/Provider/Nominatim/Tests/IntegrationTest.php @@ -19,30 +19,30 @@ */ 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 null; + return ''; } } 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/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/Pelias.php b/src/Provider/Pelias/Pelias.php index 8eb2da718..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); } @@ -123,8 +117,6 @@ public function getName(): string /** * @param $url - * - * @return Collection */ protected function executeQuery(string $url): AddressCollection { diff --git a/src/Provider/Pelias/Tests/IntegrationTest.php b/src/Provider/Pelias/Tests/IntegrationTest.php index fd905fa7a..01592f670 100644 --- a/src/Provider/Pelias/Tests/IntegrationTest.php +++ b/src/Provider/Pelias/Tests/IntegrationTest.php @@ -21,29 +21,29 @@ */ 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 null; + return ''; } } diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index f805bbbb7..3ab2b15d8 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([]); @@ -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/Photon/Tests/IntegrationTest.php b/src/Provider/Photon/Tests/IntegrationTest.php index f6aa43fdb..cc9200e16 100644 --- a/src/Provider/Photon/Tests/IntegrationTest.php +++ b/src/Provider/Photon/Tests/IntegrationTest.php @@ -19,31 +19,31 @@ */ 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.', ]; protected function createProvider(ClientInterface $httpClient) { - return Photon::withKomootServer($httpClient, 'Geocoder PHP/Photon Provider/Integration Test'); + return Photon::withKomootServer($httpClient); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - protected function getApiKey() + protected function getApiKey(): string { - return null; + return ''; } } 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()); 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(); 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/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/IntegrationTest.php b/src/Provider/Yandex/Tests/IntegrationTest.php index 2d88327db..80f69c850 100644 --- a/src/Provider/Yandex/Tests/IntegrationTest.php +++ b/src/Provider/Yandex/Tests/IntegrationTest.php @@ -21,31 +21,31 @@ */ 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 null; + return ''; } } 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());