Skip to content

Commit 4b575a5

Browse files
Update to PHPStan 2.0
1 parent 9724f13 commit 4b575a5

15 files changed

+120
-28
lines changed

.github/workflows/all_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
php-version:
17-
- "8.0"
1817
- "8.1"
1918
- "8.2"
2019
- "8.3"
20+
- "8.4"
2121

2222
steps:
2323
- name: "Checkout"

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
"minimum-stability": "dev",
1818
"prefer-stable": true,
1919
"require": {
20-
"php": ">=8.0"
20+
"php": ">=8.1"
2121
},
2222
"require-dev": {
23-
"php-static-analysis/node-visitor": "dev-main",
24-
"php-static-analysis/phpstan-extension": "dev-main",
25-
"php-static-analysis/psalm-plugin": "dev-main",
23+
"php-static-analysis/node-visitor": "^0.4.0 || dev-main",
24+
"php-static-analysis/phpstan-extension": "^0.4.0 || dev-main",
25+
"php-static-analysis/psalm-plugin": "^0.4.0 || dev-main",
2626
"phpstan/extension-installer": "^1.3",
27-
"phpstan/phpstan": "^1.8",
27+
"phpstan/phpstan": "^2.0",
2828
"phpunit/phpunit": "^9.0",
2929
"symplify/easy-coding-standard": "^12.1",
30-
"vimeo/psalm": "^5"
30+
"vimeo/psalm": "dev-master"
3131
},
3232
"scripts": {
3333
"phpstan": "phpstan analyse",
@@ -45,7 +45,8 @@
4545
},
4646
"config": {
4747
"allow-plugins": {
48-
"phpstan/extension-installer": true
48+
"phpstan/extension-installer": true,
49+
"php-static-analysis/psalm-plugin": true
4950
},
5051
"sort-packages": true
5152
},

phpstan.neon

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,61 @@ parameters:
33
paths:
44
- src
55
- tests
6-
featureToggles:
7-
readOnlyByPhpDoc: true
86

97
ignoreErrors:
10-
- '#^Constructor of class PhpStaticAnalysis\\Attributes\\[a-zA-Z]+ has an unused parameter \$[a-zA-Z]+\.$#'
11-
- '#^(Function|Method) [a-zA-Z\:]+\(\) return type has no value type specified in iterable type array.$#'
12-
- '#^Parameter \#1 \.*\$[a-zA-Z]+ of attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z]+ constructor expects string, int given.$#'
13-
- '#^PHPDoc tag @[a-z\-A-Z]+ has invalid value \(\): Unexpected token "\\n ", expected type at offset [0-9]+$#'
14-
- '#^Attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z]+ constructor invoked with [0-9]+ parameter(s)?, [0-9]+ required.$#'
15-
- '#^Attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z]+ is not repeatable but is already present above the (property|method).$#'
16-
- '#^Method [a-zA-Z\:]+\(\) has parameter \$[a-zA-Z]+ with generic class [a-zA-Z]+ but does not specify its types: [a-zA-Z]+$#'
17-
- '#^PHPDoc tag @phpstan-self-out contains generic type [a-zA-Z]+<[a-zA-Z]+> but class [a-zA-Z]+ is not generic.$#'
8+
-
9+
identifier: method.impossibleType
10+
paths:
11+
- tests/AssertIfFalseTest.php
12+
13+
-
14+
identifier: function.impossibleType
15+
paths:
16+
- tests/AssertIfFalseTest.php
17+
18+
-
19+
identifier: assert.alreadyNarrowedType
20+
paths:
21+
- tests/AssertIfFalseTest.php
22+
- tests/AssertIfTrueTest.php
23+
- tests/AssertTest.php
24+
25+
-
26+
identifier: method.alreadyNarrowedType
27+
paths:
28+
- tests/AssertIfTrueTest.php
29+
30+
-
31+
identifier: function.alreadyNarrowedType
32+
paths:
33+
- tests/AssertIfTrueTest.php
34+
35+
-
36+
identifier: constructor.unusedParameter
37+
paths:
38+
- src/*
39+
40+
-
41+
identifier: missingType.iterableValue
42+
paths:
43+
- tests/*
44+
45+
-
46+
identifier: missingType.generics
47+
paths:
48+
- tests/*
49+
50+
-
51+
identifier: phpDoc.parseError
52+
paths:
53+
- tests/*
54+
55+
-
56+
identifier: possiblyImpure.methodCall
57+
paths:
58+
- tests/PureTest.php
59+
60+
-
61+
identifier: possiblyImpure.new
62+
paths:
63+
- tests/PureTest.php

psalm.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
>
1111
<projectFiles>
1212
<directory name="src" />
13-
<ignoreFiles>
14-
<directory name="vendor" />
15-
</ignoreFiles>
1613
</projectFiles>
1714
<plugins>
1815
<pluginClass class="PhpStaticAnalysis\PsalmPlugin\Plugin" />

src/Internal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
final class Internal
1717
{
1818
public function __construct(
19-
string $namespace = null
19+
?string $namespace = null
2020
) {
2121
}
2222
}

tests/DeprecatedTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,8 @@ function functionDeprecated(): bool
107107
$reflection = new ReflectionFunction(__FUNCTION__);
108108
return DeprecatedTest::getDeprecatedFromReflection($reflection);
109109
}
110+
111+
class DeprecatedClass
112+
{
113+
use DeprecatedTestTrait;
114+
}

tests/ImmutableTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ trait ImmutableTestTrait
5151
interface ImmutableTestInterface
5252
{
5353
}
54+
55+
class ImmutableClass
56+
{
57+
use ImmutableTestTrait;
58+
}

tests/RequireExtendsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static function getRequireExtendssFromReflection(
2222
if ($attribute->getName() === RequireExtends::class) {
2323
$attribute->newInstance();
2424
$extends = $attribute->getArguments()[0];
25+
assert(is_string($extends));
2526
}
2627
}
2728

tests/ReturnsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static function getReturnsFromReflection(
9595
if ($attribute->getName() === Returns::class) {
9696
$attribute->newInstance();
9797
$returns = $attribute->getArguments()[0];
98+
assert(is_string($returns));
9899
}
99100
}
100101

tests/SelfOutTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
declare(strict_types=1);
44

55
use PhpStaticAnalysis\Attributes\SelfOut;
6+
use PhpStaticAnalysis\Attributes\Template;
67
use PHPUnit\Framework\TestCase;
78

9+
#[Template('T')]
810
class SelfOutTest extends TestCase
911
{
1012
public function testMethodSelfOut(): void
@@ -84,6 +86,7 @@ private function getSelfOut(string $methodName): string
8486
if ($attribute->getName() === SelfOut::class) {
8587
$attribute->newInstance();
8688
$selfOut = $attribute->getArguments()[0];
89+
assert(is_string($selfOut));
8790
}
8891
}
8992

0 commit comments

Comments
 (0)