Skip to content

Commit f5f975b

Browse files
authored
Merge pull request #320 from norkunas/sca
Increase phpstan level to 7
2 parents c9318d5 + abc63bf commit f5f975b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+252
-16
lines changed

BazingaGeocoderBundle.php

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class BazingaGeocoderBundle extends Bundle
2525
{
2626
/**
2727
* {@inheritdoc}
28+
*
29+
* @return void
2830
*/
2931
public function build(ContainerBuilder $container)
3032
{

Command/GeocodeCommand.php

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function __construct(ProviderAggregator $geocoder)
4141

4242
/**
4343
* {@inheritdoc}
44+
*
45+
* @return void
4446
*/
4547
protected function configure()
4648
{

DataCollector/GeocoderDataCollector.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
namespace Bazinga\GeocoderBundle\DataCollector;
1414

1515
use Bazinga\GeocoderBundle\Plugin\ProfilingPlugin;
16+
use Geocoder\Collection;
17+
use Geocoder\Query\Query;
1618
use Symfony\Component\HttpFoundation\Request;
1719
use Symfony\Component\HttpFoundation\Response;
1820
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
@@ -34,7 +36,7 @@ public function __construct()
3436
}
3537

3638
/**
37-
* {@inheritdoc}
39+
* @return void
3840
*/
3941
public function reset()
4042
{
@@ -45,6 +47,8 @@ public function reset()
4547

4648
/**
4749
* {@inheritdoc}
50+
*
51+
* @return void
4852
*/
4953
public function collect(Request $request, Response $response, \Throwable $exception = null)
5054
{
@@ -53,7 +57,6 @@ public function collect(Request $request, Response $response, \Throwable $except
5357
return;
5458
}
5559

56-
/** @var ProfilingPlugin[] $instances */
5760
$instances = $this->instances;
5861

5962
foreach ($instances as $instance) {
@@ -67,6 +70,8 @@ public function collect(Request $request, Response $response, \Throwable $except
6770

6871
/**
6972
* Returns an array of collected requests.
73+
*
74+
* @phpstan-return array<int, array{query: Query, queryString: string, duration: float, providerName: string, result: mixed, resultCount: int}>
7075
*/
7176
public function getQueries(): array
7277
{
@@ -86,18 +91,27 @@ public function getTotalDuration(): float
8691
return $time;
8792
}
8893

94+
/**
95+
* @return string[]
96+
*/
8997
public function getProviders(): array
9098
{
9199
return $this->data['providers'];
92100
}
93101

102+
/**
103+
* @phpstan-return array<int, array{query: Query, queryString: string, duration: float, providerName: string, result: mixed, resultCount: int}>
104+
*/
94105
public function getProviderQueries(string $provider): array
95106
{
96-
return array_filter($this->data['queries'], function ($data) use ($provider) {
107+
return array_filter($this->data['queries'], static function ($data) use ($provider) {
97108
return $data['providerName'] === $provider;
98109
});
99110
}
100111

112+
/**
113+
* @return void
114+
*/
101115
public function addInstance(ProfilingPlugin $instance)
102116
{
103117
$this->instances[] = $instance;

DependencyInjection/BazingaGeocoderExtension.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
*/
4040
class BazingaGeocoderExtension extends Extension
4141
{
42+
/**
43+
* @phpstan-param array<mixed, mixed> $configs
44+
*
45+
* @return void
46+
*/
4247
public function load(array $configs, ContainerBuilder $container)
4348
{
4449
$processor = new Processor();
@@ -71,6 +76,11 @@ public function load(array $configs, ContainerBuilder $container)
7176
->addTag('bazinga_geocoder.dumper');
7277
}
7378

79+
/**
80+
* @phpstan-param array<mixed, mixed> $config
81+
*
82+
* @return void
83+
*/
7484
private function loadProviders(ContainerBuilder $container, array $config)
7585
{
7686
foreach ($config['providers'] as $providerName => $providerConfig) {
@@ -109,6 +119,10 @@ private function loadProviders(ContainerBuilder $container, array $config)
109119

110120
/**
111121
* Configure plugins for a client.
122+
*
123+
* @phpstan-param array<mixed, mixed> $config
124+
*
125+
* @return Reference[]
112126
*/
113127
public function configureProviderPlugins(ContainerBuilder $container, array $config, string $providerServiceId): array
114128
{
@@ -173,13 +187,23 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con
173187
}
174188

175189
/**
190+
* @phpstan-param array<mixed, mixed> $config
191+
*
176192
* @return Configuration
177193
*/
178194
public function getConfiguration(array $config, ContainerBuilder $container)
179195
{
180-
return new Configuration($container->getParameter('kernel.debug'));
196+
/** @var bool $debug */
197+
$debug = $container->getParameter('kernel.debug');
198+
199+
return new Configuration($debug);
181200
}
182201

202+
/**
203+
* @phpstan-param array<mixed, mixed> $options
204+
*
205+
* @phpstan-return array<mixed, mixed>
206+
*/
183207
private function findReferences(array $options): array
184208
{
185209
foreach ($options as $key => $value) {

DependencyInjection/Compiler/AddProvidersPass.php

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class AddProvidersPass implements CompilerPassInterface
2525
/**
2626
* Get all providers based on their tag (`bazinga_geocoder.provider`) and
2727
* register them.
28+
*
29+
* @return void
2830
*/
2931
public function process(ContainerBuilder $container)
3032
{

DependencyInjection/Compiler/FactoryValidatorPass.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
*/
2424
class FactoryValidatorPass implements CompilerPassInterface
2525
{
26+
/**
27+
* @var string[]
28+
*/
2629
private static $factoryServiceIds = [];
2730

2831
/**
2932
* {@inheritdoc}
33+
*
34+
* @return void
3035
*/
3136
public function process(ContainerBuilder $container)
3237
{
@@ -38,10 +43,12 @@ public function process(ContainerBuilder $container)
3843
}
3944

4045
/**
41-
* @param mixed $factoryServiceIds
46+
* @param string $factoryServiceId
47+
*
48+
* @return void
4249
*/
43-
public static function addFactoryServiceId($factoryServiceIds)
50+
public static function addFactoryServiceId($factoryServiceId)
4451
{
45-
self::$factoryServiceIds[] = $factoryServiceIds;
52+
self::$factoryServiceIds[] = $factoryServiceId;
4653
}
4754
}

DependencyInjection/Compiler/ProfilerPass.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class ProfilerPass implements CompilerPassInterface
2626
{
2727
/**
2828
* {@inheritdoc}
29+
*
30+
* @return void
2931
*/
3032
public function process(ContainerBuilder $container)
3133
{

Doctrine/ORM/GeocoderListener.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function __construct(Provider $geocoder, DriverInterface $driver)
4646
* {@inheritdoc}
4747
*
4848
* @return array
49+
* @phpstan-return list<string>
4950
*/
5051
public function getSubscribedEvents()
5152
{
@@ -54,6 +55,9 @@ public function getSubscribedEvents()
5455
];
5556
}
5657

58+
/**
59+
* @return void
60+
*/
5761
public function onFlush(OnFlushEventArgs $args)
5862
{
5963
$em = $args->getEntityManager();
@@ -98,6 +102,8 @@ public function onFlush(OnFlushEventArgs $args)
98102

99103
/**
100104
* @param object $entity
105+
*
106+
* @return void
101107
*/
102108
private function geocodeEntity(ClassMetadata $metadata, $entity)
103109
{
@@ -107,7 +113,7 @@ private function geocodeEntity(ClassMetadata $metadata, $entity)
107113
$address = $metadata->addressProperty->getValue($entity);
108114
}
109115

110-
if (empty($address)) {
116+
if (empty($address) || !is_string($address)) {
111117
return;
112118
}
113119

Mapping/Driver/AnnotationDriver.php

+9
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,29 @@
2323
*/
2424
class AnnotationDriver implements DriverInterface
2525
{
26+
/**
27+
* @var Reader
28+
*/
2629
private $reader;
2730

2831
public function __construct(Reader $reader)
2932
{
3033
$this->reader = $reader;
3134
}
3235

36+
/**
37+
* {@inheritdoc}
38+
*/
3339
public function isGeocodeable($object): bool
3440
{
3541
$reflection = ClassUtils::newReflectionObject($object);
3642

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

46+
/**
47+
* {@inheritdoc}
48+
*/
4049
public function loadMetadataFromObject($object)
4150
{
4251
$reflection = ClassUtils::newReflectionObject($object);

Mapping/Driver/AttributeDriver.php

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
final class AttributeDriver implements DriverInterface
2424
{
25+
/**
26+
* {@inheritdoc}
27+
*/
2528
public function isGeocodeable($object): bool
2629
{
2730
if (PHP_VERSION_ID < 80000) {
@@ -34,6 +37,8 @@ public function isGeocodeable($object): bool
3437
}
3538

3639
/**
40+
* {@inheritdoc}
41+
*
3742
* @throws MappingException
3843
*/
3944
public function loadMetadataFromObject($object): ClassMetadata

Mapping/Driver/DriverInterface.php

+10
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@
1212

1313
namespace Bazinga\GeocoderBundle\Mapping\Driver;
1414

15+
use Bazinga\GeocoderBundle\Mapping\ClassMetadata;
16+
1517
interface DriverInterface
1618
{
19+
/**
20+
* @param object $object
21+
*/
1722
public function isGeocodeable($object): bool;
1823

24+
/**
25+
* @param object $object
26+
*
27+
* @return ClassMetadata
28+
*/
1929
public function loadMetadataFromObject($object);
2030
}

Plugin/ProfilingPlugin.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ class ProfilingPlugin implements Plugin
2828
{
2929
/**
3030
* @var array
31+
* @phpstan-var array<int, array{query: Query, queryString: string, duration: float, providerName: string, result: mixed, resultCount: int}>
3132
*/
3233
private $queries = [];
3334

3435
/**
35-
* @var string service id of the provider;
36+
* @var string service id of the provider
3637
*/
3738
private $name;
3839

@@ -62,7 +63,9 @@ public function handleQuery(Query $query, callable $next, callable $first)
6263
}
6364

6465
/**
65-
* @param Collection|Exception $result
66+
* @param mixed $result
67+
*
68+
* @return void
6669
*/
6770
private function logQuery(Query $query, float $duration, $result = null)
6871
{
@@ -84,6 +87,9 @@ private function logQuery(Query $query, float $duration, $result = null)
8487
];
8588
}
8689

90+
/**
91+
* @phpstan-return array<int, array{query: Query, queryString: string, duration: float, providerName: string, result: mixed, resultCount: int}>
92+
*/
8793
public function getQueries(): array
8894
{
8995
return $this->queries;

ProviderFactory/AbstractFactory.php

+13
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,24 @@
2525
*/
2626
abstract class AbstractFactory implements ProviderFactoryInterface
2727
{
28+
/**
29+
* @var array<int, array{requiredClass: class-string, packageName: string}>
30+
*/
2831
protected static $dependencies = [];
2932

33+
/**
34+
* @var HttpClient|null
35+
*/
3036
protected $httpClient;
3137

3238
public function __construct(HttpClient $httpClient = null)
3339
{
3440
$this->httpClient = $httpClient;
3541
}
3642

43+
/**
44+
* @phpstan-param array<mixed, mixed> $config
45+
*/
3746
abstract protected function getProvider(array $config): Provider;
3847

3948
/**
@@ -77,6 +86,8 @@ public static function validate(array $options, $providerName)
7786
/**
7887
* Make sure that we have the required class and throw and exception if we don't.
7988
*
89+
* @return void
90+
*
8091
* @throws \LogicException
8192
*/
8293
protected static function verifyDependencies()
@@ -91,6 +102,8 @@ protected static function verifyDependencies()
91102
/**
92103
* By default we do not have any options to configure. A factory should override this function and confgure
93104
* the options resolver.
105+
*
106+
* @return void
94107
*/
95108
protected static function configureOptionResolver(OptionsResolver $resolver)
96109
{

0 commit comments

Comments
 (0)