Skip to content

Commit 1c0de2d

Browse files
committed
Fix some phpstan warnings
1 parent 7474234 commit 1c0de2d

26 files changed

+157
-184
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
composer-options: "--optimize-autoloader"
5353

5454
- name: "Run PHP-CS-Fixer"
55-
run: vendor/bin/php-cs-fixer fix -v --dry-run --allow-unsupported-php-version=yes --using-cache=no --format=checkstyle | cs2pr
55+
run: vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no --format=checkstyle | cs2pr
5656

5757
phpunit:
5858
name: PHPUnit (PHP ${{ matrix.php }}) (Symfony ${{ matrix.sf_version }})
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
;
88

99
return (new PhpCsFixer\Config())
10+
->setFinder($finder)
11+
->setUnsupportedPhpVersionAllowed(true)
1012
->setRules([
1113
'@Symfony' => true,
1214
'no_superfluous_phpdoc_tags' => false,
1315
'phpdoc_to_comment' => ['ignored_tags' => ['var']], // phpstan errors pops up without this
1416
])
15-
->setFinder($finder)
1617
;

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"require-dev": {
2626
"doctrine/doctrine-bundle": "^2.18 || ^3.0",
2727
"doctrine/orm": "^2.20 || ^3.0",
28-
"fakerphp/faker": "^1.24",
29-
"friendsofphp/php-cs-fixer": "^3.92",
28+
"fakerphp/faker": "^1.24.1",
29+
"friendsofphp/php-cs-fixer": "^3.92.4",
3030
"geocoder-php/algolia-places-provider": "^0.5",
3131
"geocoder-php/arcgis-online-provider": "^4.5",
3232
"geocoder-php/bing-maps-provider": "^4.4",
@@ -53,11 +53,11 @@
5353
"geocoder-php/pickpoint-provider": "^4.4",
5454
"geocoder-php/tomtom-provider": "^4.5",
5555
"geocoder-php/yandex-provider": "^4.6",
56-
"nyholm/nsa": "^1.3",
57-
"nyholm/psr7": "^1.8",
56+
"nyholm/nsa": "^1.3.1",
57+
"nyholm/psr7": "^1.8.2",
5858
"nyholm/symfony-bundle-test": "^3.1",
59-
"phpstan/phpstan": "^2.1",
60-
"psr/http-client": "^1.0",
59+
"phpstan/phpstan": "^2.1.33",
60+
"psr/http-client": "^1.0.3",
6161
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
6262
"symfony/cache": "^6.4 || ^7.0 || ^8.0",
6363
"symfony/config": "^6.4 || ^7.0 || ^8.0",

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Bazinga\GeocoderBundle\DependencyInjection;
1414

15+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1516
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1617
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1718
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -42,7 +43,7 @@ public function getConfigTreeBuilder(): TreeBuilder
4243
->addDefaultsIfNotSet()
4344
->treatFalseLike(['enabled' => false])
4445
->treatTrueLike(['enabled' => true])
45-
->treatNullLike(['enabled' => $this->debug])
46+
->treatNullLike(['enabled' => \class_exists(DoctrineBundle::class)])
4647
->info('Extend the debug profiler with information about requests.')
4748
->children()
4849
->booleanNode('enabled')
@@ -54,7 +55,7 @@ public function getConfigTreeBuilder(): TreeBuilder
5455
->arrayNode('fake_ip')
5556
->beforeNormalization()
5657
->ifString()
57-
->then(function ($value) {
58+
->then(function (string $value): array {
5859
return ['ip' => $value];
5960
})
6061
->end()
@@ -132,7 +133,7 @@ private function createClientPluginNode(): ArrayNodeDefinition
132133
$pluginList
133134
// support having just a service id in the list
134135
->beforeNormalization()
135-
->always(function ($plugin) {
136+
->always(function (array|string $plugin) {
136137
if (is_string($plugin)) {
137138
return [
138139
'reference' => [

src/Plugin/ProfilingPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function handleQuery(Query $query, callable $next, callable $first): Prom
4343
{
4444
$startTime = microtime(true);
4545

46-
return $next($query)->then(function (Collection $result) use ($query, $startTime) {
46+
return $next($query)->then(function (Collection $result) use ($query, $startTime): Collection {
4747
$duration = (microtime(true) - $startTime) * 1000;
4848
$this->logQuery($query, $duration, $result);
4949

5050
return $result;
51-
}, function (Exception $exception) use ($query, $startTime) {
51+
}, function (Exception $exception) use ($query, $startTime): void {
5252
$duration = (microtime(true) - $startTime) * 1000;
5353
$this->logQuery($query, $duration, $exception);
5454

tests/Command/GeocodeCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
final class GeocodeCommandTest extends TestCase
3232
{
33-
private static $address = '10 rue Gambetta, Paris, France';
33+
private static string $address = '10 rue Gambetta, Paris, France';
3434

3535
public function testExecute(): void
3636
{

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class ConfigurationTest extends TestCase
2525
public function testGetConfigTreeBuilder(): void
2626
{
2727
$config = Yaml::parseFile(__DIR__.'/Fixtures/config.yml');
28+
self::assertIsArray($config);
2829

2930
$configuration = new Configuration(true);
3031
$treeBuilder = $configuration->getConfigTreeBuilder();
@@ -41,6 +42,7 @@ public function testGetConfigTreeBuilder(): void
4142
public function testGetConfigTreeBuilderNoDebug(): void
4243
{
4344
$config = Yaml::parseFile(__DIR__.'/Fixtures/config.yml');
45+
self::assertIsArray($config);
4446

4547
$configuration = new Configuration(false);
4648
$treeBuilder = $configuration->getConfigTreeBuilder();

tests/Functional/BundleInitializationTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Nyholm\BundleTest\TestKernel;
2828
use Nyholm\NSA;
2929
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
30-
use Symfony\Component\HttpKernel\KernelInterface;
3130

3231
final class BundleInitializationTest extends KernelTestCase
3332
{
@@ -36,11 +35,12 @@ protected static function getKernelClass(): string
3635
return TestKernel::class;
3736
}
3837

39-
protected static function createKernel(array $options = []): KernelInterface
38+
/**
39+
* @param array<mixed> $options
40+
*/
41+
protected static function createKernel(array $options = []): TestKernel
4042
{
41-
/**
42-
* @var TestKernel $kernel
43-
*/
43+
/** @var TestKernel $kernel */
4444
$kernel = parent::createKernel($options);
4545
$kernel->addTestBundle(BazingaGeocoderBundle::class);
4646
$kernel->handleOptions($options);
@@ -93,6 +93,7 @@ public function testBundleWithCachedProvider(): void
9393
$service = $container->get('bazinga_geocoder.provider.acme');
9494
self::assertInstanceOf(PluginProvider::class, $service);
9595
$plugins = NSA::getProperty($service, 'plugins');
96+
self::assertIsArray($plugins);
9697
self::assertNotEmpty($plugins);
9798
self::assertInstanceOf(CachePlugin::class, $plugins[0]);
9899
}
@@ -114,6 +115,7 @@ public function testCacheLifetimeCanBeNull(): void
114115
self::assertInstanceOf(PluginProvider::class, $service);
115116

116117
$plugins = NSA::getProperty($service, 'plugins');
118+
self::assertIsArray($plugins);
117119
self::assertCount(1, $plugins);
118120

119121
$cachePlugin = array_shift($plugins);
@@ -137,6 +139,7 @@ public function testBundleWithPluginsYml(): void
137139
$service = $container->get('bazinga_geocoder.provider.acme');
138140
self::assertInstanceOf(PluginProvider::class, $service);
139141
$plugins = NSA::getProperty($service, 'plugins');
142+
self::assertIsArray($plugins);
140143
self::assertCount(3, $plugins);
141144
self::assertInstanceOf(LoggerPlugin::class, $plugins[0]);
142145
}

tests/Functional/CustomTestKernel.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
class CustomTestKernel extends TestKernel implements CompilerPassInterface
3232
{
33-
private $warmupDir;
33+
private ?string $warmupDir = null;
3434

3535
public function reboot(?string $warmupDir): void
3636
{
@@ -54,6 +54,8 @@ public function getShareDir(): ?string
5454

5555
/**
5656
* Returns the kernel parameters.
57+
*
58+
* @return array<string, mixed>
5759
*/
5860
protected function getKernelParameters(): array
5961
{
@@ -87,14 +89,6 @@ protected function getKernelParameters(): array
8789
] + (null !== ($dir = $this->getShareDir()) ? ['kernel.share_dir' => realpath($dir) ?: $dir] : []);
8890
}
8991

90-
/**
91-
* @internal
92-
*/
93-
public function setAnnotatedClassCache(array $annotatedClasses): void
94-
{
95-
file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map', sprintf('<?php return %s;', var_export($annotatedClasses, true)));
96-
}
97-
9892
// Can be removed after dropping Symfony 5.4
9993
public function process(ContainerBuilder $container): void
10094
{

tests/Functional/Fixtures/Entity/DummyWithEmptyProperty.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class DummyWithEmptyProperty
2929
#[Id]
3030
#[GeneratedValue]
3131
#[Column(type: Types::INTEGER)]
32-
public $id;
32+
public ?int $id = null;
3333

34-
#[Column(nullable: true)]
34+
#[Column(type: Types::FLOAT, nullable: true)]
3535
#[Latitude]
36-
public $latitude;
36+
public ?float $latitude = null;
3737

38-
#[Column(nullable: true)]
38+
#[Column(type: Types::FLOAT, nullable: true)]
3939
#[Longitude]
40-
public $longitude;
40+
public ?float $longitude = null;
4141

42-
#[Column]
42+
#[Column(type: Types::STRING)]
4343
#[Address]
44-
public $address;
44+
public ?string $address = null;
4545
}

0 commit comments

Comments
 (0)