Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types declarations #343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions src/BazingaGeocoderBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
*/
class BazingaGeocoderBundle extends Bundle
{
/**
* @return void
*/
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
5 changes: 1 addition & 4 deletions src/Command/GeocodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public function __construct(ProviderAggregator $geocoder)
parent::__construct();
}

/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setName('geocoder:geocode')
Expand Down
19 changes: 4 additions & 15 deletions src/DataCollector/GeocoderDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 3 additions & 7 deletions src/DependencyInjection/BazingaGeocoderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ class BazingaGeocoderExtension extends Extension
{
/**
* @param array<mixed, mixed> $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);
Expand Down Expand Up @@ -78,10 +76,8 @@ public function load(array $configs, ContainerBuilder $container)

/**
* @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 Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/DependencyInjection/Compiler/AddProvidersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 3 additions & 11 deletions src/DependencyInjection/Compiler/FactoryValidatorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions src/DependencyInjection/Compiler/ProfilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 3 additions & 10 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Cannot call method end\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.$# in path /home/runner/work/BazingaGeocoderBundle/BazingaGeocoderBundle/src/DependencyInjection/Configuration.php was not matched in reported errors.

Check failure on line 1 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Cannot call method variableNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.$# in path /home/runner/work/BazingaGeocoderBundle/BazingaGeocoderBundle/src/DependencyInjection/Configuration.php was not matched in reported errors.

declare(strict_types=1);

Expand Down Expand Up @@ -37,7 +37,7 @@
$rootNode = $treeBuilder->getRootNode();
assert($rootNode instanceof ArrayNodeDefinition);

$rootNode

Check failure on line 40 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeParentInterface::end().
->children()
->append($this->getProvidersNode())
->arrayNode('profiling')
Expand All @@ -56,9 +56,7 @@
->arrayNode('fake_ip')
->beforeNormalization()
->ifString()
->then(function ($value) {
return ['ip' => $value];
})
->then(static fn (string $value): array => ['ip' => $value])
->end()
->canBeEnabled()
->children()
Expand All @@ -73,16 +71,13 @@
return $treeBuilder;
}

/**
* @return ArrayNodeDefinition
*/
private function getProvidersNode()
private function getProvidersNode(): ArrayNodeDefinition
{
$treeBuilder = new TreeBuilder('providers');
$rootNode = $treeBuilder->getRootNode();
assert($rootNode instanceof ArrayNodeDefinition);

$rootNode

Check failure on line 80 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeParentInterface::variableNode().
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->arrayPrototype()
Expand Down Expand Up @@ -111,10 +106,8 @@

/**
* 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();
Expand Down Expand Up @@ -143,7 +136,7 @@
->end()
;

$pluginList

Check failure on line 139 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeParentInterface::end().
->children()
->arrayNode('reference')
->canBeEnabled()
Expand Down
9 changes: 2 additions & 7 deletions src/Doctrine/ORM/GeocoderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 4 additions & 16 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions src/Mapping/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public function isGeocodeable($object): bool;

/**
* @param object $object
*
* @return ClassMetadata
*/
public function loadMetadataFromObject($object);
public function loadMetadataFromObject($object): ClassMetadata;
}
5 changes: 1 addition & 4 deletions src/Plugin/FakeIpPlugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in src/Plugin/FakeIpPlugin.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Method Bazinga\\GeocoderBundle\\Plugin\\FakeIpPlugin\:\:handleQuery\(\) return type with generic interface Http\\Promise\\Promise does not specify its types\: T$# in path /home/runner/work/BazingaGeocoderBundle/BazingaGeocoderBundle/src/Plugin/FakeIpPlugin.php was not matched in reported errors.

declare(strict_types=1);

Expand Down Expand Up @@ -41,10 +41,7 @@
}
}

/**
* @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);
Expand Down
19 changes: 7 additions & 12 deletions src/Plugin/ProfilingPlugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in src/Plugin/ProfilingPlugin.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Method Bazinga\\GeocoderBundle\\Plugin\\ProfilingPlugin\:\:handleQuery\(\) return type with generic interface Http\\Promise\\Promise does not specify its types\: T$# in path /home/runner/work/BazingaGeocoderBundle/BazingaGeocoderBundle/src/Plugin/ProfilingPlugin.php was not matched in reported errors.

declare(strict_types=1);

Expand Down Expand Up @@ -29,31 +29,28 @@
/**
* @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
* 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);

Expand All @@ -63,10 +60,8 @@

/**
* @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();
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/AlgoliaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/ArcGISOnlineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/BingMapsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/ChainFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/ProviderFactory/FreeGeoIpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/GeoIP2Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/GeoIPsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderFactory/GeoPluginFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading