Skip to content

Commit 3d6bbad

Browse files
authored
Merge pull request geocoder-php#390 from norkunas/final
Make classes final and add some types
2 parents b4d25cc + 6b685c8 commit 3d6bbad

40 files changed

+128
-163
lines changed

phpstan-baseline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
];
9696
$ignoreErrors[] = [
9797
// identifier: argument.type
98-
'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects string, mixed given\\.$#',
98+
'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects non\\-empty\\-string, mixed given\\.$#',
9999
'count' => 1,
100100
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
101101
];
@@ -131,7 +131,7 @@
131131
];
132132
$ignoreErrors[] = [
133133
// identifier: argument.type
134-
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array\\<int\\|string, mixed\\>, mixed given\\.$#',
134+
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array, mixed given\\.$#',
135135
'count' => 1,
136136
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
137137
];

src/BazingaGeocoderBundle.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
/**
2222
* @author William Durand <[email protected]>
2323
*/
24-
class BazingaGeocoderBundle extends Bundle
24+
final class BazingaGeocoderBundle extends Bundle
2525
{
26-
/**
27-
* @return void
28-
*/
2926
public function build(ContainerBuilder $container): void
3027
{
3128
parent::build($container);

src/Command/GeocodeCommand.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
/**
2525
* @author Markus Bachmann <[email protected]>
2626
*/
27-
#[AsCommand(name: 'geocoder:geocode', description: 'Geocode an address or an IP address')]
28-
class GeocodeCommand extends Command
27+
#[AsCommand(
28+
name: 'geocoder:geocode',
29+
description: 'Geocode an address or an IP address',
30+
)]
31+
final class GeocodeCommand extends Command
2932
{
30-
private ProviderAggregator $geocoder;
31-
32-
public function __construct(ProviderAggregator $geocoder)
33-
{
34-
$this->geocoder = $geocoder;
35-
33+
public function __construct(
34+
private readonly ProviderAggregator $geocoder,
35+
) {
3636
parent::__construct();
3737
}
3838

@@ -48,8 +48,7 @@ protected function configure(): void
4848
You can force a provider with the "provider" option.
4949
5050
<info>php bin/console geocoder:geocoder "Eiffel Tower" --provider=yahoo</info>
51-
HELP
52-
);
51+
HELP);
5352
}
5453

5554
protected function execute(InputInterface $input, OutputInterface $output): int

src/DataCollector/GeocoderDataCollector.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* @author Michal Dabrowski <[email protected]>
2323
*/
24-
class GeocoderDataCollector extends DataCollector
24+
final class GeocoderDataCollector extends DataCollector
2525
{
2626
/**
2727
* @var ProfilingPlugin[]
@@ -43,7 +43,7 @@ public function reset(): void
4343

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

103-
/**
104-
* @return void
105-
*/
106-
public function addInstance(ProfilingPlugin $instance)
103+
public function addInstance(ProfilingPlugin $instance): void
107104
{
108105
$this->instances[] = $instance;
109106
$this->data['providers'][] = $instance->getName();

src/DependencyInjection/BazingaGeocoderExtension.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ public function load(array $configs, ContainerBuilder $container): void
7676

7777
/**
7878
* @param array<mixed, mixed> $config
79-
*
80-
* @return void
8179
*/
82-
private function loadProviders(ContainerBuilder $container, array $config)
80+
private function loadProviders(ContainerBuilder $container, array $config): void
8381
{
8482
foreach ($config['providers'] as $providerName => $providerConfig) {
8583
try {
@@ -91,7 +89,7 @@ private function loadProviders(ContainerBuilder $container, array $config)
9189
// See if any option has a service reference
9290
$providerConfig['options'] = $this->findReferences($providerConfig['options']);
9391
$factoryClass::validate($providerConfig['options'], $providerName);
94-
} catch (ServiceNotFoundException $e) {
92+
} catch (ServiceNotFoundException) {
9593
// Assert: We are using a custom factory. If invalid config, it will be caught in FactoryValidatorPass
9694
$providerConfig['options'] = $this->findReferences($providerConfig['options']);
9795
FactoryValidatorPass::addFactoryServiceId($providerConfig['factory']);
@@ -118,9 +116,9 @@ private function loadProviders(ContainerBuilder $container, array $config)
118116
/**
119117
* Configure plugins for a client.
120118
*
121-
* @param array<mixed, mixed> $config
119+
* @param array<mixed> $config
122120
*
123-
* @return Reference[]
121+
* @return list<Reference>
124122
*/
125123
public function configureProviderPlugins(ContainerBuilder $container, array $config, string $providerServiceId): array
126124
{

src/DependencyInjection/Compiler/FactoryValidatorPass.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
class FactoryValidatorPass implements CompilerPassInterface
2525
{
2626
/**
27-
* @var string[]
27+
* @var list<non-empty-string>
2828
*/
29-
private static $factoryServiceIds = [];
29+
private static array $factoryServiceIds = [];
3030

3131
public function process(ContainerBuilder $container): void
3232
{
@@ -38,11 +38,9 @@ public function process(ContainerBuilder $container): void
3838
}
3939

4040
/**
41-
* @param string $factoryServiceId
42-
*
43-
* @return void
41+
* @param non-empty-string $factoryServiceId
4442
*/
45-
public static function addFactoryServiceId($factoryServiceId)
43+
public static function addFactoryServiceId(string $factoryServiceId): void
4644
{
4745
self::$factoryServiceIds[] = $factoryServiceId;
4846
}

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
/**
2020
* @author William Durand <[email protected]>
2121
*/
22-
class Configuration implements ConfigurationInterface
22+
final class Configuration implements ConfigurationInterface
2323
{
24-
private bool $debug;
25-
26-
public function __construct(bool $debug)
27-
{
28-
$this->debug = $debug;
24+
public function __construct(
25+
private readonly bool $debug,
26+
) {
2927
}
3028

3129
/**

src/Doctrine/ORM/GeocoderListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* @author Markus Bachmann <[email protected]>
2626
*/
27-
class GeocoderListener implements EventSubscriber
27+
final class GeocoderListener implements EventSubscriber
2828
{
2929
public function __construct(
3030
private readonly Provider $geocoder,

src/Plugin/FakeIpPlugin.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@
2424
*
2525
* @author Tobias Nyholm <[email protected]>
2626
*/
27-
class FakeIpPlugin implements Plugin
27+
final class FakeIpPlugin implements Plugin
2828
{
29-
private ?string $needle;
30-
private ?string $replacement;
3129
private ?Generator $faker = null;
3230

33-
public function __construct(?string $needle, ?string $replacement = null, bool $useFaker = false)
34-
{
35-
$this->needle = $needle;
36-
$this->replacement = $replacement;
37-
31+
public function __construct(
32+
private readonly ?string $needle,
33+
private readonly ?string $replacement = null,
34+
bool $useFaker = false,
35+
) {
3836
if ($useFaker) {
3937
$this->faker = new Generator();
4038
$this->faker->addProvider(new Internet($this->faker));

src/Plugin/ProfilingPlugin.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,22 @@
2424
/**
2525
* @author Tobias Nyholm <[email protected]>
2626
*/
27-
class ProfilingPlugin implements Plugin
27+
final class ProfilingPlugin implements Plugin
2828
{
2929
/**
3030
* @var list<array{query: Query, queryString: string, duration: float, providerName: string, result: mixed, resultCount: int}>
3131
*/
32-
private $queries = [];
32+
private array $queries = [];
3333

3434
/**
35-
* @var string service id of the provider
35+
* @param non-empty-string $name service id of the provider
3636
*/
37-
private $name;
38-
39-
public function __construct(string $name)
40-
{
41-
$this->name = $name;
37+
public function __construct(
38+
private readonly string $name,
39+
) {
4240
}
4341

44-
/**
45-
* @return Promise
46-
*/
47-
public function handleQuery(Query $query, callable $next, callable $first)
42+
public function handleQuery(Query $query, callable $next, callable $first): Promise
4843
{
4944
$startTime = microtime(true);
5045

@@ -61,12 +56,7 @@ public function handleQuery(Query $query, callable $next, callable $first)
6156
});
6257
}
6358

64-
/**
65-
* @param mixed $result
66-
*
67-
* @return void
68-
*/
69-
private function logQuery(Query $query, float $duration, $result = null)
59+
private function logQuery(Query $query, float $duration, mixed $result = null): void
7060
{
7161
if ($query instanceof GeocodeQuery) {
7262
$queryString = $query->getText();
@@ -94,6 +84,9 @@ public function getQueries(): array
9484
return $this->queries;
9585
}
9686

87+
/**
88+
* @return non-empty-string
89+
*/
9790
public function getName(): string
9891
{
9992
return $this->name;

0 commit comments

Comments
 (0)