Skip to content

Commit

Permalink
Add PHP Coding Standards Fixer in CI (#1196)
Browse files Browse the repository at this point in the history
* Update composer.json

* Update .gitignore

* Update php.yml

* Apply PHPCSFixer fixes

* Switch to php-cs-fixer/shim

* Create .php-cs-fixer.dist.php
  • Loading branch information
jbelien committed Jul 21, 2023
1 parent fc063aa commit 52ca351
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
22 changes: 5 additions & 17 deletions GeoIP2.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
namespace Geocoder\Provider\GeoIP2;

use Geocoder\Collection;
use Geocoder\Exception\InvalidCredentials;
use Geocoder\Exception\QuotaExceeded;
use Geocoder\Exception\UnsupportedOperation;
use Geocoder\Model\Address;
use Geocoder\Model\AddressCollection;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Geocoder\Provider\AbstractProvider;
use Geocoder\Provider\Provider;
use Geocoder\Exception\UnsupportedOperation;
use Geocoder\Exception\InvalidCredentials;
use Geocoder\Exception\QuotaExceeded;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use GeoIp2\Exception\AddressNotFoundException;
use GeoIp2\Exception\AuthenticationException;
use GeoIp2\Exception\OutOfQueriesException;
Expand All @@ -41,9 +41,6 @@ public function __construct(GeoIP2Adapter $adapter)
$this->adapter = $adapter;
}

/**
* {@inheritdoc}
*/
public function geocodeQuery(GeocodeQuery $query): Collection
{
$address = $query->getText();
Expand Down Expand Up @@ -89,25 +86,16 @@ public function geocodeQuery(GeocodeQuery $query): Collection
]);
}

/**
* {@inheritdoc}
*/
public function reverseQuery(ReverseQuery $query): Collection
{
throw new UnsupportedOperation('The GeoIP2 provider is not able to do reverse geocoding.');
}

/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'geoip2';
}

/**
* @param string $address
*/
private function executeQuery(string $address): string
{
$uri = sprintf('file://geoip?%s', $address);
Expand Down
17 changes: 4 additions & 13 deletions GeoIP2Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

namespace Geocoder\Provider\GeoIP2;

use GeoIp2\ProviderInterface;
use Geocoder\Exception\InvalidArgument;
use Geocoder\Exception\UnsupportedOperation;
use GeoIp2\ProviderInterface;

/**
* @author Jens Wiese <[email protected]>
Expand All @@ -24,9 +24,9 @@ class GeoIP2Adapter
/**
* GeoIP2 models (e.g. city or country).
*/
const GEOIP2_MODEL_CITY = 'city';
public const GEOIP2_MODEL_CITY = 'city';

const GEOIP2_MODEL_COUNTRY = 'country';
public const GEOIP2_MODEL_COUNTRY = 'country';

/**
* @var ProviderInterface
Expand All @@ -39,8 +39,7 @@ class GeoIP2Adapter
protected $geoIP2Model;

/**
* @param \GeoIp2\ProviderInterface $geoIpProvider
* @param string $geoIP2Model (e.g. self::GEOIP2_MODEL_CITY)
* @param string $geoIP2Model (e.g. self::GEOIP2_MODEL_CITY)
*/
public function __construct(ProviderInterface $geoIpProvider, $geoIP2Model = self::GEOIP2_MODEL_CITY)
{
Expand All @@ -57,8 +56,6 @@ public function __construct(ProviderInterface $geoIpProvider, $geoIP2Model = sel
* Returns the content fetched from a given resource.
*
* @param string $url (e.g. file://database?127.0.0.1)
*
* @return string
*/
public function getContent(string $url): string
{
Expand All @@ -81,8 +78,6 @@ public function getContent(string $url): string

/**
* Returns the name of the Adapter.
*
* @return string
*/
public function getName(): string
{
Expand All @@ -91,10 +86,6 @@ public function getName(): string

/**
* Returns whether method is supported by GeoIP2.
*
* @param string $method
*
* @return bool
*/
protected function isSupportedGeoIP2Model(string $method): bool
{
Expand Down
7 changes: 2 additions & 5 deletions Tests/GeoIP2AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace Geocoder\Provider\GeoIP2\Tests;

use Geocoder\Provider\GeoIP2\GeoIP2Adapter;
use RuntimeException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -28,14 +27,12 @@ class GeoIP2AdapterTest extends TestCase
protected $adapter;

/**
* {@inheritdoc}
*
* @throws RuntimeException
* @throws \RuntimeException
*/
public static function setUpBeforeClass(): void
{
if (false === class_exists('\GeoIp2\Database\Reader')) {
throw new RuntimeException("The maxmind's lib 'geoip2/geoip2' is required to run this test.");
throw new \RuntimeException("The maxmind's lib 'geoip2/geoip2' is required to run this test.");
}
}

Expand Down
15 changes: 4 additions & 11 deletions Tests/GeoIP2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
namespace Geocoder\Provider\GeoIP2\Tests;

use Geocoder\Collection;
use Geocoder\Exception\InvalidCredentials;
use Geocoder\Exception\QuotaExceeded;
use Geocoder\IntegrationTest\BaseTestCase;
use Geocoder\Location;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Geocoder\Provider\GeoIP2\GeoIP2;
use Geocoder\Provider\GeoIP2\GeoIP2Adapter;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use GeoIp2\Database\Reader;
use GeoIp2\Exception\AuthenticationException;
use GeoIp2\Exception\OutOfQueriesException;
use Geocoder\Exception\InvalidCredentials;
use Geocoder\Exception\QuotaExceeded;
use PHPUnit\Framework\MockObject\MockObject;

/**
Expand Down Expand Up @@ -164,8 +164,6 @@ public static function provideDataForRetrievingGeodata()
* @dataProvider provideDataForRetrievingGeodata
*
* @param string $address
* @param mixed $adapterResponse
* @param mixed $expectedGeodata
*/
public function testRetrievingGeodata($address, $adapterResponse, $expectedGeodata)
{
Expand Down Expand Up @@ -235,9 +233,6 @@ public function testGeoIp2Encoding()

/**
* @dataProvider provideDataForTestingExceptions
*
* @param \Exception $original
* @param string $replacementClass
*/
public function testExceptionConversion(\Exception $original, string $replacementClass)
{
Expand All @@ -260,8 +255,6 @@ public static function provideDataForTestingExceptions(): array
}

/**
* @param mixed $returnValue
*
* @return GeoIP2Adapter&MockObject
*/
private function getGeoIP2AdapterMock($returnValue = '')
Expand Down

0 comments on commit 52ca351

Please sign in to comment.