Skip to content

Commit

Permalink
Add PHPStan in CI (#1193)
Browse files Browse the repository at this point in the history
* Add PHPStan

* Update php.yml

* Update composer.json

* Fix PHPStan level 0

* Fix PHPStan level 1

* Update phpstan.neon

* Fix PHPStan level 2

* Update composer.json

* Fix PHPStan level 3

* Fix tests

* Fix PHPStan level 4

* Update src/Common/Tests/TimedGeocoderTest.php

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>

* Update src/Provider/Cache/Tests/ProviderCacheTest.php

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>

* Update src/Provider/Cache/Tests/ProviderCacheTest.php

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>

* Update src/Provider/GeoIP2/Tests/GeoIP2Test.php

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>

* Fix PHPStan level 5

* Normalize composer.json

* Rename analyse script

* Update composer.json

* Update IntegrationTest

* Update AlgoliaPlacesTest

* Update composer.json

* Update RequestInterface vs. getParsedResponse()

* Update src/Plugin/PluginProvider.php

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>

* Update src/Plugin/PluginProvider.php

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>

* Use PHPStan baseline instead of ignore

See https://phpstan.org/user-guide/baseline

---------

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>
  • Loading branch information
jbelien and norkunas authored Jul 16, 2023
1 parent 98f74a5 commit 4d6c79d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
10 changes: 2 additions & 8 deletions Mapbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ final class Mapbox extends AbstractHttpProvider implements Provider

const DEFAULT_TYPE = self::TYPE_ADDRESS;

/**
* @var ClientInterface
*/
private $client;

/**
* @var string
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
29 changes: 15 additions & 14 deletions Tests/MapboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit 4d6c79d

Please sign in to comment.