diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index 4d7a09d4..00000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,196 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Parameter \\#1 \\$name of method Geocoder\\\\ProviderAggregator\\:\\:using\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Command/GeocodeCommand.php - - - - message: "#^Parameter \\#1 \\$string of function strtolower expects string, string\\|null given\\.$#" - count: 1 - path: src/Command/GeocodeCommand.php - - - - message: "#^Parameter \\#1 \\$text of static method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:create\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Command/GeocodeCommand.php - - - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" - count: 3 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot access offset 'aliases' on mixed\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot access offset 'enabled' on mixed\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot access offset 'factory' on mixed\\.$#" - count: 5 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot access offset 'id' on mixed\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot access offset 'options' on mixed\\.$#" - count: 4 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot access offset 'reference' on mixed\\.$#" - count: 2 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot call static method validate\\(\\) on mixed\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Cannot cast mixed to string\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$alias of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:setAlias\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: Symfony\\\\Component\\\\DependencyInjection\\\\Reference given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$id of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:getDefinition\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$object_or_class of function class_implements expects object\\|string, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$options of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:findReferences\\(\\) expects array\\, mixed given\\.$#" - count: 2 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array\\, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Part \\$providerName \\(mixed\\) of encapsed string cannot be cast to string\\.$#" - count: 1 - path: src/DependencyInjection/BazingaGeocoderExtension.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:end\\(\\)\\.$#" - count: 2 - path: src/DependencyInjection/Configuration.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:variableNode\\(\\)\\.$#" - count: 1 - path: src/DependencyInjection/Configuration.php - - - - message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Event\\\\OnFlushEventArgs\\:\\:getEntityManager\\(\\)\\.$#" - count: 1 - path: src/Doctrine/ORM/GeocoderListener.php - - - - message: "#^Cannot call method getLatitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#" - count: 1 - path: src/Doctrine/ORM/GeocoderListener.php - - - - message: "#^Cannot call method getLongitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#" - count: 1 - path: src/Doctrine/ORM/GeocoderListener.php - - - - message: "#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AnnotationDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#" - count: 1 - path: src/Mapping/Driver/AnnotationDriver.php - - - - message: "#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AttributeDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#" - count: 1 - path: src/Mapping/Driver/AttributeDriver.php - - - - message: "#^Parameter \\#1 \\$text of method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:withText\\(\\) expects string, string\\|null given\\.$#" - count: 1 - path: src/Plugin/FakeIpPlugin.php - - - - message: "#^Parameter \\#2 \\$replace of function str_replace expects array\\|string, string\\|null given\\.$#" - count: 1 - path: src/Plugin/FakeIpPlugin.php - - - - message: "#^Parameter \\#1 \\$accountId of class GeoIp2\\\\WebService\\\\Client constructor expects int, int\\|null given\\.$#" - count: 1 - path: src/ProviderFactory/GeoIP2Factory.php - - - - message: "#^Parameter \\#1 \\$filename of class GeoIp2\\\\Database\\\\Reader constructor expects string, string\\|null given\\.$#" - count: 1 - path: src/ProviderFactory/GeoIP2Factory.php - - - - message: "#^Parameter \\#1 \\$geoIpProvider of class Geocoder\\\\Provider\\\\GeoIP2\\\\GeoIP2Adapter constructor expects GeoIp2\\\\ProviderInterface, GeoIp2\\\\ProviderInterface\\|null given\\.$#" - count: 1 - path: src/ProviderFactory/GeoIP2Factory.php - - - - message: "#^Parameter \\#2 \\$licenseKey of class GeoIp2\\\\WebService\\\\Client constructor expects string, string\\|null given\\.$#" - count: 1 - path: src/ProviderFactory/GeoIP2Factory.php - - - - message: "#^Class Geocoder\\\\Provider\\\\Geoip\\\\Geoip not found\\.$#" - count: 1 - path: src/ProviderFactory/GeoipFactory.php - - - - message: "#^Instantiated class Geocoder\\\\Provider\\\\Geoip\\\\Geoip not found\\.$#" - count: 1 - path: src/ProviderFactory/GeoipFactory.php - - - - message: "#^Method Bazinga\\\\GeocoderBundle\\\\ProviderFactory\\\\GeoipFactory\\:\\:getProvider\\(\\) should return Geocoder\\\\Provider\\\\Provider but returns Geocoder\\\\Provider\\\\Geoip\\\\Geoip\\.$#" - count: 1 - path: src/ProviderFactory/GeoipFactory.php diff --git a/phpstan-baseline.php b/phpstan-baseline.php new file mode 100644 index 00000000..d4aaebae --- /dev/null +++ b/phpstan-baseline.php @@ -0,0 +1,229 @@ + '#^Parameter \\#1 \\$name of method Geocoder\\\\ProviderAggregator\\:\\:using\\(\\) expects string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Command/GeocodeCommand.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$string of function strtolower expects string, string\\|null given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Command/GeocodeCommand.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$text of static method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:create\\(\\) expects string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Command/GeocodeCommand.php', +]; +$ignoreErrors[] = [ + // identifier: foreach.nonIterable + 'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#', + 'count' => 3, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: offsetAccess.nonOffsetAccessible + 'message' => '#^Cannot access offset \'aliases\' on mixed\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: offsetAccess.nonOffsetAccessible + 'message' => '#^Cannot access offset \'enabled\' on mixed\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: offsetAccess.nonOffsetAccessible + 'message' => '#^Cannot access offset \'factory\' on mixed\\.$#', + 'count' => 5, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: offsetAccess.nonOffsetAccessible + 'message' => '#^Cannot access offset \'id\' on mixed\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: offsetAccess.nonOffsetAccessible + 'message' => '#^Cannot access offset \'options\' on mixed\\.$#', + 'count' => 4, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: offsetAccess.nonOffsetAccessible + 'message' => '#^Cannot access offset \'reference\' on mixed\\.$#', + 'count' => 2, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: staticMethod.nonObject + 'message' => '#^Cannot call static method validate\\(\\) on mixed\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: cast.string + 'message' => '#^Cannot cast mixed to string\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$alias of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:setAlias\\(\\) expects string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: Symfony\\\\Component\\\\DependencyInjection\\\\Reference given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$id of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:getDefinition\\(\\) expects string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$object_or_class of function class_implements expects object\\|string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$options of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:findReferences\\(\\) expects array\\, mixed given\\.$#', + 'count' => 2, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array\\, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: encapsedStringPart.nonString + 'message' => '#^Part \\$providerName \\(mixed\\) of encapsed string cannot be cast to string\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php', +]; +$ignoreErrors[] = [ + // identifier: method.notFound + 'message' => '#^Call to an undefined method Doctrine\\\\ORM\\\\Event\\\\OnFlushEventArgs\\:\\:getEntityManager\\(\\)\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Doctrine/ORM/GeocoderListener.php', +]; +$ignoreErrors[] = [ + // identifier: method.nonObject + 'message' => '#^Cannot call method getLatitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Doctrine/ORM/GeocoderListener.php', +]; +$ignoreErrors[] = [ + // identifier: method.nonObject + 'message' => '#^Cannot call method getLongitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Doctrine/ORM/GeocoderListener.php', +]; +$ignoreErrors[] = [ + // identifier: missingType.generics + 'message' => '#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AnnotationDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#', + 'count' => 1, + 'path' => __DIR__.'/src/Mapping/Driver/AnnotationDriver.php', +]; +$ignoreErrors[] = [ + // identifier: missingType.generics + 'message' => '#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AttributeDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#', + 'count' => 1, + 'path' => __DIR__.'/src/Mapping/Driver/AttributeDriver.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$text of method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:withText\\(\\) expects string, string\\|null given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Plugin/FakeIpPlugin.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#2 \\$replace of function str_replace expects array\\|string, string\\|null given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/Plugin/FakeIpPlugin.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$accountId of class GeoIp2\\\\WebService\\\\Client constructor expects int, int\\|null given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$filename of class GeoIp2\\\\Database\\\\Reader constructor expects string, string\\|null given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#1 \\$geoIpProvider of class Geocoder\\\\Provider\\\\GeoIP2\\\\GeoIP2Adapter constructor expects GeoIp2\\\\ProviderInterface, GeoIp2\\\\ProviderInterface\\|null given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php', +]; +$ignoreErrors[] = [ + // identifier: argument.type + 'message' => '#^Parameter \\#2 \\$licenseKey of class GeoIp2\\\\WebService\\\\Client constructor expects string, string\\|null given\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php', +]; +$ignoreErrors[] = [ + // identifier: class.notFound + 'message' => '#^Class Geocoder\\\\Provider\\\\Geoip\\\\Geoip not found\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/ProviderFactory/GeoipFactory.php', +]; +$ignoreErrors[] = [ + // identifier: class.notFound + 'message' => '#^Instantiated class Geocoder\\\\Provider\\\\Geoip\\\\Geoip not found\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/ProviderFactory/GeoipFactory.php', +]; +$ignoreErrors[] = [ + // identifier: return.type + 'message' => '#^Method Bazinga\\\\GeocoderBundle\\\\ProviderFactory\\\\GeoipFactory\\:\\:getProvider\\(\\) should return Geocoder\\\\Provider\\\\Provider but returns Geocoder\\\\Provider\\\\Geoip\\\\Geoip\\.$#', + 'count' => 1, + 'path' => __DIR__.'/src/ProviderFactory/GeoipFactory.php', +]; + +return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; diff --git a/phpstan.neon.dist b/phpstan.dist.neon similarity index 83% rename from phpstan.neon.dist rename to phpstan.dist.neon index 7b4f667f..b03a2139 100644 --- a/phpstan.neon.dist +++ b/phpstan.dist.neon @@ -1,5 +1,5 @@ includes: - - phpstan-baseline.neon + - phpstan-baseline.php parameters: bootstrapFiles: diff --git a/src/BazingaGeocoderBundle.php b/src/BazingaGeocoderBundle.php index e9aba853..afbbf8b5 100644 --- a/src/BazingaGeocoderBundle.php +++ b/src/BazingaGeocoderBundle.php @@ -26,7 +26,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/DataCollector/GeocoderDataCollector.php b/src/DataCollector/GeocoderDataCollector.php index 0a8ec829..d9bfe536 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. diff --git a/src/ProviderFactory/GeoIPsFactory.php b/src/ProviderFactory/GeoIPsFactory.php deleted file mode 100644 index b5a6f98b..00000000 --- a/src/ProviderFactory/GeoIPsFactory.php +++ /dev/null @@ -1,53 +0,0 @@ - GeoIPs::class, 'packageName' => 'geocoder-php/geoips-provider'], - ]; - - /** - * @param array{api_key: string, httplug_client: ?HttpClient} $config - */ - protected function getProvider(array $config): Provider - { - @trigger_error('Bazinga\GeocoderBundle\ProviderFactory\GeoIPsFactory is deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/965', E_USER_DEPRECATED); - - $httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find(); - assert($httplug instanceof HttpClient); - - return new GeoIPs($httplug, $config['api_key']); - } - - protected static function configureOptionResolver(OptionsResolver $resolver) - { - $resolver->setDefaults([ - 'httplug_client' => null, - ]); - - $resolver->setRequired('api_key'); - $resolver->setAllowedTypes('httplug_client', [HttpClient::class, 'null']); - $resolver->setAllowedTypes('api_key', ['string']); - } -} diff --git a/src/ProviderFactory/MapzenFactory.php b/src/ProviderFactory/MapzenFactory.php deleted file mode 100644 index ed74db6e..00000000 --- a/src/ProviderFactory/MapzenFactory.php +++ /dev/null @@ -1,53 +0,0 @@ - Mapzen::class, 'packageName' => 'geocoder-php/mapzen-provider'], - ]; - - /** - * @param array{api_key: string, httplug_client: ?HttpClient} $config - */ - protected function getProvider(array $config): Provider - { - @trigger_error('Bazinga\GeocoderBundle\ProviderFactory\MapzenFactory is deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/808', E_USER_DEPRECATED); - - $httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find(); - assert($httplug instanceof HttpClient); - - return new Mapzen($httplug, $config['api_key']); - } - - protected static function configureOptionResolver(OptionsResolver $resolver) - { - $resolver->setDefaults([ - 'httplug_client' => null, - ]); - - $resolver->setRequired('api_key'); - $resolver->setAllowedTypes('httplug_client', [HttpClient::class, 'null']); - $resolver->setAllowedTypes('api_key', ['string']); - } -} diff --git a/tests/Functional/CustomTestKernel.php b/tests/Functional/CustomTestKernel.php index e32e3fb2..d0d391be 100644 --- a/tests/Functional/CustomTestKernel.php +++ b/tests/Functional/CustomTestKernel.php @@ -30,7 +30,7 @@ class CustomTestKernel extends TestKernel { private $warmupDir; - public function reboot(?string $warmupDir) + public function reboot(?string $warmupDir): void { $this->shutdown(); $this->warmupDir = $warmupDir; @@ -65,6 +65,10 @@ protected function getKernelParameters(): array 'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), 'kernel.environment' => $this->environment, 'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%', + 'kernel.runtime_mode' => '%env(query_string:default:container.runtime_mode:APP_RUNTIME_MODE)%', + 'kernel.runtime_mode.web' => '%env(bool:default::key:web:default:kernel.runtime_mode:)%', + 'kernel.runtime_mode.cli' => '%env(not:default:kernel.runtime_mode.web:)%', + 'kernel.runtime_mode.worker' => '%env(bool:default::key:worker:default:kernel.runtime_mode:)%', 'kernel.debug' => $this->debug, 'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir, 'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir, @@ -73,6 +77,7 @@ protected function getKernelParameters(): array 'kernel.bundles_metadata' => $bundlesMetadata, 'kernel.charset' => $this->getCharset(), 'kernel.container_class' => $this->getContainerClass(), + 'kernel.share_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), ]; } diff --git a/tests/Functional/PluginInteractionTest.php b/tests/Functional/PluginInteractionTest.php index 77a6fe70..3f7db7e6 100644 --- a/tests/Functional/PluginInteractionTest.php +++ b/tests/Functional/PluginInteractionTest.php @@ -14,7 +14,12 @@ use Bazinga\GeocoderBundle\BazingaGeocoderBundle; use Geocoder\Query\GeocodeQuery; +use Http\Message\RequestMatcher\RequestMatcher; +use Http\Mock\Client; use Nyholm\BundleTest\TestKernel; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; @@ -51,11 +56,33 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void } $kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml'); - $kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_cn.yml'); + $kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_cn.yml'); }]); $kernel->setClearCacheAfterShutdown(false); $container = self::getContainer(); + $httpClient = $container->get(Client::class); + $httpClient->on(new RequestMatcher(), function (RequestInterface $request) { + if ('https://freegeoip.app/json/123.123.123.128' === (string) $request->getUri()) { + $stream = $this->createMock(StreamInterface::class); + $stream->expects(self::once()) + ->method('__toString') + ->willReturn('{"ip":"123.123.123.128","country_code":"CN","country_name":"China","region_code":"CN-BJ","region_name":"Beijing","city":"Beijing","zip_code":"100006","time_zone":"Asia\/Shanghai","latitude":39.907501220703125,"longitude":116.39710235595703,"metro_code":0}'); + + $response = $this->createMock(ResponseInterface::class); + $response->expects(self::once()) + ->method('getStatusCode') + ->willReturn(200); + $response->expects(self::once()) + ->method('getBody') + ->willReturn($stream); + + return $response; + } + + self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri())); + }); + $geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin'); $result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1')); $country = $result->first()->getCountry()->getCode(); @@ -70,11 +97,33 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void } $kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml'); - $kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_fr.yml'); + $kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_fr.yml'); }]); $kernel->setClearCacheAfterShutdown(false); $container = self::getContainer(); + $httpClient = $container->get(Client::class); + $httpClient->on(new RequestMatcher(), function (RequestInterface $request) { + if ('https://freegeoip.app/json/87.98.128.10' === (string) $request->getUri()) { + $stream = $this->createMock(StreamInterface::class); + $stream->expects(self::once()) + ->method('__toString') + ->willReturn('{"ip":"87.98.128.10","country_code":"FR","country_name":"France","region_code":null,"region_name":"Nord","city":"Roubaix","zip_code":"59100","time_zone":"Europe\/Paris","latitude":50.69371032714844,"longitude":3.174438953399658,"metro_code":0}'); + + $response = $this->createMock(ResponseInterface::class); + $response->expects(self::once()) + ->method('getStatusCode') + ->willReturn(200); + $response->expects(self::once()) + ->method('getBody') + ->willReturn($stream); + + return $response; + } + + self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri())); + }); + $geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin'); $result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1')); $country = $result->first()->getCountry()->getCode(); diff --git a/tests/Functional/ProviderFactoryTest.php b/tests/Functional/ProviderFactoryTest.php index e24dbde6..a360d8a4 100644 --- a/tests/Functional/ProviderFactoryTest.php +++ b/tests/Functional/ProviderFactoryTest.php @@ -20,7 +20,6 @@ use Geocoder\Provider\FreeGeoIp\FreeGeoIp; use Geocoder\Provider\Geoip\Geoip; use Geocoder\Provider\GeoIP2\GeoIP2; -use Geocoder\Provider\GeoIPs\GeoIPs; use Geocoder\Provider\Geonames\Geonames; use Geocoder\Provider\GeoPlugin\GeoPlugin; use Geocoder\Provider\GoogleMaps\GoogleMaps; @@ -33,7 +32,6 @@ use Geocoder\Provider\LocationIQ\LocationIQ; use Geocoder\Provider\Mapbox\Mapbox; use Geocoder\Provider\MapQuest\MapQuest; -use Geocoder\Provider\Mapzen\Mapzen; use Geocoder\Provider\MaxMind\MaxMind; use Geocoder\Provider\MaxMindBinary\MaxMindBinary; use Geocoder\Provider\Nominatim\Nominatim; @@ -107,9 +105,6 @@ public function getProviders(): iterable yield [FreeGeoIp::class, ['empty', 'acme']]; // yield [Geoip::class, ['empty']]; yield [GeoIP2::class, ['acme']]; - if (class_exists(GeoIPs::class)) { - yield [GeoIPs::class, ['acme']]; - } yield [Geonames::class, ['acme']]; yield [GeoPlugin::class, ['empty']]; yield [GoogleMaps::class, ['empty']]; @@ -122,9 +117,6 @@ public function getProviders(): iterable yield [LocationIQ::class, ['acme']]; yield [Mapbox::class, ['acme']]; yield [MapQuest::class, ['acme']]; - if (class_exists(Mapzen::class)) { - yield [Mapzen::class, ['acme']]; - } yield [MaxMind::class, ['acme']]; yield [MaxMindBinary::class, ['acme']]; yield [Nominatim::class, ['empty', 'acme']]; diff --git a/tests/Functional/config/geo_plugin_fakeip_with_cache_cn.yml b/tests/Functional/config/fakeip_with_cache_cn.yml similarity index 66% rename from tests/Functional/config/geo_plugin_fakeip_with_cache_cn.yml rename to tests/Functional/config/fakeip_with_cache_cn.yml index 6bf704cc..c9c0ee46 100644 --- a/tests/Functional/config/geo_plugin_fakeip_with_cache_cn.yml +++ b/tests/Functional/config/fakeip_with_cache_cn.yml @@ -2,13 +2,18 @@ bazinga_geocoder: # The local IP (127.0.0.1) will be replaced by the fake_ip # see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip - fake_ip: + fake_ip: local_ip: ::1 ip: 123.123.123.128 # this ip is in china providers: geoPlugin: - factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory + factory: Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory cache: 'app.simple_cache' cache_lifetime: 42 - cache_precision: ~ \ No newline at end of file + cache_precision: ~ + options: + http_client: '@Http\Mock\Client' + +services: + Http\Mock\Client: ~ diff --git a/tests/Functional/config/geo_plugin_fakeip_with_cache_fr.yml b/tests/Functional/config/fakeip_with_cache_fr.yml similarity index 66% rename from tests/Functional/config/geo_plugin_fakeip_with_cache_fr.yml rename to tests/Functional/config/fakeip_with_cache_fr.yml index f0b4b321..0b7e85a4 100644 --- a/tests/Functional/config/geo_plugin_fakeip_with_cache_fr.yml +++ b/tests/Functional/config/fakeip_with_cache_fr.yml @@ -2,13 +2,18 @@ bazinga_geocoder: # The local IP (127.0.0.1) will be replaced by the fake_ip # see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip - fake_ip: + fake_ip: local_ip: ::1 ip: 87.98.128.10 # this ip is in france providers: geoPlugin: - factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory + factory: Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory cache: 'app.simple_cache' cache_lifetime: 42 - cache_precision: ~ \ No newline at end of file + cache_precision: ~ + options: + http_client: '@Http\Mock\Client' + +services: + Http\Mock\Client: ~ diff --git a/tests/Functional/config/provider/geoips.yml b/tests/Functional/config/provider/geoips.yml deleted file mode 100644 index d0ba8313..00000000 --- a/tests/Functional/config/provider/geoips.yml +++ /dev/null @@ -1,8 +0,0 @@ -bazinga_geocoder: - profiling: - enabled: false - providers: - acme: - factory: Bazinga\GeocoderBundle\ProviderFactory\GeoIPsFactory - options: - api_key: 'foo' diff --git a/tests/Functional/config/provider/mapzen.yml b/tests/Functional/config/provider/mapzen.yml deleted file mode 100644 index 2071e153..00000000 --- a/tests/Functional/config/provider/mapzen.yml +++ /dev/null @@ -1,8 +0,0 @@ -bazinga_geocoder: - profiling: - enabled: false - providers: - acme: - factory: Bazinga\GeocoderBundle\ProviderFactory\MapzenFactory - options: - api_key: 'bar' diff --git a/tests/baseline-ignore b/tests/baseline-ignore index 6642abb6..0e1fe133 100644 --- a/tests/baseline-ignore +++ b/tests/baseline-ignore @@ -1,5 +1,3 @@ -%Bazinga\\GeocoderBundle\\ProviderFactory\\GeoIPsFactory is deprecated since 5.6, to be removed in 6.0% -%Bazinga\\GeocoderBundle\\ProviderFactory\\MapzenFactory is deprecated since 5.6, to be removed in 6.0% %Since doctrine/doctrine-bundle 2.11: Not setting "enable_lazy_ghost_objects" to true is deprecated% %Not configuring a schema manager factory is deprecated. Use Doctrine\\DBAL\\Schema\\DefaultSchemaManagerFactory which is going to be the default in DBAL 4% %Doctrine\\DBAL\\Configuration::setSQLLogger is deprecated, use setMiddlewares\(\) and Logging\\Middleware instead% @@ -83,3 +81,11 @@ %Geocoder\\ProviderAggregator::__construct\(\): Implicitly marking parameter \$decider as nullable is deprecated, the explicit nullable type must be used instead% %Since symfony/var-exporter 7.3: The "Symfony\\Component\\VarExporter\\LazyGhostTrait" trait is deprecated, use native lazy objects instead.% %Method "Http\\Promise\\Promise::wait\(\)" might add " Resolved value, null if \$unwrap is set to false" as a native return type declaration in the future. Do the same in implementation "Geocoder\\Plugin\\Promise\\GeocoderFulfilledPromise" now to avoid errors or add an explicit @return annotation to suppress this message.% +%The "Symfony\\Component\\HttpKernel\\Kernel::setAnnotatedClassCache\(\)" method is considered internal. It may change without further notice. You should not extend it from "Bazinga\\GeocoderBundle\\Tests\\Functional\\CustomTestKernel".% +%The "report_fields_where_declared" configuration option is deprecated and will be removed in DoctrineBundle 3.0. When using ORM 3, report_fields_where_declared will always be true% +%Class "Doctrine\\ORM\\Proxy\\DefaultProxyClassNameResolver" is deprecated. Use native lazy objects instead% +%Calling Doctrine\\ORM\\Configuration::(getProxyDir|setProxyDir|getAutoGenerateProxyClasses|setAutoGenerateProxyClasses|setProxyNamespace|getProxyNamespace) is deprecated and will not be possible in Doctrine ORM 4.0% +%Class "Doctrine\\ORM\\Proxy\\Autoloader" is deprecated. Use native lazy objects instead% +%Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0% +%Not setting "doctrine.orm.enable_native_lazy_objects" to true is deprecated% +%Disabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0%