Skip to content

Commit 4b575a5

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

15 files changed

+120
-28
lines changed

Diff for: .github/workflows/all_tests.yml

+1-1
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"

Diff for: composer.json

+8-7
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
},

Diff for: phpstan.neon

+56-10
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

Diff for: psalm.xml

-3
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" />

Diff for: src/Internal.php

+1-1
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
}

Diff for: tests/DeprecatedTest.php

+5
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+
}

Diff for: tests/ImmutableTest.php

+5
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+
}

Diff for: tests/RequireExtendsTest.php

+1
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

Diff for: tests/ReturnsTest.php

+1
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

Diff for: tests/SelfOutTest.php

+3
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

Diff for: tests/TemplateContravariantTest.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use PhpStaticAnalysis\Attributes\TemplateContravariant;
6+
use PhpStaticAnalysis\Attributes\TemplateUse;
67
use PHPUnit\Framework\TestCase;
78

89
#[TemplateContravariant('TClass', Exception::class)]
@@ -36,8 +37,11 @@ public static function getTemplateContravariantsFromReflection(
3637
$attribute->newInstance();
3738
$templateData = $attribute->getArguments();
3839
$templateValue = $templateData[0];
39-
if (isset($templateData[1]) && $templateData[1] !== null) {
40-
$templateValue .= ' of ' . $templateData[1];
40+
assert(is_string($templateValue));
41+
if (isset($templateData[1])) {
42+
$className = $templateData[1];
43+
assert(is_string($className));
44+
$templateValue .= ' of ' . $className;
4145
}
4246
$templates[] = $templateValue;
4347
}
@@ -56,3 +60,9 @@ trait TemplateContravariantTestTrait
5660
interface TemplateContravariantTestInterface
5761
{
5862
}
63+
64+
#[TemplateUse('TemplateContravariantTestTrait<string>')]
65+
class ContravariantClass
66+
{
67+
use TemplateContravariantTestTrait;
68+
}

Diff for: tests/TemplateCovariantTest.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use PhpStaticAnalysis\Attributes\TemplateCovariant;
6+
use PhpStaticAnalysis\Attributes\TemplateUse;
67
use PHPUnit\Framework\TestCase;
78

89
#[TemplateCovariant('TClass', Exception::class)]
@@ -36,8 +37,11 @@ public static function getTemplateCovariantsFromReflection(
3637
$attribute->newInstance();
3738
$templateData = $attribute->getArguments();
3839
$templateValue = $templateData[0];
39-
if (isset($templateData[1]) && $templateData[1] !== null) {
40-
$templateValue .= ' of ' . $templateData[1];
40+
assert(is_string($templateValue));
41+
if (isset($templateData[1])) {
42+
$className = $templateData[1];
43+
assert(is_string($className));
44+
$templateValue .= ' of ' . $className;
4145
}
4246
$templates[] = $templateValue;
4347
}
@@ -56,3 +60,9 @@ trait TemplateCovariantTestTrait
5660
interface TemplateCovariantTestInterface
5761
{
5862
}
63+
64+
#[TemplateUse('TemplateCovariantTestTrait<string>')]
65+
class CovariantClass
66+
{
67+
use TemplateCovariantTestTrait;
68+
}

Diff for: tests/TemplateExtendsTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static function getTemplateExtendssFromReflection(
2323
if ($attribute->getName() === TemplateExtends::class) {
2424
$attribute->newInstance();
2525
$extends = $attribute->getArguments()[0];
26+
assert(is_string($extends));
2627
}
2728
}
2829

Diff for: tests/TemplateTest.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpStaticAnalysis\Attributes\Param;
66
use PhpStaticAnalysis\Attributes\Template;
7+
use PhpStaticAnalysis\Attributes\TemplateUse;
78
use PHPUnit\Framework\TestCase;
89

910
#[Template('TClass')]
@@ -103,8 +104,11 @@ public static function getTemplatesFromReflection(
103104
$attribute->newInstance();
104105
$templateData = $attribute->getArguments();
105106
$templateValue = $templateData[0];
106-
if (isset($templateData[1]) && $templateData[1] !== null) {
107-
$templateValue .= ' of ' . $templateData[1];
107+
assert(is_string($templateValue));
108+
if (isset($templateData[1])) {
109+
$className = $templateData[1];
110+
assert(is_string($className));
111+
$templateValue .= ' of ' . $className;
108112
}
109113
$templates[] = $templateValue;
110114
}
@@ -124,6 +128,13 @@ interface TemplateTestInterface
124128
{
125129
}
126130

131+
#[TemplateUse('TemplateTestTrait<string>')]
132+
class TemplateClass
133+
{
134+
use TemplateTestTrait;
135+
}
136+
137+
127138
#[Template('TFunction')]
128139
#[Param(param: 'TFunction')]
129140
function functionTemplate($param): array

Diff for: tests/TypeTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public static function getTypeFromReflection(
138138
if ($attribute->getName() === Type::class) {
139139
$attribute->newInstance();
140140
$type = $attribute->getArguments()[0];
141+
assert(is_string($type));
141142
}
142143
}
143144

0 commit comments

Comments
 (0)