diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml new file mode 100644 index 00000000..ccc5cc28 --- /dev/null +++ b/.github/workflows/component.yml @@ -0,0 +1,33 @@ +name: Component + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + name: PHP ${{ matrix.php-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-version: ['8.2', '8.3', '8.4'] + steps: + - uses: actions/checkout@v4 + - name: Use PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: curl + - name: Validate composer.json and composer.lock + run: composer validate --strict + - name: Install dependencies + run: composer update --prefer-stable --prefer-dist --no-progress + - name: Run test suite + run: composer run-script test-ci + - name: Upload Coverage report + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 96ffe283..00000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: php -sudo: false - -php: 7.0 - -install: - - composer update --prefer-stable --prefer-dist - -script: - - composer test-ci - -after_success: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml diff --git a/Assert.php b/Assert.php index 489c8b92..c9363209 100644 --- a/Assert.php +++ b/Assert.php @@ -16,11 +16,7 @@ class Assert { - /** - * @param float $value - * @param string $message - */ - public static function latitude($value, string $message = '') + public static function latitude(mixed $value, string $message = ''): void { self::float($value, $message); if ($value < -90 || $value > 90) { @@ -28,11 +24,7 @@ public static function latitude($value, string $message = '') } } - /** - * @param float $value - * @param string $message - */ - public static function longitude($value, string $message = '') + public static function longitude(mixed $value, string $message = ''): void { self::float($value, $message); if ($value < -180 || $value > 180) { @@ -40,32 +32,22 @@ public static function longitude($value, string $message = '') } } - /** - * @param mixed $value - * @param string $message - */ - public static function notNull($value, string $message = '') + public static function notNull(mixed $value, string $message = ''): void { if (null === $value) { throw new InvalidArgument(sprintf($message ?: 'Value cannot be null')); } } - private static function typeToString($value): string + private static function typeToString(mixed $value): string { return is_object($value) ? get_class($value) : gettype($value); } - /** - * @param $value - * @param $message - */ - private static function float($value, string $message) + private static function float(mixed $value, string $message): void { if (!is_float($value)) { - throw new InvalidArgument( - sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value)) - ); + throw new InvalidArgument(sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value))); } } } diff --git a/CHANGELOG.md b/CHANGELOG.md index c5501ff3..a9fe2493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,27 +2,131 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 5.0.0 + +- Drop support for PHP < 8.2 +- Added return values on classes and interfaces + +## 4.6.0 + +### Removed + +- Drop support for PHP 7.3 + +## 4.5.0 + +### Added + +- Add support for PHP 8.1 + +### Changed + +- Replace `empty()` by more strict checks + +## 4.4.0 + +### Added + +- Add support for PHP 8.0 + +### Removed + +- Drop support for PHP 7.2 + +### Changed + +- Upgrade PHPUnit to version 9 + +## 4.3.0 + +### Removed + +- Drop support for PHP < 7.2 + +## 4.2.2 + +### Changed + +- GeoJson dumper implements Dumper +- Excpetion interface extends Throwable + +### Fixed + +- Fix building ProviderNotRegistered exception message + +## 4.2.1 + +### Fixed + +- Bug in `AddressBuilder` where same expression is compare twice + +## 4.2.0 + +### Added + +- Add `Coordinates::toArray` + +### Fixed + +- Bug in `StatefulGeocoder` where different locale or bounds did not have any effect. + +## 4.1.0 + +### Changed + +- Make sure a `Country` never will be empty of data. + +## 4.0.0 + +No changes since Beta 5. + +## 4.0.0 - Beta 5 + +### Changed + +- `GeocodeQuery::withTest` was renamed to `GeocodeQuery::withText` + +## 4.0.0 - Beta 4 + +### Added + +- Add `GeocodeQuery::withText` and `ReverseQuery::withCoordinates`. +- Create interface for GeocodeQuery and ReverseQuery + +## 4.0.0 - Beta 3 + +### Added + +- The constructor of `ProvierAggregator` will accept a callable that can decide what providers should be used for a specific query. + +### Changed + +- `ProvierAggregator::getProvider` is now private +- `ProvierAggregator::limit` was removed +- `ProvierAggregator::getLimit` was removed +- `ProvierAggregator::__constructor` changed the order of the parameters. +- `ProvierAggregator` is not final. + ## 4.0.0 - Beta 2 ### Added -- PHP7 type hints. +- PHP7 type hints. - `AbstractArrayDumper` and `AbstractDumper` - `LogicException` and `OutOfBounds` - `GeocodeQuery::__toString` and `ReverseQuery::__toString` ### Changed -- All Dumpers are now final. -- All Exceptions are now final. -- `AddressCollection` is now final. -- `ProviderAggregator` is now final. -- `StatefulGeocoder` is now final. -- `TimedGeocoder` is now final. +- All Dumpers are now final. +- All Exceptions are now final. +- `AddressCollection` is now final. +- `ProviderAggregator` is now final. +- `StatefulGeocoder` is now final. +- `TimedGeocoder` is now final. - `ProviderAggregator::getName()` will return "provider_aggregator" - `TimedGeocoder::getName()` will return "timed_geocoder" - ## 4.0.0 - Beta1 -First release of this library. +First release of this library. diff --git a/Collection.php b/Collection.php index 64f4ec99..e6ccc86b 100644 --- a/Collection.php +++ b/Collection.php @@ -20,34 +20,26 @@ * * @author William Durand * @author Tobias Nyholm + * + * @template-extends \IteratorAggregate */ interface Collection extends \IteratorAggregate, \Countable { /** - * @return Location - * * @throws CollectionIsEmpty */ public function first(): Location; - /** - * @return bool - */ public function isEmpty(): bool; /** * @return Location[] */ - public function slice(int $offset, int $length = null); + public function slice(int $offset, ?int $length = null); - /** - * @return bool - */ public function has(int $index): bool; /** - * @return Location - * * @throws OutOfBounds */ public function get(int $index): Location; diff --git a/Dumper/AbstractArrayDumper.php b/Dumper/AbstractArrayDumper.php index b3226f1f..e7873cc4 100644 --- a/Dumper/AbstractArrayDumper.php +++ b/Dumper/AbstractArrayDumper.php @@ -20,9 +20,7 @@ abstract class AbstractArrayDumper { /** - * @param Location $location - * - * @return array + * @return array{type: 'Feature', geometry: array{type: 'Point', coordinates: array{0: float, 1: float}}, properties: array, bounds?: array{south: float, west: float, north: float, east: float}} */ protected function getArray(Location $location): array { @@ -36,7 +34,7 @@ protected function getArray(Location $location): array $properties['bounds'] ); - if (0 === count($properties)) { + if ([] === $properties) { $properties = null; } diff --git a/Dumper/AbstractDumper.php b/Dumper/AbstractDumper.php index b46025f3..9f0bba5e 100644 --- a/Dumper/AbstractDumper.php +++ b/Dumper/AbstractDumper.php @@ -16,11 +16,6 @@ abstract class AbstractDumper { - /** - * @param Location $address - * - * @return string - */ protected function formatName(Location $address): string { $name = []; diff --git a/Dumper/Dumper.php b/Dumper/Dumper.php index 44529252..18589fa9 100644 --- a/Dumper/Dumper.php +++ b/Dumper/Dumper.php @@ -22,10 +22,6 @@ interface Dumper /** * Dumps an `Location` object as a string representation of * the implemented format. - * - * @param Location $location - * - * @return mixed */ - public function dump(Location $location); + public function dump(Location $location): mixed; } diff --git a/Dumper/GeoArray.php b/Dumper/GeoArray.php index f9926862..495cf7be 100644 --- a/Dumper/GeoArray.php +++ b/Dumper/GeoArray.php @@ -20,7 +20,7 @@ final class GeoArray extends AbstractArrayDumper implements Dumper { /** - * {@inheritdoc} + * @return array{type: 'Feature', geometry: array{type: 'Point', coordinates: array{0: float, 1: float}}, properties: array, bounds?: array{south: float, west: float, north: float, east: float}} */ public function dump(Location $location): array { diff --git a/Dumper/GeoJson.php b/Dumper/GeoJson.php index c992be8f..e0a09ad9 100644 --- a/Dumper/GeoJson.php +++ b/Dumper/GeoJson.php @@ -17,11 +17,8 @@ /** * @author Jan Sorgalla */ -final class GeoJson extends AbstractArrayDumper +final class GeoJson extends AbstractArrayDumper implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { return json_encode($this->getArray($location)); diff --git a/Dumper/Gpx.php b/Dumper/Gpx.php index 935a9dad..df26074d 100644 --- a/Dumper/Gpx.php +++ b/Dumper/Gpx.php @@ -20,11 +20,6 @@ */ final class Gpx extends AbstractDumper implements Dumper { - /** - * @param Location $location - * - * @return string - */ public function dump(Location $location): string { $gpx = sprintf(<<<'GPX' @@ -37,14 +32,14 @@ public function dump(Location $location): string xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> GPX - , Geocoder::VERSION); + , Geocoder::VERSION); if (null !== $bounds = $location->getBounds()) { $gpx .= sprintf(<<<'GPX' GPX - , $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth()); + , $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth()); } $lat = null; @@ -61,7 +56,7 @@ public function dump(Location $location): string GPX - , $lat, $lon, $this->formatName($location)); + , $lat, $lon, $this->formatName($location)); $gpx .= <<<'GPX' diff --git a/Dumper/Kml.php b/Dumper/Kml.php index 9182c25c..35e35ad6 100644 --- a/Dumper/Kml.php +++ b/Dumper/Kml.php @@ -19,9 +19,6 @@ */ final class Kml extends AbstractDumper implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { $name = $this->formatName($location); diff --git a/Dumper/Wkb.php b/Dumper/Wkb.php index 9cbf2145..d602ef40 100644 --- a/Dumper/Wkb.php +++ b/Dumper/Wkb.php @@ -19,9 +19,6 @@ */ final class Wkb implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { $lat = null; diff --git a/Dumper/Wkt.php b/Dumper/Wkt.php index e07331f2..85ccc99d 100644 --- a/Dumper/Wkt.php +++ b/Dumper/Wkt.php @@ -19,9 +19,6 @@ */ final class Wkt implements Dumper { - /** - * {@inheritdoc} - */ public function dump(Location $location): string { $lat = null; diff --git a/Exception/Exception.php b/Exception/Exception.php index 1600333c..8d905481 100644 --- a/Exception/Exception.php +++ b/Exception/Exception.php @@ -15,6 +15,6 @@ /** * @author William Durand */ -interface Exception +interface Exception extends \Throwable { } diff --git a/Exception/FunctionNotFound.php b/Exception/FunctionNotFound.php index a4ba0f60..78b02b95 100644 --- a/Exception/FunctionNotFound.php +++ b/Exception/FunctionNotFound.php @@ -18,12 +18,12 @@ final class FunctionNotFound extends \RuntimeException implements Exception { /** - * @param string $functionName * @param string $description */ public function __construct(string $functionName, $description = null) { - parent::__construct(sprintf('The function "%s" cannot be found. %s', + parent::__construct(sprintf( + 'The function "%s" cannot be found. %s', $functionName, null !== $description ? sprintf(' %s', $description) : '' )); diff --git a/Exception/InvalidServerResponse.php b/Exception/InvalidServerResponse.php index 19f38e0b..a74cfd50 100644 --- a/Exception/InvalidServerResponse.php +++ b/Exception/InvalidServerResponse.php @@ -19,23 +19,12 @@ */ final class InvalidServerResponse extends \RuntimeException implements Exception { - /** - * @param string $query - * @param int $code - * - * @return InvalidServerResponse - */ - public static function create(string $query, int $code = 0): InvalidServerResponse + public static function create(string $query, int $code = 0): self { return new self(sprintf('The geocoder server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query)); } - /** - * @param string $query - * - * @return InvalidServerResponse - */ - public static function emptyResponse(string $query): InvalidServerResponse + public static function emptyResponse(string $query): self { return new self(sprintf('The geocoder server returned an empty response for query "%s".', $query)); } diff --git a/Exception/ProviderNotRegistered.php b/Exception/ProviderNotRegistered.php index eb479afa..9bd57f8c 100644 --- a/Exception/ProviderNotRegistered.php +++ b/Exception/ProviderNotRegistered.php @@ -18,10 +18,9 @@ final class ProviderNotRegistered extends \RuntimeException implements Exception { /** - * @param string $providerName - * @param array $registeredProviders + * @param string[] $registeredProviders */ - public static function create(string $providerName, array $registeredProviders = []) + public static function create(string $providerName, array $registeredProviders = []): self { return new self(sprintf( 'Provider "%s" is not registered, so you cannot use it. Did you forget to register it or made a typo?%s', @@ -30,7 +29,7 @@ public static function create(string $providerName, array $registeredProviders = )); } - public static function noProviderRegistered() + public static function noProviderRegistered(): self { return new self('No provider registered.'); } diff --git a/Formatter/StringFormatter.php b/Formatter/StringFormatter.php index 854c44e6..0acdb361 100644 --- a/Formatter/StringFormatter.php +++ b/Formatter/StringFormatter.php @@ -12,46 +12,46 @@ namespace Geocoder\Formatter; -use Geocoder\Model\AdminLevelCollection; use Geocoder\Location; +use Geocoder\Model\AdminLevelCollection; /** * @author William Durand */ final class StringFormatter { - const STREET_NUMBER = '%n'; + public const STREET_NUMBER = '%n'; - const STREET_NAME = '%S'; + public const STREET_NAME = '%S'; - const LOCALITY = '%L'; + public const LOCALITY = '%L'; - const POSTAL_CODE = '%z'; + public const POSTAL_CODE = '%z'; - const SUB_LOCALITY = '%D'; + public const SUB_LOCALITY = '%D'; - const ADMIN_LEVEL = '%A'; + public const ADMIN_LEVEL = '%A'; - const ADMIN_LEVEL_CODE = '%a'; + public const ADMIN_LEVEL_CODE = '%a'; - const COUNTRY = '%C'; + public const COUNTRY = '%C'; - const COUNTRY_CODE = '%c'; + public const COUNTRY_CODE = '%c'; - const TIMEZONE = '%T'; + public const TIMEZONE = '%T'; /** * Transform an `Address` instance into a string representation. - * - * @param Location $location - * @param string $format - * - * @return string */ public function format(Location $location, string $format): string { - if (null !== $code = $location->getCountry()->getCode()) { - $code = strtoupper($code); + $countryName = null; + $code = null; + if (null !== $country = $location->getCountry()) { + $countryName = $country->getName(); + if (null !== $code = $country->getCode()) { + $code = strtoupper($code); + } } $replace = [ @@ -60,7 +60,7 @@ public function format(Location $location, string $format): string self::LOCALITY => $location->getLocality(), self::POSTAL_CODE => $location->getPostalCode(), self::SUB_LOCALITY => $location->getSubLocality(), - self::COUNTRY => $location->getCountry()->getName(), + self::COUNTRY => $countryName, self::COUNTRY_CODE => $code, self::TIMEZONE => $location->getTimezone(), ]; diff --git a/Geocoder.php b/Geocoder.php index 85c825cc..528396a9 100644 --- a/Geocoder.php +++ b/Geocoder.php @@ -22,34 +22,26 @@ interface Geocoder extends Provider /** * Version of this package. */ - const MAJOR_VERSION = 4; - const VERSION = '4.0'; + public const MAJOR_VERSION = 4; + + public const VERSION = '4.0'; /** * The default result limit. */ - const DEFAULT_RESULT_LIMIT = 5; + public const DEFAULT_RESULT_LIMIT = 5; /** * Geocodes a given value. * - * @param string $value - * - * @return Collection - * - * @throws \Geocoder\Exception\Exception + * @throws Exception\Exception */ public function geocode(string $value): Collection; /** * Reverses geocode given latitude and longitude values. * - * @param float $latitude - * @param float $longitude - * - * @return Collection - * - * @throws \Geocoder\Exception\Exception + * @throws Exception\Exception */ public function reverse(float $latitude, float $longitude): Collection; } diff --git a/GeocoderTrait.php b/GeocoderTrait.php index 7d5949ec..2210ebf0 100644 --- a/GeocoderTrait.php +++ b/GeocoderTrait.php @@ -26,17 +26,11 @@ abstract public function geocodeQuery(GeocodeQuery $query): Collection; abstract public function reverseQuery(ReverseQuery $query): Collection; - /** - * {@inheritdoc} - */ public function geocode(string $value): Collection { return $this->geocodeQuery(GeocodeQuery::create($value)); } - /** - * {@inheritdoc} - */ public function reverse(float $latitude, float $longitude): Collection { return $this->reverseQuery(ReverseQuery::fromCoordinates($latitude, $longitude)); diff --git a/Location.php b/Location.php index 5d9b9e44..fc31f9c6 100644 --- a/Location.php +++ b/Location.php @@ -27,17 +27,13 @@ interface Location { /** * Will always return the coordinates value object. - * - * @return Coordinates|null */ - public function getCoordinates(); + public function getCoordinates(): ?Coordinates; /** * Returns the bounds value object. - * - * @return Bounds|null */ - public function getBounds(); + public function getBounds(): ?Bounds; /** * Returns the street number value. @@ -48,69 +44,53 @@ public function getStreetNumber(); /** * Returns the street name value. - * - * @return string|null */ - public function getStreetName(); + public function getStreetName(): ?string; /** * Returns the city or locality value. - * - * @return string|null */ - public function getLocality(); + public function getLocality(): ?string; /** * Returns the postal code or zipcode value. - * - * @return string|null */ - public function getPostalCode(); + public function getPostalCode(): ?string; /** * Returns the locality district, or * sublocality, or neighborhood. - * - * @return string|null */ - public function getSubLocality(); + public function getSubLocality(): ?string; /** * Returns the administrative levels. * * This method MUST NOT return null. - * - * @return AdminLevelCollection */ public function getAdminLevels(): AdminLevelCollection; /** * Returns the country value object. - * - * @return Country|null */ - public function getCountry(); + public function getCountry(): ?Country; /** * Returns the timezone for the Location. The timezone MUST be in the list of supported timezones. * * {@link http://php.net/manual/en/timezones.php} - * - * @return string|null */ - public function getTimezone(); + public function getTimezone(): ?string; /** * Returns an array with data indexed by name. * - * @return array + * @return array */ public function toArray(): array; /** * The name of the provider that created this Location. - * - * @return string */ public function getProvidedBy(): string; } diff --git a/Model/Address.php b/Model/Address.php index 544d199d..250384fd 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -74,31 +74,18 @@ class Address implements Location */ private $providedBy; - /** - * @param string $providedBy - * @param AdminLevelCollection $adminLevels - * @param Coordinates|null $coordinates - * @param Bounds|null $bounds - * @param string|null $streetNumber - * @param string|null $streetName - * @param string|null $postalCode - * @param string|null $locality - * @param string|null $subLocality - * @param Country|null $country - * @param string|null $timezone - */ - public function __construct( + final public function __construct( string $providedBy, AdminLevelCollection $adminLevels, - Coordinates $coordinates = null, - Bounds $bounds = null, - string $streetNumber = null, - string $streetName = null, - string $postalCode = null, - string $locality = null, - string $subLocality = null, - Country $country = null, - string $timezone = null + ?Coordinates $coordinates = null, + ?Bounds $bounds = null, + ?string $streetNumber = null, + ?string $streetName = null, + ?string $postalCode = null, + ?string $locality = null, + ?string $subLocality = null, + ?Country $country = null, + ?string $timezone = null, ) { $this->providedBy = $providedBy; $this->adminLevels = $adminLevels; @@ -113,90 +100,57 @@ public function __construct( $this->timezone = $timezone; } - /** - * @return string - */ public function getProvidedBy(): string { return $this->providedBy; } - /** - * {@inheritdoc} - */ - public function getCoordinates() + public function getCoordinates(): ?Coordinates { return $this->coordinates; } - /** - * {@inheritdoc} - */ - public function getBounds() + public function getBounds(): ?Bounds { return $this->bounds; } - /** - * {@inheritdoc} - */ - public function getStreetNumber() + public function getStreetNumber(): ?string { return $this->streetNumber; } - /** - * {@inheritdoc} - */ - public function getStreetName() + public function getStreetName(): ?string { return $this->streetName; } - /** - * {@inheritdoc} - */ - public function getLocality() + public function getLocality(): ?string { return $this->locality; } - /** - * {@inheritdoc} - */ - public function getPostalCode() + public function getPostalCode(): ?string { return $this->postalCode; } - /** - * {@inheritdoc} - */ - public function getSubLocality() + public function getSubLocality(): ?string { return $this->subLocality; } - /** - * {@inheritdoc} - */ public function getAdminLevels(): AdminLevelCollection { return $this->adminLevels; } - /** - * {@inheritdoc} - */ - public function getCountry() + public function getCountry(): ?Country { return $this->country; } - /** - * {@inheritdoc} - */ - public function getTimezone() + public function getTimezone(): ?string { return $this->timezone; } @@ -204,7 +158,7 @@ public function getTimezone() /** * Create an Address with an array. Useful for testing. * - * @param array $data + * @param array $data * * @return static */ @@ -235,12 +189,12 @@ public static function createFromArray(array $data) $adminLevels = []; foreach ($data['adminLevels'] as $adminLevel) { - if (empty($adminLevel['level'])) { + if (null === $adminLevel['level'] || 0 === $adminLevel['level']) { continue; } $name = $adminLevel['name'] ?? $adminLevel['code'] ?? null; - if (empty($name)) { + if (null === $name || '' === $name) { continue; } @@ -265,10 +219,7 @@ public static function createFromArray(array $data) $data['postalCode'], $data['locality'], $data['subLocality'], - new Country( - $data['country'], - $data['countryCode'] - ), + self::createCountry($data['country'], $data['countryCode']), $data['timezone'] ); } @@ -289,13 +240,24 @@ private static function createCoordinates($latitude, $longitude) } /** - * @param float $south - * @param float $west - * @param float $north + * @param string|null $name + * @param string|null $code * + * @return Country|null + */ + private static function createCountry($name, $code) + { + if (null === $name && null === $code) { + return null; + } + + return new Country($name, $code); + } + + /** * @return Bounds|null */ - private static function createBounds($south, $west, $north, $east) + private static function createBounds(?float $south, ?float $west, ?float $north, ?float $east) { if (null === $south || null === $west || null === $north || null === $east) { return null; @@ -304,9 +266,6 @@ private static function createBounds($south, $west, $north, $east) return new Bounds($south, $west, $north, $east); } - /** - * {@inheritdoc} - */ public function toArray(): array { $adminLevels = []; diff --git a/Model/AddressBuilder.php b/Model/AddressBuilder.php index 28301515..3534a2ea 100644 --- a/Model/AddressBuilder.php +++ b/Model/AddressBuilder.php @@ -63,7 +63,7 @@ final class AddressBuilder private $subLocality; /** - * @var array + * @var AdminLevel[] */ private $adminLevels = []; @@ -85,23 +85,15 @@ final class AddressBuilder /** * A storage for extra parameters. * - * @var array + * @var array */ private $data = []; - /** - * @param string $providedBy - */ public function __construct(string $providedBy) { $this->providedBy = $providedBy; } - /** - * @param string $class - * - * @return Address - */ public function build(string $class = Address::class): Address { if (!is_a($class, Address::class, true)) { @@ -109,7 +101,7 @@ public function build(string $class = Address::class): Address } $country = null; - if (!empty($this->country) || !empty($this->country)) { + if ((null !== $this->country && '' !== $this->country) || (null !== $this->countryCode && '' !== $this->countryCode)) { $country = new Country($this->country, $this->countryCode); } @@ -133,8 +125,6 @@ public function build(string $class = Address::class): Address * @param float $west * @param float $north * @param float $east - * - * @return AddressBuilder */ public function setBounds($south, $west, $north, $east): self { @@ -150,8 +140,6 @@ public function setBounds($south, $west, $north, $east): self /** * @param float $latitude * @param float $longitude - * - * @return AddressBuilder */ public function setCoordinates($latitude, $longitude): self { @@ -164,14 +152,7 @@ public function setCoordinates($latitude, $longitude): self return $this; } - /** - * @param int $level - * @param string $name - * @param string|null $code - * - * @return AddressBuilder - */ - public function addAdminLevel(int $level, string $name, string $code = null): self + public function addAdminLevel(int $level, string $name, ?string $code = null): self { $this->adminLevels[] = new AdminLevel($level, $name, $code); @@ -179,9 +160,7 @@ public function addAdminLevel(int $level, string $name, string $code = null): se } /** - * @param null|string $streetNumber - * - * @return AddressBuilder + * @param string|null $streetNumber */ public function setStreetNumber($streetNumber): self { @@ -191,9 +170,7 @@ public function setStreetNumber($streetNumber): self } /** - * @param null|string $streetName - * - * @return AddressBuilder + * @param string|null $streetName */ public function setStreetName($streetName): self { @@ -203,9 +180,7 @@ public function setStreetName($streetName): self } /** - * @param null|string $locality - * - * @return AddressBuilder + * @param string|null $locality */ public function setLocality($locality): self { @@ -215,9 +190,7 @@ public function setLocality($locality): self } /** - * @param null|string $postalCode - * - * @return AddressBuilder + * @param string|null $postalCode */ public function setPostalCode($postalCode): self { @@ -227,9 +200,7 @@ public function setPostalCode($postalCode): self } /** - * @param null|string $subLocality - * - * @return AddressBuilder + * @param string|null $subLocality */ public function setSubLocality($subLocality): self { @@ -239,9 +210,7 @@ public function setSubLocality($subLocality): self } /** - * @param array $adminLevels - * - * @return AddressBuilder + * @param AdminLevel[] $adminLevels */ public function setAdminLevels($adminLevels): self { @@ -251,9 +220,7 @@ public function setAdminLevels($adminLevels): self } /** - * @param null|string $country - * - * @return AddressBuilder + * @param string|null $country */ public function setCountry($country): self { @@ -263,9 +230,7 @@ public function setCountry($country): self } /** - * @param null|string $countryCode - * - * @return AddressBuilder + * @param string|null $countryCode */ public function setCountryCode($countryCode): self { @@ -275,9 +240,7 @@ public function setCountryCode($countryCode): self } /** - * @param null|string $timezone - * - * @return AddressBuilder + * @param string|null $timezone */ public function setTimezone($timezone): self { @@ -286,26 +249,14 @@ public function setTimezone($timezone): self return $this; } - /** - * @param string $name - * @param mixed $value - * - * @return AddressBuilder - */ - public function setValue(string $name, $value): self + public function setValue(string $name, mixed $value): self { $this->data[$name] = $value; return $this; } - /** - * @param string $name - * @param mixed|null $default - * - * @return mixed - */ - public function getValue(string $name, $default = null) + public function getValue(string $name, mixed $default = null): mixed { if ($this->hasValue($name)) { return $this->data[$name]; @@ -314,11 +265,6 @@ public function getValue(string $name, $default = null) return $default; } - /** - * @param string $name - * - * @return bool - */ public function hasValue(string $name): bool { return array_key_exists($name, $this->data); diff --git a/Model/AddressCollection.php b/Model/AddressCollection.php index 9895b18d..83af64aa 100644 --- a/Model/AddressCollection.php +++ b/Model/AddressCollection.php @@ -32,61 +32,43 @@ public function __construct(array $locations = []) $this->locations = array_values($locations); } - /** - * {@inheritdoc} - */ - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayIterator($this->all()); } - /** - * {@inheritdoc} - */ - public function count() + public function count(): int { return count($this->locations); } - /** - * {@inheritdoc} - */ public function first(): Location { - if (empty($this->locations)) { + if ([] === $this->locations) { throw new CollectionIsEmpty(); } return reset($this->locations); } - /** - * {@inheritdoc} - */ public function isEmpty(): bool { - return empty($this->locations); + return [] === $this->locations; } /** * @return Location[] */ - public function slice(int $offset, int $length = null) + public function slice(int $offset, ?int $length = null) { return array_slice($this->locations, $offset, $length); } - /** - * @return bool - */ public function has(int $index): bool { return isset($this->locations[$index]); } - /** - * {@inheritdoc} - */ public function get(int $index): Location { if (!isset($this->locations[$index])) { @@ -96,9 +78,6 @@ public function get(int $index): Location return $this->locations[$index]; } - /** - * {@inheritdoc} - */ public function all(): array { return $this->locations; diff --git a/Model/AdminLevel.php b/Model/AdminLevel.php index d2271b8b..dab0baf2 100644 --- a/Model/AdminLevel.php +++ b/Model/AdminLevel.php @@ -32,12 +32,7 @@ final class AdminLevel */ private $code; - /** - * @param int $level - * @param string $name - * @param string|null $code - */ - public function __construct(int $level, string $name, string $code = null) + public function __construct(int $level, string $name, ?string $code = null) { $this->level = $level; $this->name = $name; @@ -56,8 +51,6 @@ public function getLevel(): int /** * Returns the administrative level name. - * - * @return string */ public function getName(): string { @@ -76,8 +69,6 @@ public function getCode() /** * Returns a string with the administrative level name. - * - * @return string */ public function __toString(): string { diff --git a/Model/AdminLevelCollection.php b/Model/AdminLevelCollection.php index ecb71aca..006e1d7a 100644 --- a/Model/AdminLevelCollection.php +++ b/Model/AdminLevelCollection.php @@ -18,10 +18,12 @@ /** * @author Giorgio Premi + * + * @phpstan-implements \IteratorAggregate */ final class AdminLevelCollection implements \IteratorAggregate, \Countable { - const MAX_LEVEL_DEPTH = 5; + public const MAX_LEVEL_DEPTH = 5; /** * @var AdminLevel[] @@ -50,30 +52,22 @@ public function __construct(array $adminLevels = []) ksort($this->adminLevels, SORT_NUMERIC); } - /** - * {@inheritdoc} - */ - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayIterator($this->all()); } - /** - * {@inheritdoc} - */ - public function count() + public function count(): int { return count($this->adminLevels); } /** - * @return AdminLevel - * * @throws CollectionIsEmpty */ public function first(): AdminLevel { - if (empty($this->adminLevels)) { + if ([] === $this->adminLevels) { throw new CollectionIsEmpty(); } @@ -81,27 +75,19 @@ public function first(): AdminLevel } /** - * @param int $offset - * @param int|null $length - * * @return AdminLevel[] */ - public function slice(int $offset, int $length = null): array + public function slice(int $offset, ?int $length = null): array { return array_slice($this->adminLevels, $offset, $length, true); } - /** - * @return bool - */ public function has(int $level): bool { return isset($this->adminLevels[$level]); } /** - * @return AdminLevel - * * @throws \OutOfBoundsException * @throws InvalidArgument */ @@ -113,7 +99,7 @@ public function get(int $level): AdminLevel throw new InvalidArgument(sprintf('Administrative level %d is not set for this address', $level)); } - return $this->adminLevels[$level]; + return $this->adminLevels[$level]; } /** @@ -125,16 +111,12 @@ public function all(): array } /** - * @param int $level - * * @throws \OutOfBoundsException */ - private function checkLevel(int $level) + private function checkLevel(int $level): void { if ($level <= 0 || $level > self::MAX_LEVEL_DEPTH) { - throw new OutOfBounds( - sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level) - ); + throw new OutOfBounds(sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level)); } } } diff --git a/Model/Bounds.php b/Model/Bounds.php index 52d91b2b..832ee968 100644 --- a/Model/Bounds.php +++ b/Model/Bounds.php @@ -40,10 +40,10 @@ final class Bounds private $east; /** - * @param float $south - * @param float $west - * @param float $north - * @param float $east + * @param float $south South bound, also min latitude + * @param float $west West bound, also min longitude + * @param float $north North bound, also max latitude + * @param float $east East bound, also max longitude */ public function __construct($south, $west, $north, $east) { @@ -70,8 +70,6 @@ public function __construct($south, $west, $north, $east) /** * Returns the south bound. - * - * @return float */ public function getSouth(): float { @@ -80,8 +78,6 @@ public function getSouth(): float /** * Returns the west bound. - * - * @return float */ public function getWest(): float { @@ -90,8 +86,6 @@ public function getWest(): float /** * Returns the north bound. - * - * @return float */ public function getNorth(): float { @@ -100,8 +94,6 @@ public function getNorth(): float /** * Returns the east bound. - * - * @return float */ public function getEast(): float { @@ -111,7 +103,7 @@ public function getEast(): float /** * Returns an array with bounds. * - * @return array + * @return array{south: float, west: float, north: float, east: float} */ public function toArray(): array { diff --git a/Model/Coordinates.php b/Model/Coordinates.php index f346a298..1e8ce527 100644 --- a/Model/Coordinates.php +++ b/Model/Coordinates.php @@ -50,8 +50,6 @@ public function __construct($latitude, $longitude) /** * Returns the latitude. - * - * @return float */ public function getLatitude(): float { @@ -60,11 +58,19 @@ public function getLatitude(): float /** * Returns the longitude. - * - * @return float */ public function getLongitude(): float { return $this->longitude; } + + /** + * Returns the coordinates as a tuple. + * + * @return array{float, float} + */ + public function toArray(): array + { + return [$this->getLongitude(), $this->getLatitude()]; + } } diff --git a/Model/Country.php b/Model/Country.php index dcbf3d92..b27975f0 100644 --- a/Model/Country.php +++ b/Model/Country.php @@ -12,7 +12,11 @@ namespace Geocoder\Model; +use Geocoder\Exception\InvalidArgument; + /** + * A Country has either a name or a code. A Country will never be without data. + * * @author William Durand */ final class Country @@ -27,12 +31,12 @@ final class Country */ private $code; - /** - * @param string $name - * @param string $code - */ - public function __construct(string $name = null, string $code = null) + public function __construct(?string $name = null, ?string $code = null) { + if (null === $name && null === $code) { + throw new InvalidArgument('A country must have either a name or a code'); + } + $this->name = $name; $this->code = $code; } @@ -59,8 +63,6 @@ public function getCode() /** * Returns a string with the country name. - * - * @return string */ public function __toString(): string { diff --git a/Provider/AbstractProvider.php b/Provider/AbstractProvider.php index 7c8b8b6c..9a698a93 100644 --- a/Provider/AbstractProvider.php +++ b/Provider/AbstractProvider.php @@ -22,8 +22,6 @@ abstract class AbstractProvider implements Provider { /** * Returns the results for the 'localhost' special case. - * - * @return Location */ protected function getLocationForLocalhost(): Location { diff --git a/Provider/Provider.php b/Provider/Provider.php index bea5d02b..15b5369d 100644 --- a/Provider/Provider.php +++ b/Provider/Provider.php @@ -25,27 +25,17 @@ interface Provider { /** - * @param GeocodeQuery $query - * - * @return Collection - * * @throws \Geocoder\Exception\Exception */ public function geocodeQuery(GeocodeQuery $query): Collection; /** - * @param ReverseQuery $query - * - * @return Collection - * * @throws \Geocoder\Exception\Exception */ public function reverseQuery(ReverseQuery $query): Collection; /** * Returns the provider's name. - * - * @return string */ public function getName(): string; } diff --git a/ProviderAggregator.php b/ProviderAggregator.php index 75a9f458..e4d1fe61 100644 --- a/ProviderAggregator.php +++ b/ProviderAggregator.php @@ -14,14 +14,14 @@ use Geocoder\Exception\ProviderNotRegistered; use Geocoder\Model\Coordinates; +use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\Provider\Provider; /** * @author William Durand */ -final class ProviderAggregator implements Geocoder +class ProviderAggregator implements Geocoder { /** * @var Provider[] @@ -39,81 +39,47 @@ final class ProviderAggregator implements Geocoder private $limit; /** - * @param int $limit + * A callable that decided what provider to use. + * + * @var callable */ - public function __construct(int $limit = Geocoder::DEFAULT_RESULT_LIMIT) + private $decider; + + public function __construct(?callable $decider = null, int $limit = Geocoder::DEFAULT_RESULT_LIMIT) { - $this->limit($limit); + $this->limit = $limit; + $this->decider = $decider ?? __CLASS__.'::getProvider'; } - /** - * {@inheritdoc} - */ public function geocodeQuery(GeocodeQuery $query): Collection { - return $this->getProvider()->geocodeQuery($query); + return call_user_func($this->decider, $query, $this->providers, $this->provider)->geocodeQuery($query); } - /** - * {@inheritdoc} - */ public function reverseQuery(ReverseQuery $query): Collection { - return $this->getProvider()->reverseQuery($query); + return call_user_func($this->decider, $query, $this->providers, $this->provider)->reverseQuery($query); } - /** - * {@inheritdoc} - */ public function getName(): string { return 'provider_aggregator'; } - /** - * {@inheritdoc} - */ public function geocode(string $value): Collection { return $this->geocodeQuery(GeocodeQuery::create($value) ->withLimit($this->limit)); } - /** - * {@inheritdoc} - */ public function reverse(float $latitude, float $longitude): Collection { return $this->reverseQuery(ReverseQuery::create(new Coordinates($latitude, $longitude)) ->withLimit($this->limit)); } - /** - * @param $limit - * - * @return $this - */ - public function limit(int $limit): self - { - $this->limit = $limit; - - return $this; - } - - /** - * @return int - */ - public function getLimit(): int - { - return $this->limit; - } - /** * Registers a new provider to the aggregator. - * - * @param Provider $provider - * - * @return ProviderAggregator */ public function registerProvider(Provider $provider): self { @@ -126,8 +92,6 @@ public function registerProvider(Provider $provider): self * Registers a set of providers. * * @param Provider[] $providers - * - * @return ProviderAggregator */ public function registerProviders(array $providers = []): self { @@ -140,15 +104,11 @@ public function registerProviders(array $providers = []): self /** * Sets the default provider to use. - * - * @param string $name - * - * @return ProviderAggregator */ public function using(string $name): self { if (!isset($this->providers[$name])) { - throw ProviderNotRegistered::create($name ?? '', $this->providers); + throw ProviderNotRegistered::create($name, array_keys($this->providers)); } $this->provider = $this->providers[$name]; @@ -167,22 +127,26 @@ public function getProviders(): array } /** - * Returns the current provider in use. + * Get a provider to use for this query. * - * @return Provider + * @param GeocodeQuery|ReverseQuery $query + * @param Provider[] $providers * - * @throws \RuntimeException + * @throws ProviderNotRegistered */ - protected function getProvider(): Provider + private static function getProvider($query, array $providers, ?Provider $currentProvider = null): Provider { - if (null === $this->provider) { - if (0 === count($this->providers)) { - throw ProviderNotRegistered::noProviderRegistered(); - } + if (null !== $currentProvider) { + return $currentProvider; + } - $this->using(key($this->providers)); + if ([] === $providers) { + throw ProviderNotRegistered::noProviderRegistered(); } - return $this->provider; + // Take first + $key = key($providers); + + return $providers[$key]; } } diff --git a/Query/GeocodeQuery.php b/Query/GeocodeQuery.php index 699656cd..331b23df 100644 --- a/Query/GeocodeQuery.php +++ b/Query/GeocodeQuery.php @@ -19,7 +19,7 @@ /** * @author Tobias Nyholm */ -final class GeocodeQuery +final class GeocodeQuery implements Query { /** * The address or text that should be geocoded. @@ -44,38 +44,33 @@ final class GeocodeQuery private $limit = Geocoder::DEFAULT_RESULT_LIMIT; /** - * @var array + * @var array */ private $data = []; - /** - * @param string $text - */ private function __construct(string $text) { - if (empty($text)) { + if ('' === $text) { throw new InvalidArgument('Geocode query cannot be empty'); } $this->text = $text; } - /** - * @param string $text - * - * @return GeocodeQuery - */ - public static function create(string $text): GeocodeQuery + public static function create(string $text): self { return new self($text); } - /** - * @param Bounds $bounds - * - * @return GeocodeQuery - */ - public function withBounds(Bounds $bounds): GeocodeQuery + public function withText(string $text): self + { + $new = clone $this; + $new->text = $text; + + return $new; + } + + public function withBounds(Bounds $bounds): self { $new = clone $this; $new->bounds = $bounds; @@ -83,12 +78,7 @@ public function withBounds(Bounds $bounds): GeocodeQuery return $new; } - /** - * @param string $locale - * - * @return GeocodeQuery - */ - public function withLocale(string $locale): GeocodeQuery + public function withLocale(string $locale): self { $new = clone $this; $new->locale = $locale; @@ -96,12 +86,7 @@ public function withLocale(string $locale): GeocodeQuery return $new; } - /** - * @param int $limit - * - * @return GeocodeQuery - */ - public function withLimit(int $limit): GeocodeQuery + public function withLimit(int $limit): self { $new = clone $this; $new->limit = $limit; @@ -109,13 +94,7 @@ public function withLimit(int $limit): GeocodeQuery return $new; } - /** - * @param string $name - * @param mixed $value - * - * @return GeocodeQuery - */ - public function withData(string $name, $value): GeocodeQuery + public function withData(string $name, mixed $value): self { $new = clone $this; $new->data[$name] = $value; @@ -123,45 +102,27 @@ public function withData(string $name, $value): GeocodeQuery return $new; } - /** - * @return string - */ public function getText(): string { return $this->text; } - /** - * @return Bounds|null - */ - public function getBounds() + public function getBounds(): ?Bounds { return $this->bounds; } - /** - * @return string|null - */ - public function getLocale() + public function getLocale(): ?string { return $this->locale; } - /** - * @return int - */ public function getLimit(): int { return $this->limit; } - /** - * @param string $name - * @param mixed|null $default - * - * @return mixed - */ - public function getData(string $name, $default = null) + public function getData(string $name, mixed $default = null): mixed { if (!array_key_exists($name, $this->data)) { return $default; @@ -171,7 +132,7 @@ public function getData(string $name, $default = null) } /** - * @return array + * @return array */ public function getAllData(): array { @@ -179,11 +140,9 @@ public function getAllData(): array } /** - * String for logging. This is also a unique key for the query - * - * @return string + * String for logging. This is also a unique key for the query. */ - public function __toString() + public function __toString(): string { return sprintf('GeocodeQuery: %s', json_encode([ 'text' => $this->getText(), diff --git a/Query/Query.php b/Query/Query.php new file mode 100644 index 00000000..32bb4ba9 --- /dev/null +++ b/Query/Query.php @@ -0,0 +1,38 @@ + + */ +interface Query +{ + public function withLocale(string $locale): Query; + + public function withLimit(int $limit): Query; + + public function withData(string $name, mixed $value): Query; + + public function getLocale(): ?string; + + public function getLimit(): int; + + public function getData(string $name, mixed $default = null): mixed; + + /** + * @return array + */ + public function getAllData(): array; + + public function __toString(): string; +} diff --git a/Query/ReverseQuery.php b/Query/ReverseQuery.php index 91d7c596..ca28e22e 100644 --- a/Query/ReverseQuery.php +++ b/Query/ReverseQuery.php @@ -18,7 +18,7 @@ /** * @author Tobias Nyholm */ -final class ReverseQuery +final class ReverseQuery implements Query { /** * @var Coordinates @@ -36,21 +36,16 @@ final class ReverseQuery private $limit = Geocoder::DEFAULT_RESULT_LIMIT; /** - * @var array + * @var array */ private $data = []; - /** - * @param Coordinates $coordinates - */ private function __construct(Coordinates $coordinates) { $this->coordinates = $coordinates; } /** - * @param Coordinates $coordinates - * * @return ReverseQuery */ public static function create(Coordinates $coordinates) @@ -61,20 +56,21 @@ public static function create(Coordinates $coordinates) /** * @param float $latitude * @param float $longitude - * - * @return ReverseQuery */ - public static function fromCoordinates($latitude, $longitude): ReverseQuery + public static function fromCoordinates($latitude, $longitude): self { return new self(new Coordinates($latitude, $longitude)); } - /** - * @param int $limit - * - * @return ReverseQuery - */ - public function withLimit(int $limit): ReverseQuery + public function withCoordinates(Coordinates $coordinates): self + { + $new = clone $this; + $new->coordinates = $coordinates; + + return $new; + } + + public function withLimit(int $limit): self { $new = clone $this; $new->limit = $limit; @@ -82,12 +78,7 @@ public function withLimit(int $limit): ReverseQuery return $new; } - /** - * @param string $locale - * - * @return ReverseQuery - */ - public function withLocale(string $locale): ReverseQuery + public function withLocale(string $locale): self { $new = clone $this; $new->locale = $locale; @@ -95,13 +86,7 @@ public function withLocale(string $locale): ReverseQuery return $new; } - /** - * @param string $name - * @param mixed $value - * - * @return ReverseQuery - */ - public function withData(string $name, $value): ReverseQuery + public function withData(string $name, mixed $value): self { $new = clone $this; $new->data[$name] = $value; @@ -109,37 +94,22 @@ public function withData(string $name, $value): ReverseQuery return $new; } - /** - * @return Coordinates - */ public function getCoordinates(): Coordinates { return $this->coordinates; } - /** - * @return int - */ public function getLimit(): int { return $this->limit; } - /** - * @return string - */ - public function getLocale() + public function getLocale(): ?string { return $this->locale; } - /** - * @param string $name - * @param mixed|null $default - * - * @return mixed - */ - public function getData(string $name, $default = null) + public function getData(string $name, mixed $default = null): mixed { if (!array_key_exists($name, $this->data)) { return $default; @@ -149,7 +119,7 @@ public function getData(string $name, $default = null) } /** - * @return array + * @return array */ public function getAllData(): array { @@ -157,11 +127,9 @@ public function getAllData(): array } /** - * String for logging. This is also a unique key for the query - * - * @return string + * String for logging. This is also a unique key for the query. */ - public function __toString() + public function __toString(): string { return sprintf('ReverseQuery: %s', json_encode([ 'lat' => $this->getCoordinates()->getLatitude(), diff --git a/Readme.md b/Readme.md index 41581ff7..caa39c14 100644 --- a/Readme.md +++ b/Readme.md @@ -18,7 +18,7 @@ Just some months before the release of 4.0 of `willdurand/geocoder` we changed t from https://github.com/geocoder-php/Geocoder. The new repository will only contain classes and interfaces shared between multiple providers. The original repository is still used for issues and pull requests. -The new repository architecture allows us to use a [git subtree split](www.subtreesplit.com) from geocoder-php/Geocoder +The new repository architecture allows us to use a [git subtree split](https://www.subtreesplit.com) from geocoder-php/Geocoder to geocoder-php/php-common and to each provider. Versions before 4.0 `willdurand/geocoder` will still work as usual, but with the new repository. diff --git a/StatefulGeocoder.php b/StatefulGeocoder.php index 400f20df..4a2d5704 100644 --- a/StatefulGeocoder.php +++ b/StatefulGeocoder.php @@ -13,9 +13,9 @@ namespace Geocoder; use Geocoder\Model\Bounds; +use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\Provider\Provider; /** * @author Tobias Nyholm @@ -23,7 +23,7 @@ final class StatefulGeocoder implements Geocoder { /** - * @var string + * @var string|null */ private $locale; @@ -42,58 +42,45 @@ final class StatefulGeocoder implements Geocoder */ private $provider; - /** - * @param Provider $provider - * @param string $locale - */ - public function __construct(Provider $provider, string $locale = null) + public function __construct(Provider $provider, ?string $locale = null) { $this->provider = $provider; $this->locale = $locale; $this->limit = Geocoder::DEFAULT_RESULT_LIMIT; } - /** - * {@inheritdoc} - */ public function geocode(string $value): Collection { $query = GeocodeQuery::create($value) ->withLimit($this->limit); - if (!empty($this->locale)) { - $query->withLocale($this->locale); + if (null !== $this->locale && '' !== $this->locale) { + $query = $query->withLocale($this->locale); } - if (!empty($this->bounds)) { - $query->withBounds($this->bounds); + if (null !== $this->bounds) { + $query = $query->withBounds($this->bounds); } return $this->provider->geocodeQuery($query); } - /** - * {@inheritdoc} - */ public function reverse(float $latitude, float $longitude): Collection { $query = ReverseQuery::fromCoordinates($latitude, $longitude) ->withLimit($this->limit); - if (!empty($this->locale)) { + if (null !== $this->locale && '' !== $this->locale) { $query = $query->withLocale($this->locale); } return $this->provider->reverseQuery($query); } - /** - * {@inheritdoc} - */ public function geocodeQuery(GeocodeQuery $query): Collection { $locale = $query->getLocale(); - if (empty($locale) && null !== $this->locale) { + if ((null === $locale || '' === $locale) && null !== $this->locale) { $query = $query->withLocale($this->locale); } @@ -105,24 +92,16 @@ public function geocodeQuery(GeocodeQuery $query): Collection return $this->provider->geocodeQuery($query); } - /** - * {@inheritdoc} - */ public function reverseQuery(ReverseQuery $query): Collection { $locale = $query->getLocale(); - if (empty($locale) && null !== $this->locale) { - $query->withLocale($this->locale); + if ((null === $locale || '' === $locale) && null !== $this->locale) { + $query = $query->withLocale($this->locale); } return $this->provider->reverseQuery($query); } - /** - * @param string $locale - * - * @return StatefulGeocoder - */ public function setLocale(string $locale): self { $this->locale = $locale; @@ -130,11 +109,6 @@ public function setLocale(string $locale): self return $this; } - /** - * @param Bounds $bounds - * - * @return StatefulGeocoder - */ public function setBounds(Bounds $bounds): self { $this->bounds = $bounds; @@ -142,11 +116,6 @@ public function setBounds(Bounds $bounds): self return $this; } - /** - * @param int $limit - * - * @return StatefulGeocoder - */ public function setLimit(int $limit): self { $this->limit = $limit; @@ -154,9 +123,6 @@ public function setLimit(int $limit): self return $this; } - /** - * {@inheritdoc} - */ public function getName(): string { return 'stateful_geocoder'; diff --git a/Tests/Dumper/GeoArrayTest.php b/Tests/Dumper/GeoArrayTest.php index 252955cc..ac90a3df 100644 --- a/Tests/Dumper/GeoArrayTest.php +++ b/Tests/Dumper/GeoArrayTest.php @@ -26,12 +26,12 @@ class GeoArrayTest extends TestCase */ private $dumper; - protected function setUp() + protected function setUp(): void { $this->dumper = new GeoArray(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = [ @@ -47,11 +47,11 @@ public function testDump() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -71,11 +71,11 @@ public function testDumpWithData() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } - public function testDumpWithBounds() + public function testDumpWithBounds(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -107,11 +107,11 @@ public function testDumpWithBounds() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } - public function testDumpWithProperties() + public function testDumpWithProperties(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -147,7 +147,7 @@ public function testDumpWithProperties() $result = $this->dumper->dump($address); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals($expected, $result); } } diff --git a/Tests/Dumper/GeoJsonTest.php b/Tests/Dumper/GeoJsonTest.php index 9e745a8e..c4bfdb2c 100644 --- a/Tests/Dumper/GeoJsonTest.php +++ b/Tests/Dumper/GeoJsonTest.php @@ -27,12 +27,12 @@ class GeoJsonTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new GeoJson(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = [ @@ -52,7 +52,7 @@ public function testDump() $this->assertEquals($expected, json_decode($result, true)); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -76,7 +76,7 @@ public function testDumpWithData() $this->assertEquals($expected, json_decode($result, true)); } - public function testDumpWithBounds() + public function testDumpWithBounds(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -112,7 +112,7 @@ public function testDumpWithBounds() $this->assertEquals($expected, json_decode($result, true)); } - public function testDumpWithProperties() + public function testDumpWithProperties(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Dumper/GpxTest.php b/Tests/Dumper/GpxTest.php index f72c70c0..a00f4475 100644 --- a/Tests/Dumper/GpxTest.php +++ b/Tests/Dumper/GpxTest.php @@ -12,8 +12,8 @@ namespace Geocoder\Tests\Dumper; -use Geocoder\Geocoder; use Geocoder\Dumper\Gpx; +use Geocoder\Geocoder; use Geocoder\Model\Address; use PHPUnit\Framework\TestCase; @@ -27,12 +27,12 @@ class GpxTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Gpx(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = sprintf(<<<'GPX' @@ -49,7 +49,7 @@ public function testDump() GPX - , Geocoder::VERSION, '0', '0'); + , Geocoder::VERSION, '0', '0'); $result = $this->dumper->dump($address); @@ -57,7 +57,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -78,7 +78,7 @@ public function testDumpWithData() GPX - , Geocoder::VERSION, $address->getCoordinates()->getLatitude(), $address->getCoordinates()->getLongitude()); + , Geocoder::VERSION, $address->getCoordinates()->getLatitude(), $address->getCoordinates()->getLongitude()); $result = $this->dumper->dump($address); @@ -86,7 +86,7 @@ public function testDumpWithData() $this->assertEquals($expected, $result); } - public function testDumpWithBounds() + public function testDumpWithBounds(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, @@ -115,7 +115,7 @@ public function testDumpWithBounds() GPX - , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); + , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); $this->assertNotNull($address->getBounds()); @@ -125,7 +125,7 @@ public function testDumpWithBounds() $this->assertEquals($expected, $result); } - public function testDumpWithName() + public function testDumpWithName(): void { $bounds = [ 'south' => 48.8631507, @@ -160,7 +160,7 @@ public function testDumpWithName() GPX - , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); + , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); $this->assertNotNull($address->getBounds()); diff --git a/Tests/Dumper/KmlTest.php b/Tests/Dumper/KmlTest.php index 2870acff..05eec4a2 100644 --- a/Tests/Dumper/KmlTest.php +++ b/Tests/Dumper/KmlTest.php @@ -27,12 +27,12 @@ class KmlTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Kml(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = <<<'KML' @@ -56,7 +56,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Dumper/WkbTest.php b/Tests/Dumper/WkbTest.php index 325fa4bb..14abc04c 100644 --- a/Tests/Dumper/WkbTest.php +++ b/Tests/Dumper/WkbTest.php @@ -27,12 +27,12 @@ class WkbTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Wkb(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = pack('H*', '010100000000000000000000000000000000000000'); @@ -42,7 +42,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Dumper/WktTest.php b/Tests/Dumper/WktTest.php index 6a44ac01..9fc8982d 100644 --- a/Tests/Dumper/WktTest.php +++ b/Tests/Dumper/WktTest.php @@ -27,12 +27,12 @@ class WktTest extends TestCase */ private $dumper; - public function setUp() + public function setUp(): void { $this->dumper = new Wkt(); } - public function testDump() + public function testDump(): void { $address = Address::createFromArray([]); $expected = sprintf('POINT(%F %F)', 0, 0); @@ -42,7 +42,7 @@ public function testDump() $this->assertEquals($expected, $result); } - public function testDumpWithData() + public function testDumpWithData(): void { $address = Address::createFromArray([ 'latitude' => 48.8631507, diff --git a/Tests/Formatter/StringFormatterTest.php b/Tests/Formatter/StringFormatterTest.php index 9e83bffe..3b0359e5 100644 --- a/Tests/Formatter/StringFormatterTest.php +++ b/Tests/Formatter/StringFormatterTest.php @@ -26,15 +26,17 @@ class StringFormatterTest extends TestCase */ private $formatter; - public function setUp() + public function setUp(): void { $this->formatter = new StringFormatter(); } /** * @dataProvider dataProviderForTestFormat + * + * @param array $data */ - public function testFormat($data, $format, $expected) + public function testFormat(array $data, string $format, string $expected): void { $address = Address::createFromArray($data); $result = $this->formatter->format($address, $format); @@ -43,7 +45,10 @@ public function testFormat($data, $format, $expected) $this->assertEquals($expected, $result); } - public function dataProviderForTestFormat() + /** + * @return array>|string>|string>> + */ + public function dataProviderForTestFormat(): array { return [ [ diff --git a/Tests/Model/AddressCollectionTest.php b/Tests/Model/AddressCollectionTest.php index 842d4e3a..6ad6dcd3 100644 --- a/Tests/Model/AddressCollectionTest.php +++ b/Tests/Model/AddressCollectionTest.php @@ -20,11 +20,10 @@ */ class AddressCollectionTest extends TestCase { - /** - * @expectedException \Geocoder\Exception\CollectionIsEmpty - */ - public function testFirstOnEmpty() + public function testFirstOnEmpty(): void { + $this->expectException(\Geocoder\Exception\CollectionIsEmpty::class); + $collection = new AddressCollection([]); $collection->first(); } diff --git a/Tests/Model/AddressTest.php b/Tests/Model/AddressTest.php index 15cb5d47..2995be28 100644 --- a/Tests/Model/AddressTest.php +++ b/Tests/Model/AddressTest.php @@ -21,7 +21,7 @@ */ class AddressTest extends TestCase { - public function testDumpEmptyAddress() + public function testDumpEmptyAddress(): void { $expected = [ 'providedBy' => 'n/a', @@ -48,7 +48,7 @@ public function testDumpEmptyAddress() $this->assertEquals($address->toArray(), $expected); } - public function testToArray() + public function testToArray(): void { $data = [ 'providedBy' => 'n/a', diff --git a/Tests/ProviderAggregatorTest.php b/Tests/ProviderAggregatorTest.php index b3e41cb4..579e568e 100644 --- a/Tests/ProviderAggregatorTest.php +++ b/Tests/ProviderAggregatorTest.php @@ -13,11 +13,12 @@ namespace Geocoder\Tests; use Geocoder\Collection; -use Geocoder\Geocoder; +use Geocoder\Model\Address; +use Geocoder\Model\AddressCollection; +use Geocoder\Provider\Provider; +use Geocoder\ProviderAggregator; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\ProviderAggregator; -use Geocoder\Provider\Provider; use Nyholm\NSA; use PHPUnit\Framework\TestCase; @@ -31,62 +32,74 @@ class ProviderAggregatorTest extends TestCase */ protected $geocoder; - protected function setUp() + protected function setUp(): void { $this->geocoder = new ProviderAggregator(); } - public function testRegisterProvider() + public function testGeocode(): void { - $provider = new MockProvider('test'); - $this->geocoder->registerProvider($provider); - - $this->assertSame($provider, NSA::invokeMethod($this->geocoder, 'getProvider')); - } + $provider1 = new MockProvider('test1'); + $provider1->result = [Address::createFromArray(['providedBy' => 'p1'])]; + $provider2 = new MockProvider('test2'); + $provider2->result = [Address::createFromArray(['providedBy' => 'p2'])]; - public function testRegisterProviders() - { - $provider = new MockProvider('test'); - $this->geocoder->registerProviders([$provider]); + $this->geocoder->registerProvider($provider1); + $this->geocoder->registerProvider($provider2); - $this->assertSame($provider, NSA::invokeMethod($this->geocoder, 'getProvider')); + $result = $this->geocoder->geocode('foo'); + $this->assertEquals('p1', $result->first()->getProvidedBy()); } - public function testUsing() + public function testReverse(): void { $provider1 = new MockProvider('test1'); + $provider1->result = [Address::createFromArray(['providedBy' => 'p1'])]; $provider2 = new MockProvider('test2'); - $this->geocoder->registerProviders([$provider1, $provider2]); + $provider2->result = [Address::createFromArray(['providedBy' => 'p2'])]; - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); + $this->geocoder->registerProvider($provider1); + $this->geocoder->registerProvider($provider2); + $this->geocoder->using('test2'); - $this->geocoder->using('test1'); - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); + $result = $this->geocoder->reverse(0.1, 0.2); + $this->assertEquals('p2', $result->first()->getProvidedBy()); + } - $this->geocoder->using('test2'); - $this->assertSame($provider2, NSA::invokeMethod($this->geocoder, 'getProvider')); + public function testRegisterProvider(): void + { + $provider = new MockProvider('test'); + $this->geocoder->registerProvider($provider); - $this->geocoder->using('test1'); - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); + $this->assertSame(['test' => $provider], NSA::getProperty($this->geocoder, 'providers')); } - /** - * @expectedException \Geocoder\Exception\ProviderNotRegistered - */ - public function testUsingNonExistantProviderShouldThrowAnException() + public function testRegisterProviders(): void { + $provider = new MockProvider('test'); + $this->geocoder->registerProviders([$provider]); + + $this->assertSame(['test' => $provider], NSA::getProperty($this->geocoder, 'providers')); + } + + public function testUsingNonExistantProviderShouldThrowAnException(): void + { + $this->expectException(\Geocoder\Exception\ProviderNotRegistered::class); + $this->expectExceptionMessage('Provider "non_existant" is not registered, so you cannot use it. Did you forget to register it or made a typo? Registered providers are: test1.'); + + $this->geocoder->registerProvider(new MockProvider('test1')); + $this->geocoder->using('non_existant'); } - /** - * @expectedException \Geocoder\Exception\ProviderNotRegistered - */ - public function testUsingAnEmptyProviderNameShouldThrowAnException() + public function testUsingAnEmptyProviderNameShouldThrowAnException(): void { + $this->expectException(\Geocoder\Exception\ProviderNotRegistered::class); + $this->geocoder->using(''); } - public function testGetProviders() + public function testGetProviders(): void { $provider1 = new MockProvider('test1'); $provider2 = new MockProvider('test2'); @@ -104,49 +117,50 @@ public function testGetProviders() $this->assertArrayHasKey('test2', $result); } - /** - * @expectedException \RuntimeException - */ - public function testGetProvider() + public function testGetProvider(): void { - NSA::invokeMethod($this->geocoder, 'getProvider'); + $this->expectException(\RuntimeException::class); + + NSA::invokeMethod($this->geocoder, 'getProvider', GeocodeQuery::create('foo'), [], null); $this->fail('getProvider() should throw an exception'); } - public function testGetProviderWithMultipleProvidersReturnsTheFirstOne() + public function testGetProviderWithMultipleProvidersReturnsTheFirstOne(): void { - $this->geocoder->registerProviders([ + $providers = [ $provider1 = new MockProvider('test1'), $provider2 = new MockProvider('test2'), $provider3 = new MockProvider('test3'), - ]); - - $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider')); - } + ]; - public function testDefaultMaxResults() - { - $this->assertSame(Geocoder::DEFAULT_RESULT_LIMIT, $this->geocoder->getLimit()); + $query = GeocodeQuery::create('foo'); + $this->assertSame($provider1, NSA::invokeMethod($this->geocoder, 'getProvider', $query, $providers, null)); + $this->assertSame($provider2, NSA::invokeMethod($this->geocoder, 'getProvider', $query, $providers, $provider2)); } } class MockProvider implements Provider { - protected $name; + protected string $name; + + /** + * @var Address[] + */ + public array $result = []; - public function __construct($name) + public function __construct(string $name) { $this->name = $name; } public function geocodeQuery(GeocodeQuery $query): Collection { - return $this->returnResult([]); + return $this->returnResult(); } public function reverseQuery(ReverseQuery $query): Collection { - return $this->returnResult([]); + return $this->returnResult(); } public function getName(): string @@ -154,16 +168,17 @@ public function getName(): string return $this->name; } - public function getLimit() + public function getLimit(): void { } - public function limit($limit) + public function limit(int $limit): self { return $this; } - public function returnResult(array $data = []) + private function returnResult(): AddressCollection { + return new AddressCollection($this->result); } } diff --git a/Tests/Query/GeocodeQueryTest.php b/Tests/Query/GeocodeQueryTest.php index 60e4fa2c..e224fc3d 100644 --- a/Tests/Query/GeocodeQueryTest.php +++ b/Tests/Query/GeocodeQueryTest.php @@ -18,7 +18,7 @@ */ class GeocodeQueryTest extends TestCase { - public function testToString() + public function testToString(): void { $query = GeocodeQuery::create('foo'); $query = $query->withLocale('en'); @@ -26,10 +26,10 @@ public function testToString() $query = $query->withData('name', 'value'); $string = $query->__toString(); - $this->assertContains('GeocodeQuery', $string); - $this->assertContains('"text":"foo"', $string); - $this->assertContains('"locale":"en"', $string); - $this->assertContains('"limit":3', $string); - $this->assertContains('"name":"value"', $string); + $this->assertStringContainsString('GeocodeQuery', $string); + $this->assertStringContainsString('"text":"foo"', $string); + $this->assertStringContainsString('"locale":"en"', $string); + $this->assertStringContainsString('"limit":3', $string); + $this->assertStringContainsString('"name":"value"', $string); } } diff --git a/Tests/Query/ReverseQueryTest.php b/Tests/Query/ReverseQueryTest.php index 40272588..5c5baa47 100644 --- a/Tests/Query/ReverseQueryTest.php +++ b/Tests/Query/ReverseQueryTest.php @@ -18,7 +18,7 @@ */ class ReverseQueryTest extends TestCase { - public function testToString() + public function testToString(): void { $query = ReverseQuery::fromCoordinates(1, 2); $query = $query->withLocale('en'); @@ -26,11 +26,11 @@ public function testToString() $query = $query->withData('name', 'value'); $string = $query->__toString(); - $this->assertContains('ReverseQuery', $string); - $this->assertContains('"lat":1', $string); - $this->assertContains('"lng":2', $string); - $this->assertContains('"locale":"en"', $string); - $this->assertContains('"limit":3', $string); - $this->assertContains('"name":"value"', $string); + $this->assertStringContainsString('ReverseQuery', $string); + $this->assertStringContainsString('"lat":1', $string); + $this->assertStringContainsString('"lng":2', $string); + $this->assertStringContainsString('"locale":"en"', $string); + $this->assertStringContainsString('"limit":3', $string); + $this->assertStringContainsString('"name":"value"', $string); } } diff --git a/Tests/TimedGeocoderTest.php b/Tests/TimedGeocoderTest.php index 438a0f97..ca8b130b 100644 --- a/Tests/TimedGeocoderTest.php +++ b/Tests/TimedGeocoderTest.php @@ -15,6 +15,7 @@ use Geocoder\Model\AddressCollection; use Geocoder\Provider\Provider; use Geocoder\TimedGeocoder; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Stopwatch\Stopwatch; @@ -26,7 +27,7 @@ class TimedGeocoderTest extends TestCase private $stopwatch; /** - * @var Provider|\PHPUnit_Framework_MockObject_MockObject + * @var Provider&MockObject */ private $delegate; @@ -35,14 +36,14 @@ class TimedGeocoderTest extends TestCase */ private $geocoder; - protected function setUp() + protected function setUp(): void { $this->stopwatch = new Stopwatch(); $this->delegate = $this->getMockBuilder(Provider::class)->getMock(); $this->geocoder = new TimedGeocoder($this->delegate, $this->stopwatch); } - public function testGeocode() + public function testGeocode(): void { $this->delegate->expects($this->once()) ->method('geocodeQuery') @@ -53,7 +54,7 @@ public function testGeocode() $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__')); } - public function testGeocodeThrowsException() + public function testGeocodeThrowsException(): void { $this->delegate->expects($this->once()) ->method('geocodeQuery') @@ -69,7 +70,7 @@ public function testGeocodeThrowsException() $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__')); } - public function testReverse() + public function testReverse(): void { $this->delegate->expects($this->once()) ->method('reverseQuery') @@ -80,7 +81,7 @@ public function testReverse() $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__')); } - public function testReverseThrowsException() + public function testReverseThrowsException(): void { $this->delegate->expects($this->once()) ->method('reverseQuery') diff --git a/TimedGeocoder.php b/TimedGeocoder.php index 4abebc53..07186ee3 100644 --- a/TimedGeocoder.php +++ b/TimedGeocoder.php @@ -12,9 +12,9 @@ namespace Geocoder; +use Geocoder\Provider\Provider; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; -use Geocoder\Provider\Provider; use Symfony\Component\Stopwatch\Stopwatch; /** @@ -42,9 +42,6 @@ public function __construct(Provider $delegate, Stopwatch $stopwatch) $this->stopwatch = $stopwatch; } - /** - * {@inheritdoc} - */ public function geocodeQuery(GeocodeQuery $query): Collection { $this->stopwatch->start('geocode', 'geocoder'); @@ -62,9 +59,6 @@ public function geocodeQuery(GeocodeQuery $query): Collection return $result; } - /** - * {@inheritdoc} - */ public function reverseQuery(ReverseQuery $query): Collection { $this->stopwatch->start('reverse', 'geocoder'); @@ -82,7 +76,7 @@ public function reverseQuery(ReverseQuery $query): Collection return $result; } - public function __call($method, $args) + public function __call(string $method, array $args): mixed { return call_user_func_array([$this->delegate, $method], $args); } diff --git a/composer.json b/composer.json index 0af87bf6..122e72ec 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,12 @@ "name": "willdurand/geocoder", "type": "library", "description": "Common files for PHP Geocoder", - "keywords": ["geocoder", "geocoding", "abstraction", "geoip"], + "keywords": [ + "geocoder", + "geocoding", + "abstraction", + "geoip" + ], "homepage": "http://geocoder-php.org", "license": "MIT", "authors": [ @@ -12,18 +17,25 @@ } ], "require": { - "php": "^7.0" + "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^6.1", - "symfony/stopwatch": "~2.5", - "nyholm/nsa": "^1.1" + "nyholm/nsa": "^1.1", + "phpunit/phpunit": "^9.5", + "symfony/stopwatch": "~2.5 || ~5.0 || ~7.0" }, "suggest": { "symfony/stopwatch": "If you want to use the TimedGeocoder" }, + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, "autoload": { - "psr-4": { "Geocoder\\": "" }, + "psr-4": { + "Geocoder\\": "" + }, "exclude-from-classmap": [ "/Tests/" ] @@ -32,9 +44,9 @@ "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" }, - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" + "config": { + "allow-plugins": { + "php-http/discovery": false } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7581e875..d3ed6e38 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,24 @@ - - - - - - - - - ./Tests/ - - - - - - ./ - - ./Tests - ./vendor - - - + + + + ./ + + + ./Tests + ./vendor + + + + + + + + ./Tests/ + +