Skip to content

Commit

Permalink
Enable PHPStan Level 6 (#1194)
Browse files Browse the repository at this point in the history
* Update phpstan.neon

* Update YandexTest.php

* Update TomTomTest.php

* Update PickPointTest.php

* Update PickPoint.php

* Update PhotonTest.php

* Update PeliasTest.php

* Update OpenRouteServiceTest.php

* Update OpenCageTest.php

* Update OpenCage.php

* Update NominatimTest.php

* Update MaxMindBinaryTest.php

* Update MaxMindTest.php

* [WIP] Apply PHPStan fixes

* Apply PHPCSFixer fixes

* [WIP] Apply PHPStan fixes

* [WIP] Apply PHPStan fixes

* Revert "[WIP] Apply PHPStan fixes"

This reverts commit 734c5c52fbcba4bc12cbda07b58d902a79d47891.

* [WIP] Apply PHPStan fixes

* [WIP] Apply PHPStan fixes

* Update phpstan-baseline.neon
  • Loading branch information
jbelien authored Jul 31, 2023
1 parent db35a21 commit b893ab4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
24 changes: 21 additions & 3 deletions OpenCage.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ private function executeQuery(string $url, string $locale = null): AddressCollec
return new AddressCollection($results);
}

private function parseCoordinates(AddressBuilder $builder, array $location)
/**
* @param array<string, mixed> $location
*/
private function parseCoordinates(AddressBuilder $builder, array $location): void
{
$builder->setCoordinates($location['geometry']['lat'], $location['geometry']['lng']);

Expand Down Expand Up @@ -189,7 +192,10 @@ private function parseCoordinates(AddressBuilder $builder, array $location)
);
}

private function parseAdminsLevels(AddressBuilder $builder, array $components)
/**
* @param array<string, mixed> $components
*/
private function parseAdminsLevels(AddressBuilder $builder, array $components): void
{
if (isset($components['state'])) {
$stateCode = isset($components['state_code']) ? $components['state_code'] : null;
Expand All @@ -201,7 +207,10 @@ private function parseAdminsLevels(AddressBuilder $builder, array $components)
}
}

private function parseCountry(AddressBuilder $builder, array $components)
/**
* @param array<string, mixed> $components
*/
private function parseCountry(AddressBuilder $builder, array $components): void
{
if (isset($components['country'])) {
$builder->setCountry($components['country']);
Expand All @@ -213,6 +222,8 @@ private function parseCountry(AddressBuilder $builder, array $components)
}

/**
* @param array<string, mixed> $components
*
* @return string|null
*/
protected function guessLocality(array $components)
Expand All @@ -223,6 +234,8 @@ protected function guessLocality(array $components)
}

/**
* @param array<string, mixed> $components
*
* @return string|null
*/
protected function guessStreetName(array $components)
Expand All @@ -233,6 +246,8 @@ protected function guessStreetName(array $components)
}

/**
* @param array<string, mixed> $components
*
* @return string|null
*/
protected function guessSubLocality(array $components)
Expand All @@ -243,6 +258,9 @@ protected function guessSubLocality(array $components)
}

/**
* @param array<string, mixed> $components
* @param string[] $keys
*
* @return string|null
*/
protected function guessBestComponent(array $components, array $keys)
Expand Down
36 changes: 18 additions & 18 deletions Tests/OpenCageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
*/
class OpenCageTest extends BaseTestCase
{
protected function getCacheDir()
protected function getCacheDir(): string
{
return __DIR__.'/.cached_responses';
}

public function testGetName()
public function testGetName(): void
{
$provider = new OpenCage($this->getMockedHttpClient(), 'api_key');
$this->assertEquals('opencage', $provider->getName());
}

public function testSslSchema()
public function testSslSchema(): void
{
$provider = new OpenCage($this->getMockedHttpClient('{}'), 'api_key');
$result = $provider->geocodeQuery(GeocodeQuery::create('foobar'));
Expand All @@ -46,7 +46,7 @@ public function testSslSchema()
$this->assertEquals(0, $result->count());
}

public function testGeocodeWithRealAddress()
public function testGeocodeWithRealAddress(): void
{
if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
$this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testGeocodeWithRealAddress()
$this->assertEquals('10 Avenue Gambetta, 75020 Paris, France', $result->getFormattedAddress());
}

public function testReverseWithRealCoordinates()
public function testReverseWithRealCoordinates(): void
{
if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
$this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testReverseWithRealCoordinates()
$this->assertEquals('Saint Nicholas Arcades, Lancaster Gate, Lancaster LA1 1LZ, United Kingdom', $result->getFormattedAddress());
}

public function testReverseWithVillage()
public function testReverseWithVillage(): void
{
if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
$this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
Expand All @@ -142,7 +142,7 @@ public function testReverseWithVillage()
$this->assertEquals('Bray-et-Lû', $result->getLocality());
}

public function testGeocodeWithCity()
public function testGeocodeWithCity(): void
{
if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
$this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
Expand Down Expand Up @@ -187,7 +187,7 @@ public function testGeocodeWithCity()
$this->assertEquals('United States of America', $result->getCountry()->getName());
}

public function testGeocodeWithCityDistrict()
public function testGeocodeWithCityDistrict(): void
{
if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
$this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
Expand Down Expand Up @@ -216,7 +216,7 @@ public function testGeocodeWithCityDistrict()
$this->assertEquals('Europe/Berlin', $result->getTimezone());
}

public function testGeocodeWithLocale()
public function testGeocodeWithLocale(): void
{
if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
$this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
Expand All @@ -239,7 +239,7 @@ public function testGeocodeWithLocale()
$this->assertEquals('GB', $result->getCountry()->getCode());
}

public function testAmbiguousResultCountryCode()
public function testAmbiguousResultCountryCode(): void
{
$provider = new OpenCage($this->getHttpClient($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
$results = $provider->geocodeQuery(GeocodeQuery::create('Gera-Ost Gera 07546 DE'));
Expand All @@ -257,7 +257,7 @@ public function testAmbiguousResultCountryCode()
$this->assertEquals('DE', $result->getCountry()->getCode());
}

public function testAmbiguousResultBounds()
public function testAmbiguousResultBounds(): void
{
$provider = new OpenCage($this->getHttpClient($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
$results = $provider->geocodeQuery(GeocodeQuery::create('Gera-Ost Gera 07546 DE'));
Expand All @@ -276,7 +276,7 @@ public function testAmbiguousResultBounds()
$this->assertEquals('DE', $result->getCountry()->getCode());
}

public function testAmbiguousResultProximity()
public function testAmbiguousResultProximity(): void
{
$provider = new OpenCage($this->getHttpClient($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
$results = $provider->geocodeQuery(GeocodeQuery::create('odessa'));
Expand All @@ -292,7 +292,7 @@ public function testAmbiguousResultProximity()
$this->assertEquals('US', $result->getCountry()->getCode());
}

public function testGeocodeQuotaExceeded()
public function testGeocodeQuotaExceeded(): void
{
$this->expectException(\Geocoder\Exception\QuotaExceeded::class);
$this->expectExceptionMessage('Valid request but quota exceeded.');
Expand All @@ -311,7 +311,7 @@ public function testGeocodeQuotaExceeded()
$provider->geocodeQuery(GeocodeQuery::create('New York'));
}

public function testGeocodeInvalidApiKey()
public function testGeocodeInvalidApiKey(): void
{
$this->expectException(\Geocoder\Exception\InvalidCredentials::class);
$this->expectExceptionMessage('Invalid or missing api key.');
Expand All @@ -330,7 +330,7 @@ public function testGeocodeInvalidApiKey()
$provider->geocodeQuery(GeocodeQuery::create('New York'));
}

public function testGeocodeWithLocalhostIPv4()
public function testGeocodeWithLocalhostIPv4(): void
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The OpenCage provider does not support IP addresses, only street addresses.');
Expand All @@ -339,7 +339,7 @@ public function testGeocodeWithLocalhostIPv4()
$provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
}

public function testGeocodeWithLocalhostIPv6()
public function testGeocodeWithLocalhostIPv6(): void
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The OpenCage provider does not support IP addresses, only street addresses.');
Expand All @@ -348,7 +348,7 @@ public function testGeocodeWithLocalhostIPv6()
$provider->geocodeQuery(GeocodeQuery::create('::1'));
}

public function testGeocodeWithRealIPv4()
public function testGeocodeWithRealIPv4(): void
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The OpenCage provider does not support IP addresses, only street addresses.');
Expand All @@ -357,7 +357,7 @@ public function testGeocodeWithRealIPv4()
$provider->geocodeQuery(GeocodeQuery::create('74.200.247.59'));
}

public function testGeocodeWithRealIPv6()
public function testGeocodeWithRealIPv6(): void
{
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
$this->expectExceptionMessage('The OpenCage provider does not support IP addresses, only street addresses.');
Expand Down

0 comments on commit b893ab4

Please sign in to comment.