Skip to content

Commit e95f220

Browse files
committed
Make classes final and add some types
1 parent b4d25cc commit e95f220

39 files changed

+135
-179
lines changed

phpstan-baseline.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
'count' => 1,
2222
'path' => __DIR__.'/src/Command/GeocodeCommand.php',
2323
];
24-
$ignoreErrors[] = [
25-
// identifier: argument.type
26-
'message' => '#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#',
27-
'count' => 1,
28-
'path' => __DIR__.'/src/Command/GeocodeCommand.php',
29-
];
3024
$ignoreErrors[] = [
3125
// identifier: foreach.nonIterable
3226
'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#',
@@ -95,7 +89,7 @@
9589
];
9690
$ignoreErrors[] = [
9791
// identifier: argument.type
98-
'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects string, mixed given\\.$#',
92+
'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects non\\-empty\\-string, mixed given\\.$#',
9993
'count' => 1,
10094
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
10195
];
@@ -131,7 +125,7 @@
131125
];
132126
$ignoreErrors[] = [
133127
// identifier: argument.type
134-
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array\\<int\\|string, mixed\\>, mixed given\\.$#',
128+
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array, mixed given\\.$#',
135129
'count' => 1,
136130
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
137131
];

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: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,31 @@
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
29-
{
30-
private ProviderAggregator $geocoder;
27+
#[AsCommand(
28+
name: 'geocoder:geocode',
29+
description: 'Geocode an address or an IP address',
30+
help: <<<'HELP'
31+
The <info>geocoder:geocoder</info> command will fetch the latitude
32+
and longitude from the given address.
3133
32-
public function __construct(ProviderAggregator $geocoder)
33-
{
34-
$this->geocoder = $geocoder;
34+
You can force a provider with the "provider" option.
3535
36+
<info>php bin/console geocoder:geocoder "Eiffel Tower" --provider=yahoo</info>
37+
HELP
38+
)]
39+
final class GeocodeCommand extends Command
40+
{
41+
public function __construct(
42+
private readonly ProviderAggregator $geocoder,
43+
) {
3644
parent::__construct();
3745
}
3846

3947
protected function configure(): void
4048
{
4149
$this
4250
->addArgument('address', InputArgument::REQUIRED, 'The address')
43-
->addOption('provider', null, InputOption::VALUE_OPTIONAL)
44-
->setHelp(<<<'HELP'
45-
The <info>geocoder:geocoder</info> command will fetch the latitude
46-
and longitude from the given address.
47-
48-
You can force a provider with the "provider" option.
49-
50-
<info>php bin/console geocoder:geocoder "Eiffel Tower" --provider=yahoo</info>
51-
HELP
52-
);
51+
->addOption('provider', null, InputOption::VALUE_OPTIONAL);
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: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,22 @@
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));
4139
}
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
if (!$query instanceof GeocodeQuery) {
5045
return $next($query);

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)