Skip to content

Commit bcc5446

Browse files
committed
Fix phpstan issues
1 parent 7f1dc66 commit bcc5446

File tree

9 files changed

+51
-132
lines changed

9 files changed

+51
-132
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ jobs:
1515
- uses: shivammathur/setup-php@v2
1616
with:
1717
php-version: 8.4
18-
tools: composer-normalize, composer-require-checker
18+
tools: composer-normalize, composer-require-checker, composer-unused
1919
- uses: ramsey/composer-install@v3
2020
- run: composer validate --no-ansi --strict composer.json
2121
- run: composer-normalize --dry-run
22+
- run: composer-unused
2223
- run: composer-require-checker check
2324
coding-guidelines:
2425
name: Coding Guidelines
@@ -99,6 +100,7 @@ jobs:
99100
php-version: 8.4
100101
tools: infection
101102
- uses: ramsey/composer-install@v3
102-
- run: infection --min-msi=78 --min-covered-msi=80 --threads=4
103+
- run: |
104+
infection --min-msi=78 --min-covered-msi=80 --threads=4 "--threads=$(nproc)"
103105
env:
104106
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
vendor/
2-
composer.lock
3-
.phpunit.result.cache
42
var/
53
tools/
6-
coverage/
4+
coverage/
5+
6+
composer.lock
7+
8+
.php-cs-fixer.cache
9+
.phpunit.result.cache

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
},
2323
"require-dev": {
2424
"nyholm/symfony-bundle-test": "^3.0",
25+
"phpstan/extension-installer": "^1.4",
26+
"phpstan/phpstan-symfony": "^2.0",
2527
"phpunit/phpunit": "^9.5",
2628
"symfony/browser-kit": "^7.1",
2729
"symfony/monolog-bundle": "^3.10",
@@ -41,6 +43,7 @@
4143
},
4244
"config": {
4345
"allow-plugins": {
46+
"phpstan/extension-installer": true,
4447
"symfony/runtime": true
4548
}
4649
}

phpstan-baseline.neon

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Parameter \#1 \$value of method SoureCode\\Bundle\\Timezone\\Manager\\TimezoneManager\:\:setTimezone\(\) expects DateTimeZone\|string, mixed given\.$#'
5-
identifier: argument.type
6-
count: 1
7-
path: src/EventListener/TimezoneListener.php
8-
9-
-
10-
message: '#^Method SoureCode\\Bundle\\Timezone\\Manager\\TimezoneManager\:\:__construct\(\) has parameter \$enabledTimezoneNames with no value type specified in iterable type array\.$#'
11-
identifier: missingType.iterableValue
12-
count: 1
13-
path: src/Manager/TimezoneManager.php
14-
15-
-
16-
message: '#^Method SoureCode\\Bundle\\Timezone\\Manager\\TimezoneManager\:\:getEnabledTimezoneNames\(\) return type has no value type specified in iterable type array\.$#'
17-
identifier: missingType.iterableValue
18-
count: 1
19-
path: src/Manager/TimezoneManager.php
20-
21-
-
22-
message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:fixXmlConfig\(\)\.$#'
23-
identifier: method.notFound
24-
count: 1
25-
path: src/SoureCodeTimezoneBundle.php
26-
27-
-
28-
message: '#^Cannot call method arrayNode\(\) on mixed\.$#'
29-
identifier: method.nonObject
30-
count: 1
31-
path: src/SoureCodeTimezoneBundle.php
32-
33-
-
34-
message: '#^Cannot call method children\(\) on mixed\.$#'
35-
identifier: method.nonObject
36-
count: 1
37-
path: src/SoureCodeTimezoneBundle.php
38-
39-
-
40-
message: '#^Cannot call method defaultValue\(\) on mixed\.$#'
41-
identifier: method.nonObject
42-
count: 1
43-
path: src/SoureCodeTimezoneBundle.php
44-
45-
-
46-
message: '#^Cannot call method end\(\) on mixed\.$#'
47-
identifier: method.nonObject
48-
count: 6
49-
path: src/SoureCodeTimezoneBundle.php
50-
51-
-
52-
message: '#^Cannot call method ifTrue\(\) on mixed\.$#'
53-
identifier: method.nonObject
54-
count: 2
55-
path: src/SoureCodeTimezoneBundle.php
56-
57-
-
58-
message: '#^Cannot call method info\(\) on mixed\.$#'
59-
identifier: method.nonObject
60-
count: 2
61-
path: src/SoureCodeTimezoneBundle.php
62-
63-
-
64-
message: '#^Cannot call method scalarNode\(\) on mixed\.$#'
65-
identifier: method.nonObject
66-
count: 1
67-
path: src/SoureCodeTimezoneBundle.php
68-
69-
-
70-
message: '#^Cannot call method scalarPrototype\(\) on mixed\.$#'
71-
identifier: method.nonObject
72-
count: 1
73-
path: src/SoureCodeTimezoneBundle.php
74-
75-
-
76-
message: '#^Cannot call method then\(\) on mixed\.$#'
77-
identifier: method.nonObject
78-
count: 1
79-
path: src/SoureCodeTimezoneBundle.php
80-
81-
-
82-
message: '#^Cannot call method thenInvalid\(\) on mixed\.$#'
83-
identifier: method.nonObject
84-
count: 1
85-
path: src/SoureCodeTimezoneBundle.php
86-
87-
-
88-
message: '#^Cannot call method validate\(\) on mixed\.$#'
89-
identifier: method.nonObject
90-
count: 2
91-
path: src/SoureCodeTimezoneBundle.php
92-
93-
-
94-
message: '#^Method SoureCode\\Bundle\\Timezone\\SoureCodeTimezoneBundle\:\:loadExtension\(\) has parameter \$config with no value type specified in iterable type array\.$#'
95-
identifier: missingType.iterableValue
96-
count: 1
97-
path: src/SoureCodeTimezoneBundle.php
98-
993
-
1004
message: '#^Method SoureCode\\Bundle\\Timezone\\Tests\\BundleInitializationTest\:\:createKernel\(\) has parameter \$options with no value type specified in iterable type array\.$#'
1015
identifier: missingType.iterableValue
@@ -119,9 +23,3 @@ parameters:
11923
identifier: missingType.return
12024
count: 1
12125
path: tests/Manager/TimezoneManagerTest.php
122-
123-
-
124-
message: '#^Parameter \#1 \$value of method SoureCode\\Bundle\\Timezone\\Manager\\TimezoneManager\:\:setTimezone\(\) expects DateTimeZone\|string, float\|int\<min, \-1\>\|int\<1, max\>\|string\|true given\.$#'
125-
identifier: argument.type
126-
count: 1
127-
path: tests/app/src/Controller/TestController.php

scripts/ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ symfony composer validate --no-ansi --strict composer.json
1616
kyx composer-normalize --dry-run
1717
kyx composer-require-checker check
1818
kyx composer-unused
19-
kyx php-cs-fixer fix --dry-run --show-progress=dots --using-cache=no --verbose
19+
FORCED_PHP_VERSION=8.3 kyx php-cs-fixer fix --dry-run --show-progress=dots --using-cache=no --verbose
2020
kyx phpstan analyse --memory-limit=512M --ansi --no-progress --error-format=table
2121
vendor/bin/phpunit
22-
kyx infection --threads=4
22+
kyx infection "-j$(nproc)"
2323

2424
popd >/dev/null

scripts/fix.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ fi
1313

1414
symfony composer update
1515
kyx composer-normalize
16-
kyx php-cs-fixer fix --show-progress=dots --using-cache=no --verbose
16+
FORCED_PHP_VERSION=8.3 kyx php-cs-fixer fix --show-progress=dots --using-cache=no --verbose
1717

1818
popd >/dev/null

src/EventListener/TimezoneListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function onKernelRequest(RequestEvent $event): void
4444

4545
private function setTimezone(Request $request): void
4646
{
47-
if ($timezone = $request->attributes->get('_timezone')) {
47+
$timezone = $request->attributes->getString('_timezone');
48+
49+
if ('' !== $timezone) {
4850
$this->timezoneManager->setTimezone($timezone);
4951
} else {
5052
$request->attributes->set('_timezone', $this->timezoneManager->getTimezone()->getName());

src/Manager/TimezoneManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class TimezoneManager
1313
private \DateTimeZone $timezone;
1414

1515
public function __construct(
16+
/**
17+
* @var list<string> $enabledTimezoneNames
18+
*/
1619
private array $enabledTimezoneNames = [],
1720
private readonly ?Environment $twig = null,
1821
) {
1922
if (empty($this->enabledTimezoneNames)) {
20-
$this->enabledTimezoneNames = Timezones::getIds();
23+
$this->enabledTimezoneNames = array_values(Timezones::getIds());
2124
}
2225

2326
$this->timezone = new \DateTimeZone('Etc/UTC');
@@ -63,6 +66,9 @@ public function getTimezone(): \DateTimeZone
6366
return $this->timezone;
6467
}
6568

69+
/**
70+
* @return list<string>
71+
*/
6672
public function getEnabledTimezoneNames(): array
6773
{
6874
return $this->enabledTimezoneNames;

src/SoureCodeTimezoneBundle.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use SoureCode\Bundle\Timezone\EventListener\TimezoneListener;
66
use SoureCode\Bundle\Timezone\Manager\TimezoneManager;
7+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
78
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
910
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@@ -21,31 +22,35 @@ public function configure(DefinitionConfigurator $definition): void
2122
{
2223
$timezones = Timezones::getIds();
2324

25+
/**
26+
* @var ArrayNodeDefinition $rootNode
27+
*/
28+
$rootNode = $definition->rootNode();
29+
$children = $rootNode->fixXmlConfig('timezone')->children();
30+
2431
// @formatter:off
25-
$definition->rootNode()
26-
->fixXmlConfig('timezone')
27-
->children()
28-
->scalarNode('default_timezone')
29-
->defaultValue('Etc/UTC')
30-
->info('The default timezone.')
31-
->validate()
32-
->ifTrue(fn ($v) => !\in_array($v, $timezones, true))
33-
->thenInvalid('The timezone "%s" is not valid.')
34-
->end()
35-
->end()
36-
->arrayNode('enabled_timezones')
37-
->scalarPrototype()->end()
38-
->info('List of enabled timezones. If empty, all timezones are enabled.')
39-
->validate()
40-
->ifTrue(fn (array $values) => \count(array_diff($values, $timezones)) > 0)
41-
->then(fn (array $values) => throw new \InvalidArgumentException(\sprintf('The timezones "%s" are not valid.', implode('", "', array_diff($values, $timezones)))))
42-
->end()
43-
->end()
44-
->end()
32+
$children
33+
->scalarNode('default_timezone')
34+
->defaultValue('Etc/UTC')
35+
->info('The default timezone.')
36+
->validate()
37+
->ifTrue(fn ($v) => !\in_array($v, $timezones, true))
38+
->thenInvalid('The timezone "%s" is not valid.');
39+
40+
$children
41+
->arrayNode('enabled_timezones')
42+
->scalarPrototype()->end()
43+
->info('List of enabled timezones. If empty, all timezones are enabled.')
44+
->validate()
45+
->ifTrue(fn (array $values) => \count(array_diff($values, $timezones)) > 0)
46+
->then(fn (array $values) => throw new \InvalidArgumentException(\sprintf('The timezones "%s" are not valid.', implode('", "', array_diff($values, $timezones)))))
4547
;
4648
// @formatter:on
4749
}
4850

51+
/**
52+
* @param array{default_timezone: string, enabled_timezones: list<string>} $config
53+
*/
4954
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
5055
{
5156
$parameters = $container->parameters();

0 commit comments

Comments
 (0)