Skip to content

Commit 733d862

Browse files
Update to PHPStan 2.0
1 parent 8d59337 commit 733d862

36 files changed

+84
-111
lines changed

Diff for: .github/workflows/all_tests.yml

+6-2
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"
@@ -44,4 +44,8 @@ jobs:
4444
run: "composer install --no-interaction --no-progress"
4545

4646
- name: "Run tests"
47-
run: "composer tests"
47+
run: "composer tests-without-psalm"
48+
49+
- name: "Run Psalm"
50+
if: matrix.php-version != '8.4' # Psalm does not fully support PHP 8.4 yet
51+
run: "composer psalm"

Diff for: composer.json

+16-8
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
"minimum-stability": "dev",
2424
"prefer-stable": true,
2525
"require": {
26-
"php": ">=8.0",
27-
"php-static-analysis/attributes": "^0.3.1 || dev-main",
28-
"php-static-analysis/node-visitor": "^0.3.1 || dev-main",
29-
"phpstan/phpstan": "^1.8",
26+
"php": ">=8.1",
27+
"php-static-analysis/attributes": "^0.4.0 || dev-main",
28+
"php-static-analysis/node-visitor": "^0.4.0 || dev-main",
29+
"phpstan/phpstan": "^2.0",
3030
"webmozart/assert": "^1.11"
3131
},
3232
"require-dev": {
33-
"php-static-analysis/psalm-plugin": "dev-main",
34-
"phpstan/phpstan-deprecation-rules": "^1.1",
33+
"php-static-analysis/psalm-plugin": "^0.4.0 || dev-main",
34+
"phpstan/phpstan-deprecation-rules": "^2.0",
3535
"phpunit/phpunit": "^9.0",
3636
"symplify/easy-coding-standard": "^12.1",
37-
"vimeo/psalm": "^5"
37+
"vimeo/psalm": "dev-master"
3838
},
3939
"extra": {
4040
"phpstan": {
@@ -44,7 +44,10 @@
4444
}
4545
},
4646
"config": {
47-
"sort-packages": true
47+
"sort-packages": true,
48+
"allow-plugins": {
49+
"php-static-analysis/psalm-plugin": true
50+
}
4851
},
4952
"scripts": {
5053
"phpstan": "phpstan analyse",
@@ -58,6 +61,11 @@
5861
"@phpstan",
5962
"@phpunit",
6063
"@psalm"
64+
],
65+
"tests-without-psalm": [
66+
"@ecs",
67+
"@phpstan",
68+
"@phpunit"
6169
]
6270
}
6371
}

Diff for: phpstan.neon

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
includes:
22
- extension.neon
3-
- phar://phpstan.phar/conf/bleedingEdge.neon
43

54
parameters:
65
level: max
@@ -11,8 +10,8 @@ parameters:
1110
- tests/data/*
1211
ignoreErrors:
1312
-
14-
message: '#^Accessing [a-zA-Z\\]+::class is not covered by backward compatibility promise. The class might change in a minor PHPStan version.$#'
13+
identifier: phpstanApi.classConstant
1514
path: tests/BaseAttributeTestCase.php
1615
-
17-
message: '#^Calling [a-zA-Z\\]+::[a-zA-Z]+\(\) is not covered by backward compatibility promise. The method might change in a minor PHPStan version.$#'
16+
identifier: phpstanApi.method
1817
path: tests/BaseAttributeTestCase.php

Diff for: psalm.xml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<directory name="src" />
1313
<directory name="tests" />
1414
<ignoreFiles>
15-
<directory name="vendor" />
1615
<directory name="tests/data" />
1716
</ignoreFiles>
1817
</projectFiles>

Diff for: tests/AssertAttributeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testInvalidMethodAssertAttribute(): void
2121
$errors = $this->analyse(__DIR__ . '/data/Assert/InvalidMethodAssertAttribute.php');
2222

2323
$expectedErrors = [
24-
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Assert constructor expects string, int given.' => 9,
24+
'PHPDoc tag @phpstan-assert has invalid value (): Unexpected token "\n ", expected type at offset 22 on line 2' => 10,
2525
'Attribute class PhpStaticAnalysis\Attributes\Assert does not have the property target.' => 14,
2626
];
2727

Diff for: tests/AssertIfFalseAttributeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testInvalidMethodAssertIfFalseAttribute(): void
2222
$errors = $this->analyse(__DIR__ . '/data/AssertIfFalse/InvalidMethodAssertIfFalseAttribute.php');
2323

2424
$expectedErrors = [
25-
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\AssertIfFalse constructor expects string, int given.' => 9,
25+
'PHPDoc tag @phpstan-assert-if-false has invalid value (): Unexpected token "\n ", expected type at offset 31 on line 2' => 10,
2626
'Attribute class PhpStaticAnalysis\Attributes\AssertIfFalse does not have the property target.' => 15,
2727
];
2828

Diff for: tests/AssertIfTrueAttributeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testInvalidMethodAssertIfTrueAttribute(): void
2222
$errors = $this->analyse(__DIR__ . '/data/AssertIfTrue/InvalidMethodAssertIfTrueAttribute.php');
2323

2424
$expectedErrors = [
25-
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\AssertIfTrue constructor expects string, int given.' => 9,
25+
'PHPDoc tag @phpstan-assert-if-true has invalid value (): Unexpected token "\n ", expected type at offset 30 on line 2' => 10,
2626
'Attribute class PhpStaticAnalysis\Attributes\AssertIfTrue does not have the property target.' => 15,
2727
];
2828

Diff for: tests/DefineTypeAttributeTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ public function testInvalidClassDefineTypeAttribute(): void
2727
$errors = $this->analyse(__DIR__ . '/data/DefineType/InvalidClassDefineTypeAttribute.php');
2828

2929
$expectedErrors = [
30-
'PHPDoc tag @phpstan-type has invalid value (): Unexpected token "\n * ", expected type at offset 20' => 7,
31-
'PHPDoc tag @phpstan-type name has invalid value: Unexpected token "(", expected TOKEN_PHPDOC_EOL at offset 72' => 7,
32-
'PHPDoc tag @phpstan-type string has invalid value: Unexpected token "\n * ", expected type at offset 44' => 7,
33-
'Parameter #1 ...$types of attribute class PhpStaticAnalysis\Attributes\DefineType constructor expects string, int given.' => 7,
3430
'Type alias has an invalid name: string.' => 7,
31+
'PHPDoc tag @phpstan-type has invalid value (): Unexpected token "\n * ", expected type at offset 20 on line 2' => 8,
32+
'PHPDoc tag @phpstan-type string has invalid value: Unexpected token "\n * ", expected type at offset 44 on line 3' => 9,
33+
'PHPDoc tag @phpstan-type name has invalid value: Unexpected token "(", expected TOKEN_PHPDOC_EOL at offset 72 on line 4' => 10,
3534
'Attribute class PhpStaticAnalysis\Attributes\DefineType does not have the method target.' => 12,
3635
];
3736

Diff for: tests/DeprecatedAttributeTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function testInvalidMethodDeprecatedAttribute(): void
5454

5555
$expectedErrors = [
5656
'Attribute class PhpStaticAnalysis\Attributes\Deprecated does not have the parameter target.' => 12,
57-
'Attribute class PhpStaticAnalysis\Attributes\Deprecated is not repeatable but is already present above the method.' => 19,
5857
];
5958

6059
$this->checkExpectedErrors($errors, $expectedErrors);

Diff for: tests/ImmutableAttributeTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public function testClassImmutableAttribute(): void
99
{
1010
$errors = $this->analyse(__DIR__ . '/data/Immutable/ClassImmutableAttribute.php');
1111
$expectedErrors = [
12+
'@readonly property cannot have a default value.' => 10,
13+
'@readonly property test\PhpStaticAnalysis\PHPStanExtension\data\Immutable\ClassImmutableAttribute::$name is assigned outside of its declaring class.' => 14,
1214
];
1315

1416
$this->checkExpectedErrors($errors, $expectedErrors);
@@ -31,8 +33,8 @@ public function testInvalidClassImmutableAttribute(): void
3133
$errors = $this->analyse(__DIR__ . '/data/Immutable/InvalidClassImmutableAttribute.php');
3234

3335
$expectedErrors = [
34-
'Attribute class PhpStaticAnalysis\Attributes\Immutable is not repeatable but is already present above the class.' => 10,
3536
'Attribute class PhpStaticAnalysis\Attributes\Immutable does not have the property target.' => 13,
37+
'@readonly property cannot have a default value.' => 14,
3638
];
3739

3840
$this->checkExpectedErrors($errors, $expectedErrors);

Diff for: tests/ImportTypeAttributeTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public function testInvalidClassImportTypeAttribute(): void
2727
$errors = $this->analyse(__DIR__ . '/data/ImportType/InvalidClassImportTypeAttribute.php');
2828

2929
$expectedErrors = [
30-
'PHPDoc tag @phpstan-import-type has invalid value (Unexpected token "(", expected \'*/\' at offset 98 on line 4): Unexpected token "(", expected \'*/\' at offset 98' => 8,
31-
'Parameter #1 ...$from of attribute class PhpStaticAnalysis\Attributes\ImportType constructor expects string, int given.' => 8,
30+
'PHPDoc tag @phpstan-import-type has invalid value (Unexpected token "(", expected \'*/\' at offset 98 on line 4): Unexpected token "(", expected \'*/\' at offset 98 on line 4' => 11,
3231
'Attribute class PhpStaticAnalysis\Attributes\ImportType does not have the method target.' => 13,
3332
];
3433

Diff for: tests/ImpureAttributeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testInvalidMethodImpureAttribute(): void
2222

2323
$expectedErrors = [
2424
'Attribute class PhpStaticAnalysis\Attributes\Impure does not have the property target.' => 11,
25-
'Attribute class PhpStaticAnalysis\Attributes\Impure is not repeatable but is already present above the method.' => 15,
25+
'Method test\PhpStaticAnalysis\PHPStanExtension\data\Impure\InvalidMethodImpureAttribute::getMoreName() is marked as impure but does not have any side effects.' => 14,
2626
];
2727

2828
$this->checkExpectedErrors($errors, $expectedErrors);

Diff for: tests/InternalAttributeTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function testInvalidMethodInternalAttribute(): void
4444
{
4545
$errors = $this->analyse(__DIR__ . '/data/Internal/InvalidMethodInternalAttribute.php');
4646
$expectedErrors = [
47-
'Parameter #1 $namespace of attribute class PhpStaticAnalysis\Attributes\Internal constructor expects string|null, int given.' => 9,
4847
'Attribute class PhpStaticAnalysis\Attributes\Internal does not have the parameter target.' => 15,
49-
'Attribute class PhpStaticAnalysis\Attributes\Internal is not repeatable but is already present above the method.' => 22,
5048
];
5149

5250
$this->checkExpectedErrors($errors, $expectedErrors);

Diff for: tests/IsReadOnlyAttributeTest.php

-12
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,9 @@ public function testInvalidPropertyIsReadOnlyAttribute(): void
1919
$errors = $this->analyse(__DIR__ . '/data/IsReadOnly/InvalidPropertyIsReadOnlyAttribute.php');
2020

2121
$expectedErrors = [
22-
'Attribute class PhpStaticAnalysis\Attributes\IsReadOnly constructor invoked with 1 parameter, 0 required.' => 9,
23-
'Attribute class PhpStaticAnalysis\Attributes\IsReadOnly is not repeatable but is already present above the property.' => 13,
2422
'Attribute class PhpStaticAnalysis\Attributes\IsReadOnly does not have the method target.' => 16,
2523
];
2624

2725
$this->checkExpectedErrors($errors, $expectedErrors);
2826
}
29-
30-
public static function getAdditionalConfigFiles(): array
31-
{
32-
return array_merge(
33-
parent::getAdditionalConfigFiles(),
34-
[
35-
__DIR__ . '/conf/readonly.neon',
36-
]
37-
);
38-
}
3927
}

Diff for: tests/MethodAttributeTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ public function testInvalidClassMethodAttribute(): void
2727
$errors = $this->analyse(__DIR__ . '/data/Method/InvalidClassMethodAttribute.php');
2828

2929
$expectedErrors = [
30-
'PHPDoc tag @method has invalid value (): Unexpected token "\n * ", expected type at offset 14' => 8,
31-
'PHPDoc tag @method has invalid value (string): Unexpected token "\n * ", expected \'(\' at offset 32' => 8,
32-
'Parameter #1 ...$methods of attribute class PhpStaticAnalysis\Attributes\Method constructor expects string, int given.' => 8,
30+
'PHPDoc tag @method has invalid value (): Unexpected token "\n * ", expected type at offset 14 on line 2' => 9,
31+
'PHPDoc tag @method has invalid value (string): Unexpected token "\n * ", expected \'(\' at offset 32 on line 3' => 10,
3332
'Attribute class PhpStaticAnalysis\Attributes\Method does not have the method target.' => 13,
3433
'Call to an undefined method test\PhpStaticAnalysis\PHPStanExtension\data\Method\InvalidClassMethodAttribute::badFunction().' => 31,
3534
];

Diff for: tests/MixinAttributeTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ public function testInvalidClassMixinAttribute(): void
2727
$errors = $this->analyse(__DIR__ . '/data/Mixin/InvalidClassMixinAttribute.php');
2828

2929
$expectedErrors = [
30-
'PHPDoc tag @mixin contains unknown class test\PhpStaticAnalysis\PHPStanExtension\data\Mixin\count.' => 7,
31-
'PHPDoc tag @mixin has invalid value (): Unexpected token "\n * ", expected type at offset 13' => 7,
32-
'Parameter #1 ...$classes of attribute class PhpStaticAnalysis\Attributes\Mixin constructor expects string, int given.' => 7,
30+
'PHPDoc tag @mixin has invalid value (): Unexpected token "\n * ", expected type at offset 13 on line 2' => 8,
31+
'PHPDoc tag @mixin has invalid value (count($a)): Unexpected token "(", expected TOKEN_HORIZONTAL_WS at offset 29 on line 3' => 9,
3332
'Attribute class PhpStaticAnalysis\Attributes\Mixin does not have the method target.' => 11,
3433
];
3534

Diff for: tests/ParamAttributeTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public function testInvalidMethodParamAttribute(): void
2121
$errors = $this->analyse(__DIR__ . '/data/Param/InvalidMethodParamAttribute.php');
2222

2323
$expectedErrors = [
24-
'PHPDoc tag @param has invalid value (): Unexpected token "\n ", expected type at offset 13' => 9,
25-
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Param constructor expects string, int given.' => 9,
26-
'PHPDoc tag @param has invalid value (string): Unexpected token "\n ", expected variable at offset 20' => 15,
27-
'PHPDoc tag @param has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 19' => 21,
24+
'PHPDoc tag @param has invalid value (): Unexpected token "\n ", expected type at offset 13 on line 2' => 10,
25+
'PHPDoc tag @param has invalid value (string): Unexpected token "\n ", expected variable at offset 20 on line 2' => 16,
26+
'PHPDoc tag @param has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 19 on line 2' => 22,
2827
'Attribute class PhpStaticAnalysis\Attributes\Param does not have the property target.' => 27,
2928
];
3029

Diff for: tests/ParamOutAttributeTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public function testInvalidMethodParamOutAttribute(): void
2121
$errors = $this->analyse(__DIR__ . '/data/ParamOut/InvalidMethodParamOutAttribute.php');
2222

2323
$expectedErrors = [
24-
'PHPDoc tag @param-out has invalid value (): Unexpected token "\n ", expected type at offset 17' => 9,
25-
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\ParamOut constructor expects string, int given.' => 9,
26-
'PHPDoc tag @param-out has invalid value (string): Unexpected token "\n ", expected variable at offset 24' => 15,
27-
'PHPDoc tag @param-out has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 23' => 21,
24+
'PHPDoc tag @param-out has invalid value (): Unexpected token "\n ", expected type at offset 17 on line 2' => 10,
25+
'PHPDoc tag @param-out has invalid value (string): Unexpected token "\n ", expected variable at offset 24 on line 2' => 16,
26+
'PHPDoc tag @param-out has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 23 on line 2' => 22,
2827
'Attribute class PhpStaticAnalysis\Attributes\ParamOut does not have the property target.' => 27,
2928
];
3029

Diff for: tests/PropertyAttributeTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public function testInvalidClassPropertyAttribute(): void
2727
$errors = $this->analyse(__DIR__ . '/data/Property/InvalidClassPropertyAttribute.php');
2828

2929
$expectedErrors = [
30-
'PHPDoc tag @property has invalid value (): Unexpected token "\n * ", expected type at offset 16' => 7,
31-
'PHPDoc tag @property has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 55' => 7,
32-
'PHPDoc tag @property has invalid value (string): Unexpected token "\n * ", expected variable at offset 36' => 7,
33-
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\Property constructor expects string, int given.' => 7,
30+
'PHPDoc tag @property has invalid value (): Unexpected token "\n * ", expected type at offset 16 on line 2' => 8,
31+
'PHPDoc tag @property has invalid value (string): Unexpected token "\n * ", expected variable at offset 36 on line 3' => 9,
32+
'PHPDoc tag @property has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 55 on line 4' => 10,
3433
'Attribute class PhpStaticAnalysis\Attributes\Property does not have the method target.' => 12,
3534
];
3635

Diff for: tests/PropertyReadAttributeTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public function testInvalidClassPropertyReadAttribute(): void
2727
$errors = $this->analyse(__DIR__ . '/data/PropertyRead/InvalidClassPropertyReadAttribute.php');
2828

2929
$expectedErrors = [
30-
'PHPDoc tag @property-read has invalid value (): Unexpected token "\n * ", expected type at offset 21' => 7,
31-
'PHPDoc tag @property-read has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 70' => 7,
32-
'PHPDoc tag @property-read has invalid value (string): Unexpected token "\n * ", expected variable at offset 46' => 7,
33-
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyRead constructor expects string, int given.' => 7,
30+
'PHPDoc tag @property-read has invalid value (): Unexpected token "\n * ", expected type at offset 21 on line 2' => 8,
31+
'PHPDoc tag @property-read has invalid value (string): Unexpected token "\n * ", expected variable at offset 46 on line 3' => 9,
32+
'PHPDoc tag @property-read has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 70 on line 4' => 10,
3433
'Attribute class PhpStaticAnalysis\Attributes\PropertyRead does not have the method target.' => 13,
3534
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead\ClassPropertyReadAttribute::$age is not writable.' => 21,
3635
];

Diff for: tests/PropertyWriteAttributeTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public function testInvalidClassPropertyWriteAttribute(): void
2727
$errors = $this->analyse(__DIR__ . '/data/PropertyWrite/InvalidClassPropertyWriteAttribute.php');
2828

2929
$expectedErrors = [
30-
'PHPDoc tag @property-write has invalid value (): Unexpected token "\n * ", expected type at offset 22' => 7,
31-
'PHPDoc tag @property-write has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 73' => 7,
32-
'PHPDoc tag @property-write has invalid value (string): Unexpected token "\n * ", expected variable at offset 48' => 7,
33-
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyWrite constructor expects string, int given.' => 7,
30+
'PHPDoc tag @property-write has invalid value (): Unexpected token "\n * ", expected type at offset 22 on line 2' => 8,
31+
'PHPDoc tag @property-write has invalid value (string): Unexpected token "\n * ", expected variable at offset 48 on line 3' => 9,
32+
'PHPDoc tag @property-write has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 73 on line 4' => 10,
3433
'Attribute class PhpStaticAnalysis\Attributes\PropertyWrite does not have the method target.' => 13,
3534
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyWrite\ClassPropertyWriteAttribute::$age is not readable.' => 21,
3635
];

Diff for: tests/PureAttributeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testInvalidMethodPureAttribute(): void
2222

2323
$expectedErrors = [
2424
'Attribute class PhpStaticAnalysis\Attributes\Pure does not have the property target.' => 11,
25-
'Attribute class PhpStaticAnalysis\Attributes\Pure is not repeatable but is already present above the method.' => 15,
25+
'Method test\PhpStaticAnalysis\PHPStanExtension\data\Pure\InvalidMethodPureAttribute::getMoreName() is marked as pure but returns void.' => 14,
2626
];
2727

2828
$this->checkExpectedErrors($errors, $expectedErrors);

0 commit comments

Comments
 (0)