Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects string, mixed given\\.$#',
'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects non\\-empty\\-string, mixed given\\.$#',
'count' => 1,
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
];
Expand Down Expand Up @@ -131,7 +131,7 @@
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array\\<int\\|string, mixed\\>, mixed given\\.$#',
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array, mixed given\\.$#',
'count' => 1,
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
];
Expand Down
5 changes: 1 addition & 4 deletions src/BazingaGeocoderBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
/**
* @author William Durand <[email protected]>
*/
class BazingaGeocoderBundle extends Bundle
final class BazingaGeocoderBundle extends Bundle
{
/**
* @return void
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
Expand Down
19 changes: 9 additions & 10 deletions src/Command/GeocodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
/**
* @author Markus Bachmann <[email protected]>
*/
#[AsCommand(name: 'geocoder:geocode', description: 'Geocode an address or an IP address')]
class GeocodeCommand extends Command
#[AsCommand(
name: 'geocoder:geocode',
description: 'Geocode an address or an IP address',
)]
final class GeocodeCommand extends Command
{
private ProviderAggregator $geocoder;

public function __construct(ProviderAggregator $geocoder)
{
$this->geocoder = $geocoder;

public function __construct(
private readonly ProviderAggregator $geocoder,
) {
parent::__construct();
}

Expand All @@ -48,8 +48,7 @@ protected function configure(): void
You can force a provider with the "provider" option.

<info>php bin/console geocoder:geocoder "Eiffel Tower" --provider=yahoo</info>
HELP
);
HELP);
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
9 changes: 3 additions & 6 deletions src/DataCollector/GeocoderDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @author Michal Dabrowski <[email protected]>
*/
class GeocoderDataCollector extends DataCollector
final class GeocoderDataCollector extends DataCollector
{
/**
* @var ProfilingPlugin[]
Expand All @@ -43,7 +43,7 @@ public function reset(): void

public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
if (!empty($this->data['queries'])) {
if ([] !== $this->data['queries']) {
// To avoid collection more that once.
return;
}
Expand Down Expand Up @@ -100,10 +100,7 @@ public function getProviderQueries(string $provider): array
});
}

/**
* @return void
*/
public function addInstance(ProfilingPlugin $instance)
public function addInstance(ProfilingPlugin $instance): void
{
$this->instances[] = $instance;
$this->data['providers'][] = $instance->getName();
Expand Down
10 changes: 4 additions & 6 deletions src/DependencyInjection/BazingaGeocoderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ public function load(array $configs, ContainerBuilder $container): void

/**
* @param array<mixed, mixed> $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 {
Expand All @@ -91,7 +89,7 @@ private function loadProviders(ContainerBuilder $container, array $config)
// See if any option has a service reference
$providerConfig['options'] = $this->findReferences($providerConfig['options']);
$factoryClass::validate($providerConfig['options'], $providerName);
} catch (ServiceNotFoundException $e) {
} catch (ServiceNotFoundException) {
// Assert: We are using a custom factory. If invalid config, it will be caught in FactoryValidatorPass
$providerConfig['options'] = $this->findReferences($providerConfig['options']);
FactoryValidatorPass::addFactoryServiceId($providerConfig['factory']);
Expand All @@ -118,9 +116,9 @@ private function loadProviders(ContainerBuilder $container, array $config)
/**
* Configure plugins for a client.
*
* @param array<mixed, mixed> $config
* @param array<mixed> $config
*
* @return Reference[]
* @return list<Reference>
*/
public function configureProviderPlugins(ContainerBuilder $container, array $config, string $providerServiceId): array
{
Expand Down
10 changes: 4 additions & 6 deletions src/DependencyInjection/Compiler/FactoryValidatorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
class FactoryValidatorPass implements CompilerPassInterface
{
/**
* @var string[]
* @var list<non-empty-string>
*/
private static $factoryServiceIds = [];
private static array $factoryServiceIds = [];

public function process(ContainerBuilder $container): void
{
Expand All @@ -38,11 +38,9 @@ public function process(ContainerBuilder $container): void
}

/**
* @param string $factoryServiceId
*
* @return void
* @param non-empty-string $factoryServiceId
*/
public static function addFactoryServiceId($factoryServiceId)
public static function addFactoryServiceId(string $factoryServiceId): void
{
self::$factoryServiceIds[] = $factoryServiceId;
}
Expand Down
10 changes: 4 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
/**
* @author William Durand <[email protected]>
*/
class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
private bool $debug;

public function __construct(bool $debug)
{
$this->debug = $debug;
public function __construct(
private readonly bool $debug,
) {
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/ORM/GeocoderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* @author Markus Bachmann <[email protected]>
*/
class GeocoderListener implements EventSubscriber
final class GeocoderListener implements EventSubscriber
{
public function __construct(
private readonly Provider $geocoder,
Expand Down
14 changes: 6 additions & 8 deletions src/Plugin/FakeIpPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
*
* @author Tobias Nyholm <[email protected]>
*/
class FakeIpPlugin implements Plugin
final class FakeIpPlugin implements Plugin
{
private ?string $needle;
private ?string $replacement;
private ?Generator $faker = null;

public function __construct(?string $needle, ?string $replacement = null, bool $useFaker = false)
{
$this->needle = $needle;
$this->replacement = $replacement;

public function __construct(
private readonly ?string $needle,
private readonly ?string $replacement = null,
bool $useFaker = false,
) {
if ($useFaker) {
$this->faker = new Generator();
$this->faker->addProvider(new Internet($this->faker));
Expand Down
29 changes: 11 additions & 18 deletions src/Plugin/ProfilingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,22 @@
/**
* @author Tobias Nyholm <[email protected]>
*/
class ProfilingPlugin implements Plugin
final class ProfilingPlugin implements Plugin
{
/**
* @var list<array{query: Query, queryString: string, duration: float, providerName: string, result: mixed, resultCount: int}>
*/
private $queries = [];
private array $queries = [];

/**
* @var string service id of the provider
* @param non-empty-string $name service id of the provider
*/
private $name;

public function __construct(string $name)
{
$this->name = $name;
public function __construct(
private readonly string $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);

Expand All @@ -61,12 +56,7 @@ 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, mixed $result = null): void
{
if ($query instanceof GeocodeQuery) {
$queryString = $query->getText();
Expand Down Expand Up @@ -94,6 +84,9 @@ public function getQueries(): array
return $this->queries;
}

/**
* @return non-empty-string
*/
public function getName(): string
{
return $this->name;
Expand Down
22 changes: 8 additions & 14 deletions src/ProviderFactory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ abstract class AbstractFactory implements ProviderFactoryInterface
/**
* @var list<array{requiredClass: class-string, packageName: string}>
*/
protected static $dependencies = [];
protected static array $dependencies = [];

protected ?ClientInterface $httpClient;

public function __construct(?ClientInterface $httpClient = null)
{
$this->httpClient = $httpClient;
public function __construct(
protected ?ClientInterface $httpClient = null,
) {
}

/**
* @param array<mixed, mixed> $config
* @param array<mixed> $config
*/
abstract protected function getProvider(array $config): Provider;

Expand All @@ -53,7 +51,7 @@ public function createProvider(array $options = []): Provider
return $this->getProvider($config);
}

public static function validate(array $options, $providerName)
public static function validate(array $options, string $providerName): void
{
static::verifyDependencies();

Expand All @@ -77,11 +75,9 @@ public static function validate(array $options, $providerName)
/**
* Make sure that we have the required class and throw and exception if we don't.
*
* @return void
*
* @throws \LogicException
*/
protected static function verifyDependencies()
protected static function verifyDependencies(): void
{
foreach (static::$dependencies as $dependency) {
if (!class_exists($dependency['requiredClass'])) {
Expand All @@ -93,10 +89,8 @@ protected static function verifyDependencies()
/**
* By default, we do not have any options to configure. A factory should override this function and configure
* the options resolver.
*
* @return void
*/
protected static function configureOptionResolver(OptionsResolver $resolver)
protected static function configureOptionResolver(OptionsResolver $resolver): void
{
}
}
4 changes: 2 additions & 2 deletions src/ProviderFactory/AlgoliaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

final class AlgoliaFactory extends AbstractFactory
{
protected static $dependencies = [
protected static array $dependencies = [
['requiredClass' => AlgoliaPlaces::class, 'packageName' => 'geocoder-php/algolia-places-provider'],
];

Expand All @@ -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([
'http_client' => null,
Expand Down
4 changes: 2 additions & 2 deletions src/ProviderFactory/ArcGISOnlineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

final class ArcGISOnlineFactory extends AbstractFactory
{
protected static $dependencies = [
protected static array $dependencies = [
['requiredClass' => ArcGISOnline::class, 'packageName' => 'geocoder-php/arcgis-online-provider'],
];

Expand All @@ -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([
'http_client' => null,
Expand Down
4 changes: 2 additions & 2 deletions src/ProviderFactory/BingMapsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

final class BingMapsFactory extends AbstractFactory
{
protected static $dependencies = [
protected static array $dependencies = [
['requiredClass' => BingMaps::class, 'packageName' => 'geocoder-php/bing-maps-provider'],
];

Expand All @@ -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([
'http_client' => null,
Expand Down
4 changes: 2 additions & 2 deletions src/ProviderFactory/ChainFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class ChainFactory extends AbstractFactory implements LoggerAwareInterface
{
use LoggerAwareTrait;

protected static $dependencies = [
protected static array $dependencies = [
['requiredClass' => Chain::class, 'packageName' => 'geocoder-php/chain-provider'],
];

Expand All @@ -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);

Expand Down
Loading