Skip to content

Commit 0dfc067

Browse files
Update to PHPStan 2.0
1 parent 75f5686 commit 0dfc067

12 files changed

+64
-14
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
"php": ">=8.0"
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.3.2 || dev-main",
24+
"php-static-analysis/phpstan-extension": "^0.3.2 || dev-main",
25+
"php-static-analysis/psalm-plugin": "^0.3.2 || dev-main",
2626
"phpstan/extension-installer": "^1.3",
27-
"phpstan/phpstan": "^1.8",
27+
"phpstan/phpstan": "^1.8 | ^2.0",
2828
"phpunit/phpunit": "^9.0",
2929
"symplify/easy-coding-standard": "^12.1",
3030
"vimeo/psalm": "^5"

phpstan.neon

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

97
ignoreErrors:
108
- '#^Constructor of class PhpStaticAnalysis\\Attributes\\[a-zA-Z]+ has an unused parameter \$[a-zA-Z]+\.$#'
119
- '#^(Function|Method) [a-zA-Z\:]+\(\) return type has no value type specified in iterable type array.$#'
1210
- '#^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]+$#'
1411
- '#^Attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z]+ constructor invoked with [0-9]+ parameter(s)?, [0-9]+ required.$#'
1512
- '#^Attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z]+ is not repeatable but is already present above the (property|method).$#'
1613
- '#^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.$#'
14+
- '#^PHPDoc tag @[a-z\-A-Z]+ has invalid value \(\): Unexpected token "\\n ", expected type at offset [0-9]+( on line [0-9]+)?$#'
15+
- '#^Possibly impure call to method [a-z\-A-Z]+::[a-z\-A-Z]+\(\) in pure (method|function) ([a-z\-A-Z]+::)?[a-z\-A-Z]+\(\).?$#'
16+
- '#^Possibly impure instantiation of class [a-z\-A-Z]+ in pure function [a-z\-A-Z]+\(\).?$#'
17+
18+
includes:
19+
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

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

tests/TemplateContravariantTest.php

Lines changed: 12 additions & 2 deletions
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+
}

tests/TemplateCovariantTest.php

Lines changed: 12 additions & 2 deletions
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+
}

tests/TemplateExtendsTest.php

Lines changed: 1 addition & 0 deletions
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

tests/TemplateTest.php

Lines changed: 13 additions & 2 deletions
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

tests/TypeTest.php

Lines changed: 1 addition & 0 deletions
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)