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 9f9a9b4 commit 33a88fc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
6 changes: 4 additions & 2 deletions GoogleMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private function fetchUrl(string $url, string $locale = null, int $limit, string
* @param string $type Component type
* @param object $values The component values
*/
private function updateAddressComponent(AddressBuilder $builder, string $type, $values)
private function updateAddressComponent(AddressBuilder $builder, string $type, $values): void
{
switch ($type) {
case 'postal_code':
Expand Down Expand Up @@ -385,6 +385,8 @@ private function signQuery(string $query): string

/**
* Serialize the component query parameter.
*
* @param array<string, string> $components
*/
private function serializeComponents(array $components): string
{
Expand Down Expand Up @@ -439,7 +441,7 @@ private function validateResponse(string $url, $content)
*
* @param \Stdclass $result
*/
private function parseCoordinates(AddressBuilder $builder, $result)
private function parseCoordinates(AddressBuilder $builder, $result): void
{
$coordinates = $result->geometry->location;
$builder->setCoordinates($coordinates->lat, $coordinates->lng);
Expand Down
9 changes: 8 additions & 1 deletion Model/GoogleAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class GoogleAddress extends Address
private $locationType;

/**
* @var array
* @var string[]
*/
private $resultType = [];

Expand Down Expand Up @@ -161,12 +161,17 @@ public function getLocationType()
return $this->locationType;
}

/**
* @return string[]
*/
public function getResultType(): array
{
return $this->resultType;
}

/**
* @param string[] $resultType
*
* @return GoogleAddress
*/
public function withResultType(array $resultType)
Expand Down Expand Up @@ -473,6 +478,8 @@ public function getSubLocalityLevels()
}

/**
* @param array<array{level: int, name: string, code: string}> $subLocalityLevel
*
* @return $this
*/
public function withSubLocalityLevels(array $subLocalityLevel)
Expand Down
66 changes: 33 additions & 33 deletions Tests/GoogleMapsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GoogleMapsTest extends BaseTestCase
*/
private $testAPIKey = 'fake_key';

protected function getCacheDir()
protected function getCacheDir(): ?string
{
if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) {
return __DIR__.'/.cached_responses';
Expand All @@ -38,13 +38,13 @@ protected function getCacheDir()
return null;
}

public function testGetName()
public function testGetName(): void
{
$provider = new GoogleMaps($this->getMockedHttpClient(), null, 'mock-api-key');
$this->assertEquals('google_maps', $provider->getName());
}

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

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

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

public function testGeocodeWithQuotaExceeded()
public function testGeocodeWithQuotaExceeded(): void
{
$this->expectException(\Geocoder\Exception\QuotaExceeded::class);
$this->expectExceptionMessage('Daily quota exceeded https://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France');
Expand All @@ -80,7 +80,7 @@ public function testGeocodeWithQuotaExceeded()
$provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France'));
}

public function testGeocodeWithRealAddress()
public function testGeocodeWithRealAddress(): void
{
if (!isset($_SERVER['GOOGLE_GEOCODING_KEY'])) {
$this->markTestSkipped('You need to configure the GOOGLE_GEOCODING_KEY value in phpunit.xml');
Expand Down Expand Up @@ -119,7 +119,7 @@ public function testGeocodeWithRealAddress()
$this->assertNull($result->getPostalCodeSuffix());
}

public function testGeocodeBoundsWithRealAddressForNonRooftopLocation()
public function testGeocodeBoundsWithRealAddressForNonRooftopLocation(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('Paris, France'));
Expand All @@ -139,15 +139,15 @@ public function testGeocodeBoundsWithRealAddressForNonRooftopLocation()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testReverse()
public function testReverse(): void
{
$this->expectException(\Geocoder\Exception\InvalidServerResponse::class);

$provider = new GoogleMaps($this->getMockedHttpClient(), null, 'mock-api-key');
$provider->reverseQuery(ReverseQuery::fromCoordinates(1, 2));
}

public function testReverseWithRealCoordinates()
public function testReverseWithRealCoordinates(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8631507, 2.388911));
Expand All @@ -171,7 +171,7 @@ public function testReverseWithRealCoordinates()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testReverseWithRealCoordinatesAndLocale()
public function testReverseWithRealCoordinatesAndLocale(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8631507, 2.388911)->withLocale('fr-FR'));
Expand All @@ -195,7 +195,7 @@ public function testReverseWithRealCoordinatesAndLocale()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeWithCityDistrict()
public function testGeocodeWithCityDistrict(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany'));
Expand All @@ -210,7 +210,7 @@ public function testGeocodeWithCityDistrict()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeWithInvalidApiKey()
public function testGeocodeWithInvalidApiKey(): void
{
$this->expectException(\Geocoder\Exception\InvalidCredentials::class);
$this->expectExceptionMessage('API key is invalid https://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France');
Expand All @@ -219,7 +219,7 @@ public function testGeocodeWithInvalidApiKey()
$provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France'));
}

public function testGeocodeWithRealValidApiKey()
public function testGeocodeWithRealValidApiKey(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('Columbia University'));
Expand All @@ -237,7 +237,7 @@ public function testGeocodeWithRealValidApiKey()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeWithComponentFiltering()
public function testGeocodeWithComponentFiltering(): void
{
$provider = $this->getGoogleMapsProvider();
$query = GeocodeQuery::create('Sankt Petri')->withData('components', [
Expand All @@ -259,7 +259,7 @@ public function testGeocodeWithComponentFiltering()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testCorrectlySerializesComponents()
public function testCorrectlySerializesComponents(): void
{
$uri = '';

Expand Down Expand Up @@ -292,7 +292,7 @@ function (RequestInterface $request) use (&$uri) {
);
}

public function testCorrectlySetsComponents()
public function testCorrectlySetsComponents(): void
{
$uri = '';

Expand Down Expand Up @@ -322,7 +322,7 @@ function (RequestInterface $request) use (&$uri) {
);
}

public function testGeocodeWithRealInvalidApiKey()
public function testGeocodeWithRealInvalidApiKey(): void
{
$this->expectException(\Geocoder\Exception\InvalidCredentials::class);
$this->expectExceptionMessage('API key is invalid https://maps.googleapis.com/maps/api/geocode/json?address=Columbia&key=fake_key');
Expand All @@ -331,7 +331,7 @@ public function testGeocodeWithRealInvalidApiKey()
$provider->geocodeQuery(GeocodeQuery::create('Columbia'));
}

public function testGeocodePostalTown()
public function testGeocodePostalTown(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('CF37, United Kingdom'));
Expand All @@ -346,7 +346,7 @@ public function testGeocodePostalTown()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testBusinessQueryWithoutPrivateKey()
public function testBusinessQueryWithoutPrivateKey(): void
{
$uri = '';

Expand All @@ -366,7 +366,7 @@ function (RequestInterface $request) use (&$uri) {
$this->assertEquals('https://maps.googleapis.com/maps/api/geocode/json?address=blah&client=foo', $uri);
}

public function testBusinessQueryWithPrivateKey()
public function testBusinessQueryWithPrivateKey(): void
{
$uri = '';

Expand All @@ -390,7 +390,7 @@ function (RequestInterface $request) use (&$uri) {
);
}

public function testBusinessQueryWithPrivateKeyAndChannel()
public function testBusinessQueryWithPrivateKeyAndChannel(): void
{
$uri = '';

Expand All @@ -417,23 +417,23 @@ function (RequestInterface $request) use (&$uri) {
);
}

public function testGeocodeWithInvalidClientIdAndKey()
public function testGeocodeWithInvalidClientIdAndKey(): void
{
$this->expectException(\Geocoder\Exception\InvalidCredentials::class);

$provider = GoogleMaps::business($this->getHttpClient(), 'foo', 'bogus');
$provider->geocodeQuery(GeocodeQuery::create('Columbia University'));
}

public function testGeocodeWithInvalidClientIdAndKeyNoSsl()
public function testGeocodeWithInvalidClientIdAndKeyNoSsl(): void
{
$this->expectException(\Geocoder\Exception\InvalidCredentials::class);

$provider = GoogleMaps::business($this->getHttpClient(), 'foo', 'bogus');
$provider->geocodeQuery(GeocodeQuery::create('Columbia University'));
}

public function testGeocodeWithSupremise()
public function testGeocodeWithSupremise(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('2123 W Mineral Ave Apt 61,Littleton,CO8 0120'));
Expand All @@ -448,7 +448,7 @@ public function testGeocodeWithSupremise()
$this->assertEquals(true, $result->isPartialMatch()); // 2123 W Mineral Ave #61, Littleton, CO 80120, USA
}

public function testGeocodeWithNaturalFeatureComponent()
public function testGeocodeWithNaturalFeatureComponent(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('Durmitor Nacionalni Park'));
Expand All @@ -467,7 +467,7 @@ public function testGeocodeWithNaturalFeatureComponent()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeWithAirportComponent()
public function testGeocodeWithAirportComponent(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('Brisbane Airport'));
Expand All @@ -484,7 +484,7 @@ public function testGeocodeWithAirportComponent()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeWithPremiseComponent()
public function testGeocodeWithPremiseComponent(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('1125 17th St, Denver, CO 80202'));
Expand All @@ -502,7 +502,7 @@ public function testGeocodeWithPremiseComponent()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeWithColloquialAreaComponent()
public function testGeocodeWithColloquialAreaComponent(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('darwin'));
Expand All @@ -517,7 +517,7 @@ public function testGeocodeWithColloquialAreaComponent()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testReverseWithSubLocalityLevels()
public function testReverseWithSubLocalityLevels(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(36.2745084, 136.9003169));
Expand All @@ -533,7 +533,7 @@ public function testReverseWithSubLocalityLevels()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeWithPostalCodeSuffixComponent()
public function testGeocodeWithPostalCodeSuffixComponent(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('900 S Oak Park Ave, Oak Park, IL 60304'));
Expand All @@ -549,7 +549,7 @@ public function testGeocodeWithPostalCodeSuffixComponent()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeBoundsWithRealAddressWithViewportOnly()
public function testGeocodeBoundsWithRealAddressWithViewportOnly(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('Sibbe, Netherlands'));
Expand All @@ -568,7 +568,7 @@ public function testGeocodeBoundsWithRealAddressWithViewportOnly()
$this->assertEquals(false, $result->isPartialMatch());
}

public function testGeocodeDuplicateSubLocalityLevel()
public function testGeocodeDuplicateSubLocalityLevel(): void
{
$provider = $this->getGoogleMapsProvider();
$results = $provider->geocodeQuery(GeocodeQuery::create('Rue de Pont-A-Migneloux, 6210 Wayaux, Belgique'));
Expand Down

0 comments on commit 33a88fc

Please sign in to comment.