Skip to content

Commit fc5d60d

Browse files
DjordyKoertDominicLuidolddependabot[bot]
authored
phpstan installation (#2249)
* phpstan installation * remove old symfony 4.2 code * deprecate unused property * remove symfony 5.3 BC layer * remove bleedingEdge * remove phpstan/extension-installer * add phpstan-strict-rules * rename to phpstan.dist.neon * add phpstan job * add phpstan-symfony application loader * remove phpVersion * source code fixes PHPStan level 1 * test code fixes PHPStan level 1 * fix strings used for int Asserts * revert util change for PHP < 8.1 * remove mixed type usage * remove __callStatic * add baseline command * PHPStan level 2 * cleanup ControllerReflector class * remove bitwise operator usage * PHPStan level 3 * PHPStan level 4 * PHPStan level 5 * bump deprecation version Co-authored-by: Dominic Luidold <[email protected]> * Create dependabot.yml * Bump actions/cache from 3 to 4 Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](actions/cache@v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * drop sensio/framework-extra-bundle (#2256) * add phpstan-baseline description * remove config section * move PropertyDescriberInterface errors to baseline * add phpstan.neon to gitignore --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Dominic Luidold <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 8aa0ca0 commit fc5d60d

File tree

74 files changed

+819
-658
lines changed

Some content is hidden

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

74 files changed

+819
-658
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,29 @@ jobs:
101101

102102
- name: Run PHP-CS-Fixer
103103
run: vendor/bin/php-cs-fixer check -v --diff
104+
105+
phpstan:
106+
name: PHPStan
107+
runs-on: ubuntu-22.04
108+
109+
steps:
110+
- name: Checkout
111+
uses: actions/checkout@v4
112+
with:
113+
fetch-depth: 2
114+
115+
- name: Install PHP without coverage
116+
uses: shivammathur/setup-php@v2
117+
with:
118+
php-version: 8.3
119+
tools: composer, flex
120+
coverage: pcov
121+
122+
- name: Setup dependencies
123+
uses: ./.github/workflows/common/composer-install
124+
with:
125+
symfony-version: "7.0.*"
126+
install-doctrine-annotations: false
127+
128+
- name: Run PHPStan
129+
run: vendor/bin/phpstan analyse --memory-limit=2G --no-progress --no-interaction

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/Tests/Functional/cache
99
/Tests/Functional/logs
1010
.idea
11+
/phpstan.neon
1112

1213
###> friendsofphp/php-cs-fixer ###
1314
/.php-cs-fixer.php

composer.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@
5353
"jms/serializer": "^1.14|^3.0",
5454
"composer/package-versions-deprecated": "1.11.99.1",
5555

56-
"phpunit/phpunit": "^8.5|^9.6",
5756
"doctrine/annotations": "^2.0",
58-
"friendsofphp/php-cs-fixer": "^3.52"
57+
58+
"phpunit/phpunit": "^8.5|^9.6",
59+
60+
"friendsofphp/php-cs-fixer": "^3.52",
61+
62+
"phpstan/phpstan": "^1.10",
63+
"phpstan/phpstan-symfony": "^1.3",
64+
"phpstan/phpstan-phpunit": "^1.3",
65+
"phpstan/phpstan-strict-rules": "^1.5"
5966
},
6067
"conflict": {
6168
"zircote/swagger-php": "4.8.7"
@@ -93,11 +100,15 @@
93100
"scripts-descriptions": {
94101
"phpcs-check": "Run PHP-CS-Fixer in dry-run mode",
95102
"phpcs-fix": "Run PHP-CS-Fixer",
96-
"phpunit": "Run phpunit"
103+
"phpunit": "Run phpunit",
104+
"phpstan": "Run phpstan",
105+
"phpstan-baseline": "Generate a baseline for phpstan"
97106
},
98107
"scripts": {
99108
"phpcs-check": "vendor/bin/php-cs-fixer check -v --diff",
100109
"phpcs-fix": "vendor/bin/php-cs-fixer fix -v",
101-
"phpunit": "phpunit"
110+
"phpunit": "phpunit",
111+
"phpstan": "phpstan --memory-limit=2G",
112+
"phpstan-baseline": "phpstan --memory-limit=2G --generate-baseline"
102113
}
103114
}

phpstan-baseline.neon

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
5+
count: 1
6+
path: src/PropertyDescriber/ArrayPropertyDescriber.php
7+
8+
-
9+
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
10+
count: 1
11+
path: src/PropertyDescriber/CompoundPropertyDescriber.php
12+
13+
-
14+
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
15+
count: 1
16+
path: src/PropertyDescriber/DictionaryPropertyDescriber.php
17+
18+
-
19+
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
20+
count: 1
21+
path: src/PropertyDescriber/NullablePropertyDescriber.php
22+
23+
-
24+
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
25+
count: 1
26+
path: src/PropertyDescriber/PropertyDescriber.php
27+
28+
-
29+
message: "#^PHPDoc tag @param references unknown parameter\\: \\$context$#"
30+
count: 1
31+
path: src/PropertyDescriber/PropertyDescriberInterface.php
32+
33+
-
34+
message: "#^PHPDoc tag @param references unknown parameter\\: \\$schema$#"
35+
count: 1
36+
path: src/PropertyDescriber/PropertyDescriberInterface.php
37+
38+
-
39+
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
40+
count: 1
41+
path: src/PropertyDescriber/RequiredPropertyDescriber.php
42+
43+
-
44+
message: "#^Call to method render\\(\\) on an unknown class Twig_Environment\\.$#"
45+
count: 2
46+
path: src/Render/Html/HtmlOpenApiRenderer.php
47+
48+
-
49+
message: "#^Class Twig_Environment not found\\.$#"
50+
count: 1
51+
path: src/Render/Html/HtmlOpenApiRenderer.php
52+
53+
-
54+
message: "#^Property Nelmio\\\\ApiDocBundle\\\\Render\\\\Html\\\\HtmlOpenApiRenderer\\:\\:\\$twig has unknown class Twig_Environment as its type\\.$#"
55+
count: 1
56+
path: src/Render/Html/HtmlOpenApiRenderer.php
57+
58+
-
59+
message: "#^Access to property \\$allowBlank on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam\\.$#"
60+
count: 1
61+
path: src/RouteDescriber/FosRestDescriber.php
62+
63+
-
64+
message: "#^Access to property \\$description on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam\\.$#"
65+
count: 1
66+
path: src/RouteDescriber/FosRestDescriber.php
67+
68+
-
69+
message: "#^Access to property \\$key on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam\\.$#"
70+
count: 1
71+
path: src/RouteDescriber/FosRestDescriber.php
72+
73+
-
74+
message: "#^Access to property \\$key on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\RequestParam\\.$#"
75+
count: 1
76+
path: src/RouteDescriber/FosRestDescriber.php
77+
78+
-
79+
message: "#^Access to property \\$map on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam\\.$#"
80+
count: 2
81+
path: src/RouteDescriber/FosRestDescriber.php
82+
83+
-
84+
message: "#^Access to property \\$nullable on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam\\.$#"
85+
count: 2
86+
path: src/RouteDescriber/FosRestDescriber.php
87+
88+
-
89+
message: "#^Access to property \\$nullable on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\RequestParam\\.$#"
90+
count: 1
91+
path: src/RouteDescriber/FosRestDescriber.php
92+
93+
-
94+
message: "#^Access to property \\$strict on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam\\.$#"
95+
count: 1
96+
path: src/RouteDescriber/FosRestDescriber.php
97+
98+
-
99+
message: "#^Access to property \\$strict on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\RequestParam\\.$#"
100+
count: 1
101+
path: src/RouteDescriber/FosRestDescriber.php
102+
103+
-
104+
message: "#^Call to method getName\\(\\) on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam\\.$#"
105+
count: 1
106+
path: src/RouteDescriber/FosRestDescriber.php
107+
108+
-
109+
message: "#^Call to method getName\\(\\) on an unknown class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\RequestParam\\.$#"
110+
count: 1
111+
path: src/RouteDescriber/FosRestDescriber.php
112+
113+
-
114+
message: "#^Class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\QueryParam not found\\.$#"
115+
count: 3
116+
path: src/RouteDescriber/FosRestDescriber.php
117+
118+
-
119+
message: "#^Class FOS\\\\RestBundle\\\\Controller\\\\Annotations\\\\RequestParam not found\\.$#"
120+
count: 2
121+
path: src/RouteDescriber/FosRestDescriber.php
122+
123+
-
124+
message: "#^Call to function method_exists\\(\\) with 'Hateoas\\\\\\\\Configuration\\\\\\\\Embedded' and 'getType' will always evaluate to true\\.$#"
125+
count: 1
126+
path: tests/Functional/BazingaFunctionalTest.php

phpstan.dist.neon

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
- vendor/phpstan/phpstan-phpunit/extension.neon
4+
- vendor/phpstan/phpstan-phpunit/rules.neon
5+
- vendor/phpstan/phpstan-symfony/extension.neon
6+
- vendor/phpstan/phpstan-symfony/rules.neon
7+
- vendor/phpstan/phpstan-strict-rules/rules.neon
8+
9+
parameters:
10+
level: 5
11+
paths:
12+
- src
13+
- tests
14+
excludePaths:
15+
- tests/Functional/Entity/*
16+
- tests/Functional/EntityExcluded/*
17+
- tests/Functional/Controller/*
18+
dynamicConstantNames:
19+
- Symfony\Component\HttpKernel\Kernel::VERSION
20+
- Symfony\Component\HttpKernel\Kernel::VERSION_ID
21+
- Symfony\Component\HttpKernel\Kernel::MAJOR_VERSION
22+
- Symfony\Component\HttpKernel\Kernel::MINOR_VERSION
23+
- Symfony\Component\HttpKernel\Kernel::RELEASE_VERSION
24+
symfony:
25+
consoleApplicationLoader: tests/console-application.php
26+
strictRules:
27+
noVariableVariables: false # Neccessary for swagger-php integration
28+
universalObjectCratesClasses:
29+
- OpenApi\Context
30+
treatPhpDocTypesAsCertain: false

src/Annotation/Areas.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ final class Areas
2020
/** @var string[] */
2121
private $areas;
2222

23+
/**
24+
* @param string[]|array{value: string[]} $properties
25+
*/
2326
public function __construct(array $properties)
2427
{
2528
if (!array_key_exists('value', $properties) || !is_array($properties['value'])) {
@@ -36,15 +39,11 @@ public function __construct(array $properties)
3639
throw new \InvalidArgumentException('An area must be given as a string');
3740
}
3841

39-
if (!in_array($area, $areas)) {
42+
if (!in_array($area, $areas, true)) {
4043
$areas[] = $area;
4144
}
4245
}
4346

44-
if (0 === count($areas)) {
45-
throw new \LogicException('At least one area is expected');
46-
}
47-
4847
$this->areas = $areas;
4948
}
5049

src/ApiDocGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ public function generate(): OpenApi
9090
return $this->openApi;
9191
}
9292

93-
if ($this->cacheItemPool) {
93+
if (null !== $this->cacheItemPool) {
9494
$item = $this->cacheItemPool->getItem($this->cacheItemId);
9595
if ($item->isHit()) {
9696
return $this->openApi = $item->get();
9797
}
9898
}
9999

100-
if ($this->openApiVersion) {
100+
if (null !== $this->openApiVersion) {
101101
$this->generator->setVersion($this->openApiVersion);
102102
}
103103

src/Command/DumpCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7777
];
7878
}
7979

80-
if ($input->getOption('server-url')) {
80+
if (null !== $input->getOption('server-url')) {
8181
$options['server_url'] = $input->getOption('server-url');
8282
}
8383

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ public function getConfigTreeBuilder(): TreeBuilder
2020
{
2121
$treeBuilder = new TreeBuilder('nelmio_api_doc');
2222

23-
if (method_exists($treeBuilder, 'getRootNode')) {
24-
$rootNode = $treeBuilder->getRootNode();
25-
} else {
26-
// symfony < 4.2 support
27-
$rootNode = $treeBuilder->root('nelmio_api_doc');
28-
}
23+
$rootNode = $treeBuilder->getRootNode();
2924

3025
$rootNode
3126
->children()

src/DependencyInjection/NelmioApiDocExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function load(array $configs, ContainerBuilder $container): void
284284
private function findNameAliases(array $names, string $area): array
285285
{
286286
$nameAliases = array_filter($names, function (array $aliasInfo) use ($area) {
287-
return empty($aliasInfo['areas']) || in_array($area, $aliasInfo['areas'], true);
287+
return [] === $aliasInfo['areas'] || in_array($area, $aliasInfo['areas'], true);
288288
});
289289

290290
$aliases = [];

0 commit comments

Comments
 (0)