Skip to content

Commit

Permalink
Add types declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
ker0x committed Sep 25, 2023
1 parent 9628346 commit d2bfcb6
Show file tree
Hide file tree
Showing 60 changed files with 126 additions and 258 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
/phpspec.ci.yml export-ignore
/phpspec.yml.dist export-ignore
/phpunit.xml.dist export-ignore
/rector.php export-ignore
/spec/ export-ignore
/Tests/ export-ignore
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"php-http/curl-client": "^2.2",
"php-http/message": "^1.13",
"phpstan/phpstan": "^1.9.2",
"rector/rector": "^0.18.3",
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
"symfony/config": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^5.2 || ^6.0",
Expand All @@ -83,7 +84,8 @@
},
"config": {
"allow-plugins": {
"symfony/flex": true
"symfony/flex": true,
"php-http/discovery": true
},
"sort-packages": true
},
Expand Down
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__.'/src',
__DIR__.'/tests',
]);

$rectorConfig->sets([
SetList::PHP_74,
SetList::TYPE_DECLARATION,
]);
};
10 changes: 1 addition & 9 deletions src/BazingaGeocoderBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
*/
class BazingaGeocoderBundle extends Bundle
{
/**
* {@inheritdoc}
*
* @return void
*/
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand All @@ -37,9 +32,6 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new FactoryValidatorPass());
}

/**
* {@inheritdoc}
*/
public function getPath(): string
{
return \dirname(__DIR__);
Expand Down
14 changes: 2 additions & 12 deletions src/Command/GeocodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ public function __construct(ProviderAggregator $geocoder)
parent::__construct();
}

/**
* {@inheritdoc}
*
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setName('geocoder:geocode')
Expand All @@ -57,12 +52,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($input->getOption('provider')) {
$this->geocoder->using($input->getOption('provider'));
Expand Down
24 changes: 4 additions & 20 deletions src/DataCollector/GeocoderDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +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'] = [];
}

/**
* {@inheritdoc}
*
* @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 @@ -103,23 +95,15 @@ 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 ($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();
}

/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'geocoder';
Expand Down
13 changes: 3 additions & 10 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 Expand Up @@ -213,9 +209,6 @@ private function findReferences(array $options): array
return $options;
}

/**
* @param mixed $factoryClass
*/
private function implementsProviderFactory($factoryClass): bool
{
if (false === $interfaces = class_implements($factoryClass)) {
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
16 changes: 3 additions & 13 deletions src/DependencyInjection/Compiler/FactoryValidatorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ class FactoryValidatorPass implements CompilerPassInterface
/**
* @var string[]
*/
private static $factoryServiceIds = [];
private static array $factoryServiceIds = [];

/**
* {@inheritdoc}
*
* @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 @@ -42,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
7 changes: 1 addition & 6 deletions src/DependencyInjection/Compiler/ProfilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
*/
class ProfilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*
* @return void
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition(GeocoderDataCollector::class)) {
return;
Expand Down
17 changes: 4 additions & 13 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ public function __construct(bool $debug)

/**
* Generates the configuration tree builder.
*
* @return TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('bazinga_geocoder');
$rootNode = $treeBuilder->getRootNode();
Expand All @@ -58,9 +56,7 @@ public function getConfigTreeBuilder()
->arrayNode('fake_ip')
->beforeNormalization()
->ifString()
->then(function ($value) {
return ['ip' => $value];
})
->then(fn ($value): array => ['ip' => $value])
->end()
->canBeEnabled()
->children()
Expand All @@ -75,10 +71,7 @@ public function getConfigTreeBuilder()
return $treeBuilder;
}

/**
* @return ArrayNodeDefinition
*/
private function getProvidersNode()
private function getProvidersNode(): ArrayNodeDefinition
{
$treeBuilder = new TreeBuilder('providers');
$rootNode = $treeBuilder->getRootNode();
Expand Down Expand Up @@ -113,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();
Expand Down
11 changes: 2 additions & 9 deletions src/Doctrine/ORM/GeocoderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function __construct(Provider $geocoder, DriverInterface $driver)
}

/**
* {@inheritdoc}
*
* @return list<string>
*/
public function getSubscribedEvents(): array
Expand All @@ -47,10 +45,7 @@ public function getSubscribedEvents(): array
];
}

/**
* @return void
*/
public function onFlush(OnFlushEventArgs $args)
public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
Expand Down Expand Up @@ -94,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;
}
8 changes: 1 addition & 7 deletions src/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@ public function __construct(Reader $reader)
$this->reader = $reader;
}

/**
* {@inheritdoc}
*/
public function isGeocodeable($object): bool
{
$reflection = ClassUtils::newReflectionObject($object);

return (bool) $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class);
}

/**
* {@inheritdoc}
*/
public function loadMetadataFromObject($object)
public function loadMetadataFromObject($object): ClassMetadata
{
$reflection = ClassUtils::newReflectionObject($object);

Expand Down
5 changes: 0 additions & 5 deletions src/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
final class AttributeDriver implements DriverInterface
{
/**
* {@inheritdoc}
*/
public function isGeocodeable($object): bool
{
if (PHP_VERSION_ID < 80000) {
Expand All @@ -37,8 +34,6 @@ public function isGeocodeable($object): bool
}

/**
* {@inheritdoc}
*
* @throws MappingException
*/
public function loadMetadataFromObject($object): ClassMetadata
Expand Down
Loading

0 comments on commit d2bfcb6

Please sign in to comment.