diff --git a/src/DependencyInjection/BazingaGeocoderExtension.php b/src/DependencyInjection/BazingaGeocoderExtension.php index 2647d23..7cf3e3c 100644 --- a/src/DependencyInjection/BazingaGeocoderExtension.php +++ b/src/DependencyInjection/BazingaGeocoderExtension.php @@ -209,7 +209,7 @@ private function findReferences(array $options): array foreach ($options as $key => $value) { if (is_array($value)) { $options[$key] = $this->findReferences($value); - } elseif ('_service' === substr((string) $key, -8) || 0 === strpos((string) $value, '@') || 'service' === $key) { + } elseif (str_ends_with((string) $key, '_service') || str_starts_with((string) $value, '@') || 'service' === $key) { $options[$key] = new Reference(ltrim($value, '@')); } } @@ -217,10 +217,7 @@ private function findReferences(array $options): array return $options; } - /** - * @param mixed $factoryClass - */ - private function implementsProviderFactory($factoryClass): bool + private function implementsProviderFactory(mixed $factoryClass): bool { if (false === $interfaces = class_implements($factoryClass)) { return false; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 216465b..61e9b7d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -83,10 +83,7 @@ public function getConfigTreeBuilder(): TreeBuilder return $treeBuilder; } - /** - * @return ArrayNodeDefinition - */ - private function getProvidersNode() + private function getProvidersNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('providers'); $rootNode = $treeBuilder->getRootNode(); @@ -121,16 +118,13 @@ private function getProvidersNode() /** * Create plugin node of a client. - * - * @return ArrayNodeDefinition The plugin node */ - private function createClientPluginNode() + private function createClientPluginNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('plugins'); $rootNode = $treeBuilder->getRootNode(); assert($rootNode instanceof ArrayNodeDefinition); - /** @var ArrayNodeDefinition $pluginList */ $pluginList = $rootNode ->info('A list of plugin service ids. The order is important.') ->arrayPrototype() diff --git a/src/ProviderFactory/GeoIP2Factory.php b/src/ProviderFactory/GeoIP2Factory.php index 34814d2..ffa34c8 100644 --- a/src/ProviderFactory/GeoIP2Factory.php +++ b/src/ProviderFactory/GeoIP2Factory.php @@ -18,6 +18,7 @@ use GeoIp2\Database\Reader; use GeoIp2\ProviderInterface; use GeoIp2\WebService\Client; +use MaxMind\Db\Reader\InvalidDatabaseException; use Symfony\Component\OptionsResolver\OptionsResolver; final class GeoIP2Factory extends AbstractFactory @@ -28,6 +29,8 @@ final class GeoIP2Factory extends AbstractFactory /** * @param array{provider: string, provider_service: ?ProviderInterface, model: string, user_id: string|int|null, license_key: string|null, locales: list, webservice_options: array, database_filename: ?string} $config + * + * @throws InvalidDatabaseException */ protected function getProvider(array $config): Provider { diff --git a/src/ProviderFactory/PluginProviderFactory.php b/src/ProviderFactory/PluginProviderFactory.php index 2857610..5a68b16 100644 --- a/src/ProviderFactory/PluginProviderFactory.php +++ b/src/ProviderFactory/PluginProviderFactory.php @@ -14,6 +14,7 @@ use Geocoder\Plugin\Plugin; use Geocoder\Plugin\PluginProvider; +use Geocoder\Provider\Provider; /** * This factory creates a PluginProvider. @@ -23,19 +24,17 @@ final class PluginProviderFactory { /** - * @param Plugin[] $plugins - * @param ProviderFactoryInterface|callable $factory - * @param array $config config to the client factory - * @param array{max_restarts?: int<0, max>} $pluginProviderOptions config forwarded to the PluginProvider + * @param Plugin[] $plugins + * @param callable(array):Provider|ProviderFactoryInterface $factory + * @param array $config config to the client factory + * @param array{max_restarts?: int<0, max>} $pluginProviderOptions config forwarded to the PluginProvider */ - public static function createPluginProvider(array $plugins, $factory, array $config, array $pluginProviderOptions = []): PluginProvider + public static function createPluginProvider(array $plugins, callable|ProviderFactoryInterface $factory, array $config, array $pluginProviderOptions = []): PluginProvider { if ($factory instanceof ProviderFactoryInterface) { $client = $factory->createProvider($config); - } elseif (is_callable($factory)) { - $client = $factory($config); } else { - throw new \RuntimeException(sprintf('Second argument to PluginProviderFactory::createPluginProvider must be a "%s" or a callable.', ProviderFactoryInterface::class)); + $client = $factory($config); } return new PluginProvider($client, $plugins, $pluginProviderOptions); diff --git a/src/Validator/Constraint/Address.php b/src/Validator/Constraint/Address.php index 7ceb448..e6578fd 100644 --- a/src/Validator/Constraint/Address.php +++ b/src/Validator/Constraint/Address.php @@ -29,24 +29,9 @@ class Address extends Constraint self::INVALID_ADDRESS_ERROR => 'INVALID_ADDRESS_ERROR', ]; - /** - * @var string - */ - public $service = AddressValidator::class; - - /** - * @var string - */ - public $message = 'Address {{ address }} is not valid.'; - - /** - * @param string[]|null $options - */ - public function __construct(?array $options = null, ?string $message = null, ?array $groups = null, $payload = null) + public function __construct(public string $service = AddressValidator::class, public string $message = 'Address {{ address }} is not valid.', ?array $groups = null, $payload = null) { - parent::__construct($options, $groups, $payload); - - $this->message = $message ?? $this->message; + parent::__construct(null, $groups, $payload); } public function validatedBy(): string diff --git a/tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php b/tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php index b6c43b7..2656279 100644 --- a/tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php +++ b/tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php @@ -33,9 +33,6 @@ protected function tearDown(): void { $reflection = new \ReflectionObject($this->compilerPass); $prop = $reflection->getProperty('factoryServiceIds'); - if (PHP_VERSION_ID < 80100) { - $prop->setAccessible(true); - } $prop->setValue(null, []); } diff --git a/tests/Functional/BundleInitializationTest.php b/tests/Functional/BundleInitializationTest.php index 74d427e..b6e8030 100644 --- a/tests/Functional/BundleInitializationTest.php +++ b/tests/Functional/BundleInitializationTest.php @@ -52,10 +52,7 @@ public function testInitBundle(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); }]); $container = self::getContainer(); @@ -70,11 +67,7 @@ public function testBundleWithOneProviderConfiguration(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/simple.yml'); }]); @@ -90,11 +83,7 @@ public function testBundleWithCachedProvider(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/cache.yml'); }]); @@ -112,11 +101,7 @@ public function testCacheLifetimeCanBeNull(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/cache_without_lifetime.yml'); }]); @@ -142,11 +127,7 @@ public function testBundleWithPluginsYml(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/service_plugin.yml'); }]); @@ -164,10 +145,7 @@ public function testBundleHasRegisteredDumpers(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); }]); $container = self::getContainer(); diff --git a/tests/Functional/GeocodeEntityListenerTest.php b/tests/Functional/GeocodeEntityListenerTest.php index a3e68b3..25eb301 100644 --- a/tests/Functional/GeocodeEntityListenerTest.php +++ b/tests/Functional/GeocodeEntityListenerTest.php @@ -106,11 +106,7 @@ public function testPersistForProperty(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/listener.yml'); }]); @@ -145,11 +141,7 @@ public function testPersistForGetter(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/listener.yml'); }]); @@ -184,11 +176,7 @@ public function testPersistForStringableGetter(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/listener.yml'); }]); @@ -223,11 +211,7 @@ public function testPersistForInvalidGetter(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/listener.yml'); }]); @@ -255,11 +239,7 @@ public function testPersistForEmptyProperty(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/listener.yml'); }]); @@ -287,11 +267,7 @@ public function testDoesNotGeocodeIfAddressNotChanged(): void { self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/listener.yml'); }]); diff --git a/tests/Functional/Helper/CacheHelper.php b/tests/Functional/Helper/CacheHelper.php index 67df280..9a248ef 100644 --- a/tests/Functional/Helper/CacheHelper.php +++ b/tests/Functional/Helper/CacheHelper.php @@ -14,24 +14,49 @@ use Psr\SimpleCache\CacheInterface; -if (PHP_VERSION_ID >= 80000) { - /** - * @internal - * - * @author Tobias Nyholm - */ - class CacheHelper implements CacheInterface - { - use CacheHelperV8; - } -} else { - /** - * @internal - * - * @author Tobias Nyholm - */ - class CacheHelper implements CacheInterface - { - use CacheHelperV7; +/** + * @internal + * + * @author Tobias Nyholm + */ +class CacheHelper implements CacheInterface +{ + public function get(string $key, mixed $default = null): mixed + { + } + + public function set(string $key, mixed $value, int|\DateInterval|null $ttl = null): bool + { + return true; + } + + public function delete(string $key): bool + { + return true; + } + + public function clear(): bool + { + return true; + } + + public function getMultiple(iterable $keys, mixed $default = null): iterable + { + return []; + } + + public function setMultiple(iterable $values, int|\DateInterval|null $ttl = null): bool + { + return true; + } + + public function deleteMultiple(iterable $keys): bool + { + return true; + } + + public function has(string $key): bool + { + return false; } } diff --git a/tests/Functional/Helper/CacheHelperV7.php b/tests/Functional/Helper/CacheHelperV7.php deleted file mode 100644 index fb50fb0..0000000 --- a/tests/Functional/Helper/CacheHelperV7.php +++ /dev/null @@ -1,84 +0,0 @@ - - */ -trait CacheHelperV7 -{ - /** - * @return mixed - */ - public function get($key, $default = null) - { - } - - /** - * @return bool - */ - public function set($key, $value, $ttl = null) - { - return true; - } - - /** - * @return bool - */ - public function delete($key) - { - return true; - } - - /** - * @return bool - */ - public function clear() - { - return true; - } - - /** - * @return iterable - */ - public function getMultiple($keys, $default = null) - { - return []; - } - - /** - * @return bool - */ - public function setMultiple($values, $ttl = null) - { - return true; - } - - /** - * @return bool - */ - public function deleteMultiple($keys) - { - return true; - } - - /** - * @return bool - */ - public function has($key) - { - return false; - } -} diff --git a/tests/Functional/Helper/CacheHelperV8.php b/tests/Functional/Helper/CacheHelperV8.php deleted file mode 100644 index 939ef94..0000000 --- a/tests/Functional/Helper/CacheHelperV8.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -trait CacheHelperV8 -{ - public function get(string $key, mixed $default = null): mixed - { - } - - public function set(string $key, mixed $value, int|\DateInterval|null $ttl = null): bool - { - return true; - } - - public function delete(string $key): bool - { - return true; - } - - public function clear(): bool - { - return true; - } - - public function getMultiple(iterable $keys, mixed $default = null): iterable - { - return []; - } - - public function setMultiple(iterable $values, int|\DateInterval|null $ttl = null): bool - { - return true; - } - - public function deleteMultiple(iterable $keys): bool - { - return true; - } - - public function has(string $key): bool - { - return false; - } -} diff --git a/tests/Functional/PluginInteractionTest.php b/tests/Functional/PluginInteractionTest.php index 27a3381..4ee904c 100644 --- a/tests/Functional/PluginInteractionTest.php +++ b/tests/Functional/PluginInteractionTest.php @@ -57,11 +57,7 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->setClearCacheAfterShutdown(false); $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml'); $kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_cn.yml'); }]); @@ -83,11 +79,7 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { $kernel->setClearCacheAfterShutdown(false); $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml'); $kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_fr.yml'); }]); diff --git a/tests/Functional/ProviderFactoryTest.php b/tests/Functional/ProviderFactoryTest.php index 880e0b4..0eb5695 100644 --- a/tests/Functional/ProviderFactoryTest.php +++ b/tests/Functional/ProviderFactoryTest.php @@ -74,11 +74,7 @@ public function testProviderConfiguration(string $class, array $serviceNames): v { self::bootKernel(['config' => static function (TestKernel $kernel) use ($class) { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); - - if ($kernel::VERSION_ID >= 60000) { - $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); - } - + $kernel->addTestConfig(__DIR__.'/config/framework_sf'.$kernel::MAJOR_VERSION.'.yml'); $kernel->addTestConfig(__DIR__.'/config/provider/'.strtolower(substr($class, strrpos($class, '\\') + 1)).'.yml'); }]); @@ -94,7 +90,7 @@ public function testProviderConfiguration(string $class, array $serviceNames): v /** * @return iterable}> */ - public function getProviders(): iterable + public static function getProviders(): iterable { yield [AlgoliaPlaces::class, ['empty', 'acme']]; yield [ArcGISOnline::class, ['empty', 'acme']]; diff --git a/tests/Plugin/FakeIpPluginTest.php b/tests/Plugin/FakeIpPluginTest.php index b9677d1..4c8f194 100644 --- a/tests/Plugin/FakeIpPluginTest.php +++ b/tests/Plugin/FakeIpPluginTest.php @@ -30,7 +30,7 @@ public function testSimpleHandleQuery(): void /** @var Query $query */ $query = $fakeIpPlugin->handleQuery($query, function (Query $query) { return $query; }, function () {}); - self::assertSame($query->getText(), '123.123.123.123'); + self::assertSame('123.123.123.123', $query->getText()); } /** @@ -45,7 +45,7 @@ public function testEmptyLocalIpQuery(?string $localIp): void /** @var Query $query */ $query = $fakeIpPlugin->handleQuery($query, function (Query $query) { return $query; }, function () {}); - self::assertSame($query->getText(), '123.123.123.123'); + self::assertSame('123.123.123.123', $query->getText()); } public function testHandleQueryUsingFaker(): void @@ -56,6 +56,6 @@ public function testHandleQueryUsingFaker(): void /** @var Query $query */ $query = $fakeIpPlugin->handleQuery($query, function (Query $query) { return $query; }, function () {}); - self::assertNotSame($query->getText(), '192.168.1.1'); + self::assertNotSame('192.168.1.1', $query->getText()); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4dda63d..510e3cd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,7 +12,7 @@ if (!$loader = @require_once __DIR__.'/../vendor/autoload.php') { exit('You must set up the project dependencies, run the following commands: -wget http://getcomposer.org/composer.phar +wget https://getcomposer.org/composer.phar php composer.phar install --dev --prefer-source '); }