From 162cb1e08001c76081a47343f2b7f150bba9dcc5 Mon Sep 17 00:00:00 2001 From: Romain Monteil Date: Mon, 25 Sep 2023 11:00:24 +0200 Subject: [PATCH] Add types declarations --- src/BazingaGeocoderBundle.php | 5 +-- src/Command/GeocodeCommand.php | 5 +-- src/DataCollector/GeocoderDataCollector.php | 19 +++-------- .../BazingaGeocoderExtension.php | 10 ++---- .../Compiler/AddProvidersPass.php | 4 +-- .../Compiler/FactoryValidatorPass.php | 14 ++------ .../Compiler/ProfilerPass.php | 5 +-- src/DependencyInjection/Configuration.php | 13 ++----- src/Doctrine/ORM/GeocoderListener.php | 9 ++--- src/Mapping/ClassMetadata.php | 20 +++-------- src/Mapping/Driver/AnnotationDriver.php | 2 +- src/Mapping/Driver/DriverInterface.php | 4 +-- src/Plugin/FakeIpPlugin.php | 5 +-- src/Plugin/ProfilingPlugin.php | 19 ++++------- src/ProviderFactory/AbstractFactory.php | 2 +- src/ProviderFactory/AlgoliaFactory.php | 2 +- src/ProviderFactory/ArcGISOnlineFactory.php | 2 +- src/ProviderFactory/BingMapsFactory.php | 2 +- src/ProviderFactory/ChainFactory.php | 2 +- src/ProviderFactory/FreeGeoIpFactory.php | 2 +- src/ProviderFactory/GeoIP2Factory.php | 2 +- src/ProviderFactory/GeoIPsFactory.php | 2 +- src/ProviderFactory/GeoPluginFactory.php | 2 +- src/ProviderFactory/GeoipFactory.php | 2 +- src/ProviderFactory/GeonamesFactory.php | 2 +- src/ProviderFactory/GoogleMapsFactory.php | 2 +- .../GoogleMapsPlacesFactory.php | 2 +- src/ProviderFactory/HereFactory.php | 2 +- src/ProviderFactory/HostIpFactory.php | 2 +- src/ProviderFactory/IpInfoDbFactory.php | 2 +- src/ProviderFactory/IpInfoFactory.php | 2 +- src/ProviderFactory/IpstackFactory.php | 2 +- src/ProviderFactory/LocationIQFactory.php | 2 +- src/ProviderFactory/MapQuestFactory.php | 2 +- src/ProviderFactory/MapboxFactory.php | 2 +- src/ProviderFactory/MapzenFactory.php | 2 +- src/ProviderFactory/MaxMindBinaryFactory.php | 2 +- src/ProviderFactory/MaxMindFactory.php | 2 +- src/ProviderFactory/NominatimFactory.php | 2 +- src/ProviderFactory/OpenCageFactory.php | 2 +- .../OpenRouteServiceFactory.php | 2 +- src/ProviderFactory/PickPointFactory.php | 2 +- src/ProviderFactory/TomTomFactory.php | 2 +- src/ProviderFactory/YandexFactory.php | 2 +- src/Validator/Constraint/Address.php | 3 +- src/Validator/Constraint/AddressValidator.php | 14 ++------ tests/Command/GeocodeCommandTest.php | 2 +- tests/Functional/BundleInitializationTest.php | 14 ++++---- tests/Functional/CustomTestKernel.php | 6 ++-- tests/Functional/Helper/CacheHelperV7.php | 34 +++++-------------- tests/Functional/PluginInteractionTest.php | 4 +-- tests/Functional/ProviderFactoryTest.php | 4 +-- tests/Plugin/FakeIpPluginTest.php | 6 ++-- tests/PublicServicePass.php | 2 +- 54 files changed, 94 insertions(+), 189 deletions(-) diff --git a/src/BazingaGeocoderBundle.php b/src/BazingaGeocoderBundle.php index e9aba853..1dfc6209 100644 --- a/src/BazingaGeocoderBundle.php +++ b/src/BazingaGeocoderBundle.php @@ -23,10 +23,7 @@ */ class BazingaGeocoderBundle extends Bundle { - /** - * @return void - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/src/Command/GeocodeCommand.php b/src/Command/GeocodeCommand.php index 12b0c50c..eb69726b 100644 --- a/src/Command/GeocodeCommand.php +++ b/src/Command/GeocodeCommand.php @@ -34,10 +34,7 @@ public function __construct(ProviderAggregator $geocoder) parent::__construct(); } - /** - * @return void - */ - protected function configure() + protected function configure(): void { $this ->setName('geocoder:geocode') diff --git a/src/DataCollector/GeocoderDataCollector.php b/src/DataCollector/GeocoderDataCollector.php index 688932f0..48355442 100644 --- a/src/DataCollector/GeocoderDataCollector.php +++ b/src/DataCollector/GeocoderDataCollector.php @@ -34,20 +34,14 @@ public function __construct() $this->data['providers'] = []; } - /** - * @return void - */ - public function reset() + public function reset(): void { $this->instances = []; $this->data['queries'] = []; $this->data['providers'] = []; } - /** - * @return void - */ - public function collect(Request $request, Response $response, \Throwable $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null): void { if (!empty($this->data['queries'])) { // To avoid collection more that once. @@ -101,15 +95,10 @@ public function getProviders(): array */ public function getProviderQueries(string $provider): array { - return array_filter($this->data['queries'], static function ($data) use ($provider) { - return $data['providerName'] === $provider; - }); + return array_filter($this->data['queries'], static fn (array $data): bool => $data['providerName'] === $provider); } - /** - * @return void - */ - public function addInstance(ProfilingPlugin $instance) + public function addInstance(ProfilingPlugin $instance): void { $this->instances[] = $instance; $this->data['providers'][] = $instance->getName(); diff --git a/src/DependencyInjection/BazingaGeocoderExtension.php b/src/DependencyInjection/BazingaGeocoderExtension.php index a48ac76b..23507146 100644 --- a/src/DependencyInjection/BazingaGeocoderExtension.php +++ b/src/DependencyInjection/BazingaGeocoderExtension.php @@ -41,10 +41,8 @@ class BazingaGeocoderExtension extends Extension { /** * @param array $configs - * - * @return void */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $processor = new Processor(); $configuration = $this->getConfiguration($configs, $container); @@ -78,10 +76,8 @@ public function load(array $configs, ContainerBuilder $container) /** * @param array $config - * - * @return void */ - private function loadProviders(ContainerBuilder $container, array $config) + private function loadProviders(ContainerBuilder $container, array $config): void { foreach ($config['providers'] as $providerName => $providerConfig) { try { @@ -181,7 +177,7 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con ->addTag('bazinga_geocoder.profiling_plugin'); } - return array_map(static fn (string $id) => new Reference($id), $plugins); + return array_map(static fn (string $id): Reference => new Reference($id), $plugins); } /** diff --git a/src/DependencyInjection/Compiler/AddProvidersPass.php b/src/DependencyInjection/Compiler/AddProvidersPass.php index 526a94c1..a98e83fb 100644 --- a/src/DependencyInjection/Compiler/AddProvidersPass.php +++ b/src/DependencyInjection/Compiler/AddProvidersPass.php @@ -25,10 +25,8 @@ class AddProvidersPass implements CompilerPassInterface /** * Get all providers based on their tag (`bazinga_geocoder.provider`) and * register them. - * - * @return void */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition(ProviderAggregator::class)) { return; diff --git a/src/DependencyInjection/Compiler/FactoryValidatorPass.php b/src/DependencyInjection/Compiler/FactoryValidatorPass.php index 6f54fba5..98369d70 100644 --- a/src/DependencyInjection/Compiler/FactoryValidatorPass.php +++ b/src/DependencyInjection/Compiler/FactoryValidatorPass.php @@ -26,12 +26,9 @@ class FactoryValidatorPass implements CompilerPassInterface /** * @var string[] */ - private static $factoryServiceIds = []; + private static array $factoryServiceIds = []; - /** - * @return void - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { foreach (self::$factoryServiceIds as $id) { if (!$container->hasAlias($id) && !$container->hasDefinition($id)) { @@ -40,12 +37,7 @@ public function process(ContainerBuilder $container) } } - /** - * @param string $factoryServiceId - * - * @return void - */ - public static function addFactoryServiceId($factoryServiceId) + public static function addFactoryServiceId(string $factoryServiceId): void { self::$factoryServiceIds[] = $factoryServiceId; } diff --git a/src/DependencyInjection/Compiler/ProfilerPass.php b/src/DependencyInjection/Compiler/ProfilerPass.php index 3ba985db..0ad374b8 100644 --- a/src/DependencyInjection/Compiler/ProfilerPass.php +++ b/src/DependencyInjection/Compiler/ProfilerPass.php @@ -24,10 +24,7 @@ */ class ProfilerPass implements CompilerPassInterface { - /** - * @return void - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition(GeocoderDataCollector::class)) { return; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ca4d3da1..d80891d5 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -56,9 +56,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->arrayNode('fake_ip') ->beforeNormalization() ->ifString() - ->then(function ($value) { - return ['ip' => $value]; - }) + ->then(static fn (string $value): array => ['ip' => $value]) ->end() ->canBeEnabled() ->children() @@ -73,10 +71,7 @@ public function getConfigTreeBuilder(): TreeBuilder return $treeBuilder; } - /** - * @return ArrayNodeDefinition - */ - private function getProvidersNode() + private function getProvidersNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('providers'); $rootNode = $treeBuilder->getRootNode(); @@ -111,10 +106,8 @@ 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(); diff --git a/src/Doctrine/ORM/GeocoderListener.php b/src/Doctrine/ORM/GeocoderListener.php index 070d3a82..5683c97c 100644 --- a/src/Doctrine/ORM/GeocoderListener.php +++ b/src/Doctrine/ORM/GeocoderListener.php @@ -45,10 +45,7 @@ public function getSubscribedEvents(): array ]; } - /** - * @return void - */ - public function onFlush(OnFlushEventArgs $args) + public function onFlush(OnFlushEventArgs $args): void { $em = method_exists($args, 'getObjectManager') ? $args->getObjectManager() : $args->getEntityManager(); $uow = $em->getUnitOfWork(); @@ -92,10 +89,8 @@ public function onFlush(OnFlushEventArgs $args) /** * @param object $entity - * - * @return void */ - private function geocodeEntity(ClassMetadata $metadata, $entity) + private function geocodeEntity(ClassMetadata $metadata, $entity): void { if (null !== $metadata->addressGetter) { $address = $metadata->addressGetter->invoke($entity); diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index 891bffb2..2704247d 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -17,23 +17,11 @@ */ class ClassMetadata { - /** - * @var \ReflectionProperty - */ - public $addressProperty; + public \ReflectionProperty $addressProperty; - /** - * @var \ReflectionProperty - */ - public $latitudeProperty; + public \ReflectionProperty $latitudeProperty; - /** - * @var \ReflectionProperty - */ - public $longitudeProperty; + public \ReflectionProperty $longitudeProperty; - /** - * @var \ReflectionMethod - */ - public $addressGetter; + public ?\ReflectionMethod $addressGetter = null; } diff --git a/src/Mapping/Driver/AnnotationDriver.php b/src/Mapping/Driver/AnnotationDriver.php index e2ae8498..fae35cf5 100644 --- a/src/Mapping/Driver/AnnotationDriver.php +++ b/src/Mapping/Driver/AnnotationDriver.php @@ -37,7 +37,7 @@ public function isGeocodeable($object): bool return (bool) $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class); } - public function loadMetadataFromObject($object) + public function loadMetadataFromObject($object): ClassMetadata { $reflection = ClassUtils::newReflectionObject($object); diff --git a/src/Mapping/Driver/DriverInterface.php b/src/Mapping/Driver/DriverInterface.php index 0f38cfcc..fc91df58 100644 --- a/src/Mapping/Driver/DriverInterface.php +++ b/src/Mapping/Driver/DriverInterface.php @@ -23,8 +23,6 @@ public function isGeocodeable($object): bool; /** * @param object $object - * - * @return ClassMetadata */ - public function loadMetadataFromObject($object); + public function loadMetadataFromObject($object): ClassMetadata; } diff --git a/src/Plugin/FakeIpPlugin.php b/src/Plugin/FakeIpPlugin.php index 64a8f5ce..6f326a7b 100644 --- a/src/Plugin/FakeIpPlugin.php +++ b/src/Plugin/FakeIpPlugin.php @@ -41,10 +41,7 @@ public function __construct(?string $needle, string $replacement = null, bool $u } } - /** - * @return Promise - */ - public function handleQuery(Query $query, callable $next, callable $first) + public function handleQuery(Query $query, callable $next, callable $first): Promise { if (!$query instanceof GeocodeQuery) { return $next($query); diff --git a/src/Plugin/ProfilingPlugin.php b/src/Plugin/ProfilingPlugin.php index c2290779..641d2333 100644 --- a/src/Plugin/ProfilingPlugin.php +++ b/src/Plugin/ProfilingPlugin.php @@ -29,31 +29,28 @@ class ProfilingPlugin implements Plugin /** * @var list */ - private $queries = []; + private array $queries = []; /** - * @var string service id of the provider + * service id of the provider. */ - private $name; + private string $name; public function __construct(string $name) { $this->name = $name; } - /** - * @return Promise - */ - public function handleQuery(Query $query, callable $next, callable $first) + public function handleQuery(Query $query, callable $next, callable $first): Promise { $startTime = microtime(true); - return $next($query)->then(function (Collection $result) use ($query, $startTime) { + return $next($query)->then(function (Collection $result) use ($query, $startTime): Collection { $duration = (microtime(true) - $startTime) * 1000; $this->logQuery($query, $duration, $result); return $result; - }, function (Exception $exception) use ($query, $startTime) { + }, function (Exception $exception) use ($query, $startTime): void { $duration = (microtime(true) - $startTime) * 1000; $this->logQuery($query, $duration, $exception); @@ -63,10 +60,8 @@ public function handleQuery(Query $query, callable $next, callable $first) /** * @param mixed $result - * - * @return void */ - private function logQuery(Query $query, float $duration, $result = null) + private function logQuery(Query $query, float $duration, $result = null): void { if ($query instanceof GeocodeQuery) { $queryString = $query->getText(); diff --git a/src/ProviderFactory/AbstractFactory.php b/src/ProviderFactory/AbstractFactory.php index 069ca660..885ea4c7 100644 --- a/src/ProviderFactory/AbstractFactory.php +++ b/src/ProviderFactory/AbstractFactory.php @@ -53,7 +53,7 @@ public function createProvider(array $options = []): Provider return $this->getProvider($config); } - public static function validate(array $options, $providerName) + public static function validate(array $options, $providerName): void { static::verifyDependencies(); diff --git a/src/ProviderFactory/AlgoliaFactory.php b/src/ProviderFactory/AlgoliaFactory.php index 7bb28375..afa5873a 100644 --- a/src/ProviderFactory/AlgoliaFactory.php +++ b/src/ProviderFactory/AlgoliaFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new AlgoliaPlaces($httpClient, $config['api_key'], $config['app_id']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/ArcGISOnlineFactory.php b/src/ProviderFactory/ArcGISOnlineFactory.php index e35c1f36..d44a23e0 100644 --- a/src/ProviderFactory/ArcGISOnlineFactory.php +++ b/src/ProviderFactory/ArcGISOnlineFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new ArcGISOnline($httpClient, $config['source_country']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/BingMapsFactory.php b/src/ProviderFactory/BingMapsFactory.php index 03abecf9..1d7a6890 100644 --- a/src/ProviderFactory/BingMapsFactory.php +++ b/src/ProviderFactory/BingMapsFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new BingMaps($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/ChainFactory.php b/src/ProviderFactory/ChainFactory.php index 77eb4404..7d8c8f09 100644 --- a/src/ProviderFactory/ChainFactory.php +++ b/src/ProviderFactory/ChainFactory.php @@ -42,7 +42,7 @@ protected function getProvider(array $config): Provider return $provider; } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { parent::configureOptionResolver($resolver); diff --git a/src/ProviderFactory/FreeGeoIpFactory.php b/src/ProviderFactory/FreeGeoIpFactory.php index 53da263d..797d0465 100644 --- a/src/ProviderFactory/FreeGeoIpFactory.php +++ b/src/ProviderFactory/FreeGeoIpFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new FreeGeoIp($httpClient, $config['base_url']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/GeoIP2Factory.php b/src/ProviderFactory/GeoIP2Factory.php index c0f39ece..a2de2859 100644 --- a/src/ProviderFactory/GeoIP2Factory.php +++ b/src/ProviderFactory/GeoIP2Factory.php @@ -47,7 +47,7 @@ protected function getProvider(array $config): Provider return new GeoIP2($adapter); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'model' => GeoIP2Adapter::GEOIP2_MODEL_CITY, diff --git a/src/ProviderFactory/GeoIPsFactory.php b/src/ProviderFactory/GeoIPsFactory.php index b5a6f98b..e92afbb3 100644 --- a/src/ProviderFactory/GeoIPsFactory.php +++ b/src/ProviderFactory/GeoIPsFactory.php @@ -40,7 +40,7 @@ protected function getProvider(array $config): Provider return new GeoIPs($httplug, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/GeoPluginFactory.php b/src/ProviderFactory/GeoPluginFactory.php index 2162676b..7b0e0a1e 100644 --- a/src/ProviderFactory/GeoPluginFactory.php +++ b/src/ProviderFactory/GeoPluginFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new GeoPlugin($httpClient); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/GeoipFactory.php b/src/ProviderFactory/GeoipFactory.php index 03a874a7..33cb1a81 100644 --- a/src/ProviderFactory/GeoipFactory.php +++ b/src/ProviderFactory/GeoipFactory.php @@ -30,7 +30,7 @@ protected function getProvider(array $config): Provider return new Geoip(); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { } } diff --git a/src/ProviderFactory/GeonamesFactory.php b/src/ProviderFactory/GeonamesFactory.php index 81c1afbc..45c2ef7a 100644 --- a/src/ProviderFactory/GeonamesFactory.php +++ b/src/ProviderFactory/GeonamesFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new Geonames($httpClient, $config['username']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/GoogleMapsFactory.php b/src/ProviderFactory/GoogleMapsFactory.php index 2f548eaf..aea40c1f 100644 --- a/src/ProviderFactory/GoogleMapsFactory.php +++ b/src/ProviderFactory/GoogleMapsFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new GoogleMaps($httpClient, $config['region'], $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/GoogleMapsPlacesFactory.php b/src/ProviderFactory/GoogleMapsPlacesFactory.php index 82ac985b..e911012f 100644 --- a/src/ProviderFactory/GoogleMapsPlacesFactory.php +++ b/src/ProviderFactory/GoogleMapsPlacesFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new GoogleMapsPlaces($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/HereFactory.php b/src/ProviderFactory/HereFactory.php index 48309fba..56c03e06 100644 --- a/src/ProviderFactory/HereFactory.php +++ b/src/ProviderFactory/HereFactory.php @@ -46,7 +46,7 @@ protected function getProvider(array $config): Provider return new Here($httpClient, $config['app_id'], $config['app_code'], $config['use_cit']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/HostIpFactory.php b/src/ProviderFactory/HostIpFactory.php index 864e0229..5fa4a4d5 100644 --- a/src/ProviderFactory/HostIpFactory.php +++ b/src/ProviderFactory/HostIpFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new HostIp($httpClient); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/IpInfoDbFactory.php b/src/ProviderFactory/IpInfoDbFactory.php index d065f8d8..a3148174 100644 --- a/src/ProviderFactory/IpInfoDbFactory.php +++ b/src/ProviderFactory/IpInfoDbFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new IpInfoDb($httpClient, $config['api_key'], $config['precision']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/IpInfoFactory.php b/src/ProviderFactory/IpInfoFactory.php index 2420f79c..e1e0114e 100644 --- a/src/ProviderFactory/IpInfoFactory.php +++ b/src/ProviderFactory/IpInfoFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new IpInfo($httpClient); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/IpstackFactory.php b/src/ProviderFactory/IpstackFactory.php index 5396c90b..bd763db9 100644 --- a/src/ProviderFactory/IpstackFactory.php +++ b/src/ProviderFactory/IpstackFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new Ipstack($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/LocationIQFactory.php b/src/ProviderFactory/LocationIQFactory.php index ce793d3b..2d8d3f75 100644 --- a/src/ProviderFactory/LocationIQFactory.php +++ b/src/ProviderFactory/LocationIQFactory.php @@ -32,7 +32,7 @@ protected function getProvider(array $config): Provider return new LocationIQ($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/MapQuestFactory.php b/src/ProviderFactory/MapQuestFactory.php index 6207e28b..c633eff1 100644 --- a/src/ProviderFactory/MapQuestFactory.php +++ b/src/ProviderFactory/MapQuestFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new MapQuest($httpClient, $config['api_key'], $config['licensed']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/MapboxFactory.php b/src/ProviderFactory/MapboxFactory.php index 26229998..2fe66283 100644 --- a/src/ProviderFactory/MapboxFactory.php +++ b/src/ProviderFactory/MapboxFactory.php @@ -32,7 +32,7 @@ protected function getProvider(array $config): Provider return new Mapbox($httpClient, $config['api_key'], $config['country'], $config['mode']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/MapzenFactory.php b/src/ProviderFactory/MapzenFactory.php index ed74db6e..c41a013b 100644 --- a/src/ProviderFactory/MapzenFactory.php +++ b/src/ProviderFactory/MapzenFactory.php @@ -40,7 +40,7 @@ protected function getProvider(array $config): Provider return new Mapzen($httplug, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/MaxMindBinaryFactory.php b/src/ProviderFactory/MaxMindBinaryFactory.php index 009792f7..a1d90f9d 100644 --- a/src/ProviderFactory/MaxMindBinaryFactory.php +++ b/src/ProviderFactory/MaxMindBinaryFactory.php @@ -30,7 +30,7 @@ protected function getProvider(array $config): Provider return new MaxMindBinary($config['dat_file'], $config['open_flag']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'open_flag' => null, diff --git a/src/ProviderFactory/MaxMindFactory.php b/src/ProviderFactory/MaxMindFactory.php index c551f7b1..b2c070a2 100644 --- a/src/ProviderFactory/MaxMindFactory.php +++ b/src/ProviderFactory/MaxMindFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new MaxMind($httpClient, $config['api_key'], $config['endpoint']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/NominatimFactory.php b/src/ProviderFactory/NominatimFactory.php index 28dcd2a1..1a1f6a16 100644 --- a/src/ProviderFactory/NominatimFactory.php +++ b/src/ProviderFactory/NominatimFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new Nominatim($httpClient, $config['root_url'], $config['user_agent']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/OpenCageFactory.php b/src/ProviderFactory/OpenCageFactory.php index 65a9fc37..d65eb91b 100644 --- a/src/ProviderFactory/OpenCageFactory.php +++ b/src/ProviderFactory/OpenCageFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new OpenCage($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/OpenRouteServiceFactory.php b/src/ProviderFactory/OpenRouteServiceFactory.php index 86214fc5..4d6fd2c6 100644 --- a/src/ProviderFactory/OpenRouteServiceFactory.php +++ b/src/ProviderFactory/OpenRouteServiceFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new OpenRouteService($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/PickPointFactory.php b/src/ProviderFactory/PickPointFactory.php index 35c95aa2..5a1e8e34 100644 --- a/src/ProviderFactory/PickPointFactory.php +++ b/src/ProviderFactory/PickPointFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new PickPoint($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/TomTomFactory.php b/src/ProviderFactory/TomTomFactory.php index 27820e78..5d2e07e4 100644 --- a/src/ProviderFactory/TomTomFactory.php +++ b/src/ProviderFactory/TomTomFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new TomTom($httpClient, $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/ProviderFactory/YandexFactory.php b/src/ProviderFactory/YandexFactory.php index 9792c090..5b0ff37c 100644 --- a/src/ProviderFactory/YandexFactory.php +++ b/src/ProviderFactory/YandexFactory.php @@ -34,7 +34,7 @@ protected function getProvider(array $config): Provider return new Yandex($httpClient, $config['toponym'], $config['api_key']); } - protected static function configureOptionResolver(OptionsResolver $resolver) + protected static function configureOptionResolver(OptionsResolver $resolver): void { $resolver->setDefaults([ 'httplug_client' => null, diff --git a/src/Validator/Constraint/Address.php b/src/Validator/Constraint/Address.php index 36cfe125..59e92944 100644 --- a/src/Validator/Constraint/Address.php +++ b/src/Validator/Constraint/Address.php @@ -16,7 +16,6 @@ /** * @Annotation - * * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) * * @author Tomas Norkūnas @@ -50,7 +49,7 @@ class Address extends Constraint /** * @param string[]|null $options */ - public function __construct(array $options = null, string $message = null, array $groups = null, $payload = null) + public function __construct(array $options = null, string $message = null, array $groups = null, mixed $payload = null) { parent::__construct($options, $groups, $payload); diff --git a/src/Validator/Constraint/AddressValidator.php b/src/Validator/Constraint/AddressValidator.php index a01ff13a..46b992a5 100644 --- a/src/Validator/Constraint/AddressValidator.php +++ b/src/Validator/Constraint/AddressValidator.php @@ -25,10 +25,7 @@ */ class AddressValidator extends ConstraintValidator { - /** - * @var Provider - */ - protected $addressGeocoder; + protected Provider $addressGeocoder; public function __construct(Provider $addressGeocoder) { @@ -37,10 +34,8 @@ public function __construct(Provider $addressGeocoder) /** * @param mixed $value - * - * @return void */ - public function validate($value, Constraint $constraint) + public function validate($value, Constraint $constraint): void { if (!$constraint instanceof Address) { throw new UnexpectedTypeException($constraint, Address::class); @@ -67,10 +62,7 @@ public function validate($value, Constraint $constraint) } } - /** - * @return void - */ - private function buildViolation(Address $constraint, string $address) + private function buildViolation(Address $constraint, string $address): void { $this->context->buildViolation($constraint->message) ->setParameter('{{ address }}', $this->formatValue($address)) diff --git a/tests/Command/GeocodeCommandTest.php b/tests/Command/GeocodeCommandTest.php index f43ad536..6c7485b9 100644 --- a/tests/Command/GeocodeCommandTest.php +++ b/tests/Command/GeocodeCommandTest.php @@ -30,7 +30,7 @@ */ final class GeocodeCommandTest extends TestCase { - private static $address = '10 rue Gambetta, Paris, France'; + private static string $address = '10 rue Gambetta, Paris, France'; public function testExecute(): void { diff --git a/tests/Functional/BundleInitializationTest.php b/tests/Functional/BundleInitializationTest.php index c393c77a..1aac379b 100644 --- a/tests/Functional/BundleInitializationTest.php +++ b/tests/Functional/BundleInitializationTest.php @@ -53,7 +53,7 @@ protected static function createKernel(array $options = []): KernelInterface public function testInitBundle(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); }]); @@ -67,7 +67,7 @@ public function testInitBundle(): void public function testBundleWithOneProviderConfiguration(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/simple.yml'); }]); @@ -82,7 +82,7 @@ public function testBundleWithOneProviderConfiguration(): void public function testBundleWithCachedProvider(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/cache.yml'); }]); @@ -99,7 +99,7 @@ public function testBundleWithCachedProvider(): void public function testCacheLifetimeCanBeNull(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/cache_without_lifetime.yml'); }]); @@ -124,7 +124,7 @@ public function testCacheLifetimeCanBeNull(): void public function testBundleWithPluginsYml(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/service_plugin.yml'); }]); @@ -141,7 +141,7 @@ public function testBundleWithPluginsYml(): void public function testBundleWithPluginXml(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/service_plugin.xml'); }]); @@ -158,7 +158,7 @@ public function testBundleWithPluginXml(): void public function testBundleHasRegisteredDumpers(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); }]); diff --git a/tests/Functional/CustomTestKernel.php b/tests/Functional/CustomTestKernel.php index 393172c9..95e02d2e 100644 --- a/tests/Functional/CustomTestKernel.php +++ b/tests/Functional/CustomTestKernel.php @@ -29,9 +29,9 @@ */ class CustomTestKernel extends TestKernel { - private $warmupDir; + private ?string $warmupDir = null; - public function reboot(?string $warmupDir) + public function reboot(?string $warmupDir): void { $this->shutdown(); $this->warmupDir = $warmupDir; @@ -80,7 +80,7 @@ protected function getKernelParameters(): array /** * @internal */ - public function setAnnotatedClassCache(array $annotatedClasses) + public function setAnnotatedClassCache(array $annotatedClasses): void { file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map', sprintf(' static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->setClearCacheAfterShutdown(false); $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml'); @@ -59,7 +59,7 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void $country = $result->first()->getCountry()->getCode(); self::assertEquals('CN', $country); - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->setClearCacheAfterShutdown(false); $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml'); diff --git a/tests/Functional/ProviderFactoryTest.php b/tests/Functional/ProviderFactoryTest.php index cee76662..481ad8be 100644 --- a/tests/Functional/ProviderFactoryTest.php +++ b/tests/Functional/ProviderFactoryTest.php @@ -79,7 +79,7 @@ protected static function createKernel(array $options = []): KernelInterface */ public function testProviderConfiguration(string $class, array $serviceNames): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) use ($class) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) use ($class): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/provider/'.strtolower(substr($class, strrpos($class, '\\') + 1)).'.yml'); }]); @@ -137,7 +137,7 @@ public function getProviders(): iterable */ public function testProviderConfigurationWithDeprecatedHttplugClientOption(): void { - $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel): void { $kernel->addTestConfig(__DIR__.'/config/framework.yml'); $kernel->addTestConfig(__DIR__.'/config/deprecated_httplug_client_option.yml'); }]); diff --git a/tests/Plugin/FakeIpPluginTest.php b/tests/Plugin/FakeIpPluginTest.php index d24c18ee..04a2c527 100644 --- a/tests/Plugin/FakeIpPluginTest.php +++ b/tests/Plugin/FakeIpPluginTest.php @@ -28,7 +28,7 @@ public function testSimpleHandleQuery(): void $query = GeocodeQuery::create('127.0.0.1'); /** @var Query $query */ - $query = $fakeIpPlugin->handleQuery($query, function (Query $query) { return $query; }, function () {}); + $query = $fakeIpPlugin->handleQuery($query, static fn (Query $query): Query => $query, static function (): void {}); self::assertSame($query->getText(), '123.123.123.123'); } @@ -43,7 +43,7 @@ public function testEmptyLocalIpQuery(?string $localIp): void $query = GeocodeQuery::create('124.124.124.124'); /** @var Query $query */ - $query = $fakeIpPlugin->handleQuery($query, function (Query $query) { return $query; }, function () {}); + $query = $fakeIpPlugin->handleQuery($query, static fn (Query $query): Query => $query, static function (): void {}); self::assertSame($query->getText(), '123.123.123.123'); } @@ -54,7 +54,7 @@ public function testHandleQueryUsingFaker(): void $query = GeocodeQuery::create('127.0.0.1'); /** @var Query $query */ - $query = $fakeIpPlugin->handleQuery($query, function (Query $query) { return $query; }, function () {}); + $query = $fakeIpPlugin->handleQuery($query, static fn (Query $query): Query => $query, static function (): void {}); self::assertNotSame($query->getText(), '192.168.1.1'); } diff --git a/tests/PublicServicePass.php b/tests/PublicServicePass.php index 8f430b6a..69abc3c0 100644 --- a/tests/PublicServicePass.php +++ b/tests/PublicServicePass.php @@ -31,7 +31,7 @@ public function __construct(string $regex = '|.*|') $this->regex = $regex; } - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { foreach ($container->getDefinitions() as $id => $definition) { if (preg_match($this->regex, $id)) {