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 authored Jul 21, 2023
1 parent 4d6c79d commit a178a35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 69 deletions.
75 changes: 25 additions & 50 deletions Mapbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,99 +16,99 @@
use Geocoder\Exception\InvalidArgument;
use Geocoder\Exception\InvalidServerResponse;
use Geocoder\Exception\UnsupportedOperation;
use Geocoder\Model\AddressCollection;
use Geocoder\Model\AddressBuilder;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Geocoder\Http\Provider\AbstractHttpProvider;
use Geocoder\Model\AddressBuilder;
use Geocoder\Model\AddressCollection;
use Geocoder\Provider\Mapbox\Model\MapboxAddress;
use Geocoder\Provider\Provider;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Psr\Http\Client\ClientInterface;

final class Mapbox extends AbstractHttpProvider implements Provider
{
/**
* @var string
*/
const GEOCODE_ENDPOINT_URL_SSL = 'https://api.mapbox.com/geocoding/v5/%s/%s.json';
public const GEOCODE_ENDPOINT_URL_SSL = 'https://api.mapbox.com/geocoding/v5/%s/%s.json';

/**
* @var string
*/
const REVERSE_ENDPOINT_URL_SSL = 'https://api.mapbox.com/geocoding/v5/%s/%F,%F.json';
public const REVERSE_ENDPOINT_URL_SSL = 'https://api.mapbox.com/geocoding/v5/%s/%F,%F.json';

/**
* @var string
*/
const GEOCODING_MODE_PLACES = 'mapbox.places';
public const GEOCODING_MODE_PLACES = 'mapbox.places';

/**
* @var string
*/
const GEOCODING_MODE_PLACES_PERMANENT = 'mapbox.places-permanent';
public const GEOCODING_MODE_PLACES_PERMANENT = 'mapbox.places-permanent';

/**
* @var array
*/
const GEOCODING_MODES = [
public const GEOCODING_MODES = [
self::GEOCODING_MODE_PLACES,
self::GEOCODING_MODE_PLACES_PERMANENT,
];

/**
* @var string
*/
const TYPE_COUNTRY = 'country';
public const TYPE_COUNTRY = 'country';

/**
* @var string
*/
const TYPE_REGION = 'region';
public const TYPE_REGION = 'region';

/**
* @var string
*/
const TYPE_POSTCODE = 'postcode';
public const TYPE_POSTCODE = 'postcode';

/**
* @var string
*/
const TYPE_DISTRICT = 'district';
public const TYPE_DISTRICT = 'district';

/**
* @var string
*/
const TYPE_PLACE = 'place';
public const TYPE_PLACE = 'place';

/**
* @var string
*/
const TYPE_LOCALITY = 'locality';
public const TYPE_LOCALITY = 'locality';

/**
* @var string
*/
const TYPE_NEIGHBORHOOD = 'neighborhood';
public const TYPE_NEIGHBORHOOD = 'neighborhood';

/**
* @var string
*/
const TYPE_ADDRESS = 'address';
public const TYPE_ADDRESS = 'address';

/**
* @var string
*/
const TYPE_POI = 'poi';
public const TYPE_POI = 'poi';

/**
* @var string
*/
const TYPE_POI_LANDMARK = 'poi.landmark';
public const TYPE_POI_LANDMARK = 'poi.landmark';

/**
* @var array
*/
const TYPES = [
public const TYPES = [
self::TYPE_COUNTRY,
self::TYPE_REGION,
self::TYPE_POSTCODE,
Expand All @@ -121,7 +121,7 @@ final class Mapbox extends AbstractHttpProvider implements Provider
self::TYPE_POI_LANDMARK,
];

const DEFAULT_TYPE = self::TYPE_ADDRESS;
public const DEFAULT_TYPE = self::TYPE_ADDRESS;

/**
* @var string
Expand All @@ -139,10 +139,8 @@ final class Mapbox extends AbstractHttpProvider implements Provider
private $geocodingMode;

/**
* @param ClientInterface $client An HTTP adapter
* @param string $accessToken Your Mapbox access token
* @param string|null $country
* @param string $geocodingMode
* @param ClientInterface $client An HTTP adapter
* @param string $accessToken Your Mapbox access token
*/
public function __construct(
ClientInterface $client,
Expand Down Expand Up @@ -223,20 +221,12 @@ public function reverseQuery(ReverseQuery $query): Collection
return $this->fetchUrl($url, $query->getLimit(), $query->getLocale(), $query->getData('country', $this->country));
}

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

/**
* @param string $url
* @param int $limit
* @param string|null $locale
* @param string|null $country
*
* @return string query with extra params
*/
private function buildQuery(string $url, int $limit, string $locale = null, string $country = null): string
Expand All @@ -253,14 +243,6 @@ private function buildQuery(string $url, int $limit, string $locale = null, stri
return $url.$separator.http_build_query($parameters);
}

/**
* @param string $url
* @param int $limit
* @param string|null $locale
* @param string|null $country
*
* @return AddressCollection
*/
private function fetchUrl(string $url, int $limit, string $locale = null, string $country = null): AddressCollection
{
$url = $this->buildQuery($url, $limit, $locale, $country);
Expand Down Expand Up @@ -323,9 +305,8 @@ private function fetchUrl(string $url, int $limit, string $locale = null, string
/**
* Update current resultSet with given key/value.
*
* @param AddressBuilder $builder
* @param string $type Component type
* @param array $value The component value
* @param string $type Component type
* @param array $value The component value
*/
private function updateAddressComponent(AddressBuilder $builder, string $type, array $value)
{
Expand Down Expand Up @@ -378,10 +359,7 @@ private function updateAddressComponent(AddressBuilder $builder, string $type, a
/**
* Decode the response content and validate it to make sure it does not have any errors.
*
* @param string $url
* @param string $content
*
* @return array
*/
private function validateResponse(string $url, $content): array
{
Expand All @@ -397,9 +375,6 @@ private function validateResponse(string $url, $content): array

/**
* Parse coordinats and bounds.
*
* @param AddressBuilder $builder
* @param array $result
*/
private function parseCoordinates(AddressBuilder $builder, array $result)
{
Expand Down
15 changes: 0 additions & 15 deletions Model/MapboxAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ final class MapboxAddress extends Address
private $neighborhood;

/**
* @param string|null $id
*
* @return MapboxAddress
*/
public function withId(string $id = null)
Expand Down Expand Up @@ -78,8 +76,6 @@ public function getStreetName()
}

/**
* @param string|null $streetName
*
* @return MapboxAddress
*/
public function withStreetName(string $streetName = null)
Expand All @@ -99,8 +95,6 @@ public function getStreetNumber()
}

/**
* @param string|null $streetNumber
*
* @return MapboxAddress
*/
public function withStreetNumber(string $streetNumber = null)
Expand All @@ -111,17 +105,12 @@ public function withStreetNumber(string $streetNumber = null)
return $new;
}

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

/**
* @param array $resultType
*
* @return MapboxAddress
*/
public function withResultType(array $resultType)
Expand All @@ -141,8 +130,6 @@ public function getFormattedAddress()
}

/**
* @param string|null $formattedAddress
*
* @return MapboxAddress
*/
public function withFormattedAddress(string $formattedAddress = null)
Expand All @@ -162,8 +149,6 @@ public function getNeighborhood()
}

/**
* @param string|null $neighborhood
*
* @return MapboxAddress
*/
public function withNeighborhood(string $neighborhood = null)
Expand Down
6 changes: 2 additions & 4 deletions Tests/MapboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
namespace Geocoder\Provider\Mapbox\Tests;

use Geocoder\IntegrationTest\BaseTestCase;
use Geocoder\Location;
use Geocoder\Model\Address;
use Geocoder\Model\AddressCollection;
use Geocoder\Model\Bounds;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Geocoder\Provider\Mapbox\Mapbox;
use Geocoder\Provider\Mapbox\Model\MapboxAddress;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;

class MapboxTest extends BaseTestCase
{
Expand Down

0 comments on commit a178a35

Please sign in to comment.