Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6e87788

Browse files
committedOct 9, 2024·
Update to PHPStan 2.0
1 parent 08d2039 commit 6e87788

28 files changed

+422
-172
lines changed
 

‎composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"prefer-stable": true,
2525
"require": {
2626
"php": ">=8.0",
27-
"php-static-analysis/attributes": "^0.3.1 || dev-main",
28-
"php-static-analysis/node-visitor": "^0.3.1 || dev-main",
27+
"php-static-analysis/attributes": "^0.3.2 || dev-main",
28+
"php-static-analysis/node-visitor": "^0.3.2 || dev-main",
2929
"phpstan/phpstan": "^1.8 | ^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.3.2 || dev-main",
34+
"phpstan/phpstan-deprecation-rules": "^1.1 | ^2.0",
3535
"phpunit/phpunit": "^9.0",
3636
"symplify/easy-coding-standard": "^12.1",
3737
"vimeo/psalm": "^5"

‎phpstan.neon

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

55
parameters:
66
level: max

‎tests/BaseAttributeTestCase.php

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\Analyser\Analyser;
66
use PHPStan\Analyser\Error;
77
use PHPStan\File\FileHelper;
8+
use PHPStan\Internal\ComposerHelper;
89
use PHPStan\Testing\PHPStanTestCase;
910
use PhpStaticAnalysis\Attributes\Param;
1011
use PhpStaticAnalysis\Attributes\Returns;
@@ -49,4 +50,9 @@ public static function getAdditionalConfigFiles(): array
4950
__DIR__ . '/../extension.neon',
5051
];
5152
}
53+
54+
public static function getPhpStanVersion(): string
55+
{
56+
return ComposerHelper::getPhpStanVersion();
57+
}
5258
}

‎tests/DefineTypeAttributeTest.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,25 @@ public function testInvalidClassDefineTypeAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/DefineType/InvalidClassDefineTypeAttribute.php');
2828

29-
$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,
34-
'Type alias has an invalid name: string.' => 7,
35-
'Attribute class PhpStaticAnalysis\Attributes\DefineType does not have the method target.' => 12,
36-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @phpstan-type has invalid value (): Unexpected token "\n * ", expected type at offset 20' => 7,
32+
'PHPDoc tag @phpstan-type name has invalid value: Unexpected token "(", expected TOKEN_PHPDOC_EOL at offset 72' => 7,
33+
'PHPDoc tag @phpstan-type string has invalid value: Unexpected token "\n * ", expected type at offset 44' => 7,
34+
'Parameter #1 ...$types of attribute class PhpStaticAnalysis\Attributes\DefineType constructor expects string, int given.' => 7,
35+
'Type alias has an invalid name: string.' => 7,
36+
'Attribute class PhpStaticAnalysis\Attributes\DefineType does not have the method target.' => 12,
37+
];
38+
} else {
39+
$expectedErrors = [
40+
'Parameter #1 ...$types of attribute class PhpStaticAnalysis\Attributes\DefineType constructor expects string, int given.' => 7,
41+
'Type alias has an invalid name: string.' => 7,
42+
'PHPDoc tag @phpstan-type has invalid value (): Unexpected token "\n * ", expected type at offset 20 on line 2' => 8,
43+
'PHPDoc tag @phpstan-type string has invalid value: Unexpected token "\n * ", expected type at offset 44 on line 3' => 9,
44+
'PHPDoc tag @phpstan-type name has invalid value: Unexpected token "(", expected TOKEN_PHPDOC_EOL at offset 72 on line 4' => 10,
45+
'Attribute class PhpStaticAnalysis\Attributes\DefineType does not have the method target.' => 12,
46+
];
47+
}
3748

3849
$this->checkExpectedErrors($errors, $expectedErrors);
3950
}

‎tests/ImmutableAttributeTest.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ class ImmutableAttributeTest extends BaseAttributeTestCase
88
public function testClassImmutableAttribute(): void
99
{
1010
$errors = $this->analyse(__DIR__ . '/data/Immutable/ClassImmutableAttribute.php');
11-
$expectedErrors = [
12-
];
11+
if (self::getPhpStanVersion() < '2') {
12+
$expectedErrors = [];
13+
} else {
14+
$expectedErrors = [
15+
'@readonly property cannot have a default value.' => 10,
16+
'@readonly property test\PhpStaticAnalysis\PHPStanExtension\data\Immutable\ClassImmutableAttribute::$name is assigned outside of its declaring class.' => 14,
17+
];
18+
}
1319

1420
$this->checkExpectedErrors($errors, $expectedErrors);
1521
}
@@ -30,10 +36,18 @@ public function testInvalidClassImmutableAttribute(): void
3036
{
3137
$errors = $this->analyse(__DIR__ . '/data/Immutable/InvalidClassImmutableAttribute.php');
3238

33-
$expectedErrors = [
34-
'Attribute class PhpStaticAnalysis\Attributes\Immutable is not repeatable but is already present above the class.' => 10,
35-
'Attribute class PhpStaticAnalysis\Attributes\Immutable does not have the property target.' => 13,
36-
];
39+
if (self::getPhpStanVersion() < '2') {
40+
$expectedErrors = [
41+
'Attribute class PhpStaticAnalysis\Attributes\Immutable is not repeatable but is already present above the class.' => 10,
42+
'Attribute class PhpStaticAnalysis\Attributes\Immutable does not have the property target.' => 13,
43+
];
44+
} else {
45+
$expectedErrors = [
46+
'Attribute class PhpStaticAnalysis\Attributes\Immutable is not repeatable but is already present above the class.' => 10,
47+
'Attribute class PhpStaticAnalysis\Attributes\Immutable does not have the property target.' => 13,
48+
'@readonly property cannot have a default value.' => 14,
49+
];
50+
}
3751

3852
$this->checkExpectedErrors($errors, $expectedErrors);
3953
}

‎tests/ImportTypeAttributeTest.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ public function testInvalidClassImportTypeAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/ImportType/InvalidClassImportTypeAttribute.php');
2828

29-
$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,
32-
'Attribute class PhpStaticAnalysis\Attributes\ImportType does not have the method target.' => 13,
33-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @phpstan-import-type has invalid value (Unexpected token "(", expected \'*/\' at offset 98 on line 4): Unexpected token "(", expected \'*/\' at offset 98' => 8,
32+
'Parameter #1 ...$from of attribute class PhpStaticAnalysis\Attributes\ImportType constructor expects string, int given.' => 8,
33+
'Attribute class PhpStaticAnalysis\Attributes\ImportType does not have the method target.' => 13,
34+
];
35+
} else {
36+
$expectedErrors = [
37+
'Parameter #1 ...$from of attribute class PhpStaticAnalysis\Attributes\ImportType constructor expects string, int given.' => 8,
38+
'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,
39+
'Attribute class PhpStaticAnalysis\Attributes\ImportType does not have the method target.' => 13,
40+
];
41+
}
3442

3543
$this->checkExpectedErrors($errors, $expectedErrors);
3644
}

‎tests/ImpureAttributeTest.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ public function testInvalidMethodImpureAttribute(): void
2020
{
2121
$errors = $this->analyse(__DIR__ . '/data/Impure/InvalidMethodImpureAttribute.php');
2222

23-
$expectedErrors = [
24-
'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,
26-
];
23+
if (self::getPhpStanVersion() < '2') {
24+
$expectedErrors = [
25+
'Attribute class PhpStaticAnalysis\Attributes\Impure does not have the property target.' => 11,
26+
'Attribute class PhpStaticAnalysis\Attributes\Impure is not repeatable but is already present above the method.' => 15,
27+
];
28+
} else {
29+
$expectedErrors = [
30+
'Attribute class PhpStaticAnalysis\Attributes\Impure does not have the property target.' => 11,
31+
'Method test\PhpStaticAnalysis\PHPStanExtension\data\Impure\InvalidMethodImpureAttribute::getMoreName() is marked as impure but does not have any side effects.' => 14,
32+
'Attribute class PhpStaticAnalysis\Attributes\Impure is not repeatable but is already present above the method.' => 15,
33+
];
34+
}
2735

2836
$this->checkExpectedErrors($errors, $expectedErrors);
2937
}

‎tests/IsReadOnlyAttributeTest.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ public function testInvalidPropertyIsReadOnlyAttribute(): void
2929

3030
public static function getAdditionalConfigFiles(): array
3131
{
32-
return array_merge(
33-
parent::getAdditionalConfigFiles(),
34-
[
35-
__DIR__ . '/conf/readonly.neon',
36-
]
37-
);
32+
if (self::getPhpStanVersion() < '2') {
33+
return array_merge(
34+
parent::getAdditionalConfigFiles(),
35+
[
36+
__DIR__ . '/conf/readonly.neon',
37+
]
38+
);
39+
} else {
40+
return parent::getAdditionalConfigFiles();
41+
}
3842
}
3943
}

‎tests/MethodAttributeTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ public function testInvalidClassMethodAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/Method/InvalidClassMethodAttribute.php');
2828

29-
$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,
33-
'Attribute class PhpStaticAnalysis\Attributes\Method does not have the method target.' => 13,
34-
'Call to an undefined method test\PhpStaticAnalysis\PHPStanExtension\data\Method\InvalidClassMethodAttribute::badFunction().' => 31,
35-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @method has invalid value (): Unexpected token "\n * ", expected type at offset 14' => 8,
32+
'PHPDoc tag @method has invalid value (string): Unexpected token "\n * ", expected \'(\' at offset 32' => 8,
33+
'Parameter #1 ...$methods of attribute class PhpStaticAnalysis\Attributes\Method constructor expects string, int given.' => 8,
34+
'Attribute class PhpStaticAnalysis\Attributes\Method does not have the method target.' => 13,
35+
'Call to an undefined method test\PhpStaticAnalysis\PHPStanExtension\data\Method\InvalidClassMethodAttribute::badFunction().' => 31,
36+
];
37+
} else {
38+
$expectedErrors = [
39+
'Parameter #1 ...$methods of attribute class PhpStaticAnalysis\Attributes\Method constructor expects string, int given.' => 8,
40+
'PHPDoc tag @method has invalid value (): Unexpected token "\n * ", expected type at offset 14 on line 2' => 9,
41+
'PHPDoc tag @method has invalid value (string): Unexpected token "\n * ", expected \'(\' at offset 32 on line 3' => 10,
42+
'Attribute class PhpStaticAnalysis\Attributes\Method does not have the method target.' => 13,
43+
'Call to an undefined method test\PhpStaticAnalysis\PHPStanExtension\data\Method\InvalidClassMethodAttribute::badFunction().' => 31,
44+
];
45+
}
3646

3747
$this->checkExpectedErrors($errors, $expectedErrors);
3848
}

‎tests/MixinAttributeTest.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ public function testInvalidClassMixinAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/Mixin/InvalidClassMixinAttribute.php');
2828

29-
$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,
33-
'Attribute class PhpStaticAnalysis\Attributes\Mixin does not have the method target.' => 11,
34-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @mixin contains unknown class test\PhpStaticAnalysis\PHPStanExtension\data\Mixin\count.' => 7,
32+
'PHPDoc tag @mixin has invalid value (): Unexpected token "\n * ", expected type at offset 13' => 7,
33+
'Parameter #1 ...$classes of attribute class PhpStaticAnalysis\Attributes\Mixin constructor expects string, int given.' => 7,
34+
'Attribute class PhpStaticAnalysis\Attributes\Mixin does not have the method target.' => 11,
35+
];
36+
} else {
37+
$expectedErrors = [
38+
'Parameter #1 ...$classes of attribute class PhpStaticAnalysis\Attributes\Mixin constructor expects string, int given.' => 7,
39+
'PHPDoc tag @mixin has invalid value (): Unexpected token "\n * ", expected type at offset 13 on line 2' => 8,
40+
'PHPDoc tag @mixin has invalid value (count($a)): Unexpected token "(", expected TOKEN_HORIZONTAL_WS at offset 29 on line 3' => 9,
41+
'Attribute class PhpStaticAnalysis\Attributes\Mixin does not have the method target.' => 11,
42+
];
43+
}
3544

3645
$this->checkExpectedErrors($errors, $expectedErrors);
3746
}

‎tests/ParamAttributeTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,23 @@ public function testInvalidMethodParamAttribute(): void
2020
{
2121
$errors = $this->analyse(__DIR__ . '/data/Param/InvalidMethodParamAttribute.php');
2222

23-
$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,
28-
'Attribute class PhpStaticAnalysis\Attributes\Param does not have the property target.' => 27,
29-
];
23+
if (self::getPhpStanVersion() < '2') {
24+
$expectedErrors = [
25+
'PHPDoc tag @param has invalid value (): Unexpected token "\n ", expected type at offset 13' => 9,
26+
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Param constructor expects string, int given.' => 9,
27+
'PHPDoc tag @param has invalid value (string): Unexpected token "\n ", expected variable at offset 20' => 15,
28+
'PHPDoc tag @param has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 19' => 21,
29+
'Attribute class PhpStaticAnalysis\Attributes\Param does not have the property target.' => 27,
30+
];
31+
} else {
32+
$expectedErrors = [
33+
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Param constructor expects string, int given.' => 9,
34+
'PHPDoc tag @param has invalid value (): Unexpected token "\n ", expected type at offset 13 on line 2' => 10,
35+
'PHPDoc tag @param has invalid value (string): Unexpected token "\n ", expected variable at offset 20 on line 2' => 16,
36+
'PHPDoc tag @param has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 19 on line 2' => 22,
37+
'Attribute class PhpStaticAnalysis\Attributes\Param does not have the property target.' => 27,
38+
];
39+
}
3040

3141
$this->checkExpectedErrors($errors, $expectedErrors);
3242
}

‎tests/ParamOutAttributeTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,23 @@ public function testInvalidMethodParamOutAttribute(): void
2020
{
2121
$errors = $this->analyse(__DIR__ . '/data/ParamOut/InvalidMethodParamOutAttribute.php');
2222

23-
$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,
28-
'Attribute class PhpStaticAnalysis\Attributes\ParamOut does not have the property target.' => 27,
29-
];
23+
if (self::getPhpStanVersion() < '2') {
24+
$expectedErrors = [
25+
'PHPDoc tag @param-out has invalid value (): Unexpected token "\n ", expected type at offset 17' => 9,
26+
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\ParamOut constructor expects string, int given.' => 9,
27+
'PHPDoc tag @param-out has invalid value (string): Unexpected token "\n ", expected variable at offset 24' => 15,
28+
'PHPDoc tag @param-out has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 23' => 21,
29+
'Attribute class PhpStaticAnalysis\Attributes\ParamOut does not have the property target.' => 27,
30+
];
31+
} else {
32+
$expectedErrors = [
33+
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\ParamOut constructor expects string, int given.' => 9,
34+
'PHPDoc tag @param-out has invalid value (): Unexpected token "\n ", expected type at offset 17 on line 2' => 10,
35+
'PHPDoc tag @param-out has invalid value (string): Unexpected token "\n ", expected variable at offset 24 on line 2' => 16,
36+
'PHPDoc tag @param-out has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 23 on line 2' => 22,
37+
'Attribute class PhpStaticAnalysis\Attributes\ParamOut does not have the property target.' => 27,
38+
];
39+
}
3040

3141
$this->checkExpectedErrors($errors, $expectedErrors);
3242
}

‎tests/PropertyAttributeTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ public function testInvalidClassPropertyAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/Property/InvalidClassPropertyAttribute.php');
2828

29-
$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,
34-
'Attribute class PhpStaticAnalysis\Attributes\Property does not have the method target.' => 12,
35-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @property has invalid value (): Unexpected token "\n * ", expected type at offset 16' => 7,
32+
'PHPDoc tag @property has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 55' => 7,
33+
'PHPDoc tag @property has invalid value (string): Unexpected token "\n * ", expected variable at offset 36' => 7,
34+
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\Property constructor expects string, int given.' => 7,
35+
'Attribute class PhpStaticAnalysis\Attributes\Property does not have the method target.' => 12,
36+
];
37+
} else {
38+
$expectedErrors = [
39+
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\Property constructor expects string, int given.' => 7,
40+
'PHPDoc tag @property has invalid value (): Unexpected token "\n * ", expected type at offset 16 on line 2' => 8,
41+
'PHPDoc tag @property has invalid value (string): Unexpected token "\n * ", expected variable at offset 36 on line 3' => 9,
42+
'PHPDoc tag @property has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 55 on line 4' => 10,
43+
'Attribute class PhpStaticAnalysis\Attributes\Property does not have the method target.' => 12,
44+
];
45+
}
3646

3747
$this->checkExpectedErrors($errors, $expectedErrors);
3848
}

‎tests/PropertyReadAttributeTest.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,25 @@ public function testInvalidClassPropertyReadAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/PropertyRead/InvalidClassPropertyReadAttribute.php');
2828

29-
$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,
34-
'Attribute class PhpStaticAnalysis\Attributes\PropertyRead does not have the method target.' => 13,
35-
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead\ClassPropertyReadAttribute::$age is not writable.' => 21,
36-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @property-read has invalid value (): Unexpected token "\n * ", expected type at offset 21' => 7,
32+
'PHPDoc tag @property-read has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 70' => 7,
33+
'PHPDoc tag @property-read has invalid value (string): Unexpected token "\n * ", expected variable at offset 46' => 7,
34+
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyRead constructor expects string, int given.' => 7,
35+
'Attribute class PhpStaticAnalysis\Attributes\PropertyRead does not have the method target.' => 13,
36+
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead\ClassPropertyReadAttribute::$age is not writable.' => 21,
37+
];
38+
} else {
39+
$expectedErrors = [
40+
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyRead constructor expects string, int given.' => 7,
41+
'PHPDoc tag @property-read has invalid value (): Unexpected token "\n * ", expected type at offset 21 on line 2' => 8,
42+
'PHPDoc tag @property-read has invalid value (string): Unexpected token "\n * ", expected variable at offset 46 on line 3' => 9,
43+
'PHPDoc tag @property-read has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 70 on line 4' => 10,
44+
'Attribute class PhpStaticAnalysis\Attributes\PropertyRead does not have the method target.' => 13,
45+
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead\ClassPropertyReadAttribute::$age is not writable.' => 21,
46+
];
47+
}
3748

3849
$this->checkExpectedErrors($errors, $expectedErrors);
3950
}

‎tests/PropertyWriteAttributeTest.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,25 @@ public function testInvalidClassPropertyWriteAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/PropertyWrite/InvalidClassPropertyWriteAttribute.php');
2828

29-
$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,
34-
'Attribute class PhpStaticAnalysis\Attributes\PropertyWrite does not have the method target.' => 13,
35-
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyWrite\ClassPropertyWriteAttribute::$age is not readable.' => 21,
36-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @property-write has invalid value (): Unexpected token "\n * ", expected type at offset 22' => 7,
32+
'PHPDoc tag @property-write has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 73' => 7,
33+
'PHPDoc tag @property-write has invalid value (string): Unexpected token "\n * ", expected variable at offset 48' => 7,
34+
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyWrite constructor expects string, int given.' => 7,
35+
'Attribute class PhpStaticAnalysis\Attributes\PropertyWrite does not have the method target.' => 13,
36+
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyWrite\ClassPropertyWriteAttribute::$age is not readable.' => 21,
37+
];
38+
} else {
39+
$expectedErrors = [
40+
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyWrite constructor expects string, int given.' => 7,
41+
'PHPDoc tag @property-write has invalid value (): Unexpected token "\n * ", expected type at offset 22 on line 2' => 8,
42+
'PHPDoc tag @property-write has invalid value (string): Unexpected token "\n * ", expected variable at offset 48 on line 3' => 9,
43+
'PHPDoc tag @property-write has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 73 on line 4' => 10,
44+
'Attribute class PhpStaticAnalysis\Attributes\PropertyWrite does not have the method target.' => 13,
45+
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyWrite\ClassPropertyWriteAttribute::$age is not readable.' => 21,
46+
];
47+
}
3748

3849
$this->checkExpectedErrors($errors, $expectedErrors);
3950
}

‎tests/PureAttributeTest.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ public function testInvalidMethodPureAttribute(): void
2020
{
2121
$errors = $this->analyse(__DIR__ . '/data/Pure/InvalidMethodPureAttribute.php');
2222

23-
$expectedErrors = [
24-
'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,
26-
];
23+
if (self::getPhpStanVersion() < '2') {
24+
$expectedErrors = [
25+
'Attribute class PhpStaticAnalysis\Attributes\Pure does not have the property target.' => 11,
26+
'Attribute class PhpStaticAnalysis\Attributes\Pure is not repeatable but is already present above the method.' => 15,
27+
];
28+
} else {
29+
$expectedErrors = [
30+
'Attribute class PhpStaticAnalysis\Attributes\Pure does not have the property target.' => 11,
31+
'Method test\PhpStaticAnalysis\PHPStanExtension\data\Pure\InvalidMethodPureAttribute::getMoreName() is marked as pure but returns void.' => 14,
32+
'Attribute class PhpStaticAnalysis\Attributes\Pure is not repeatable but is already present above the method.' => 15,
33+
];
34+
}
2735

2836
$this->checkExpectedErrors($errors, $expectedErrors);
2937
}

‎tests/RequireExtendsAttributeTest.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@ public function testInvalidClassRequireExtendsAttribute(): void
1818
{
1919
$errors = $this->analyse(__DIR__ . '/data/RequireExtends/InvalidTraitRequireExtendsAttribute.php');
2020

21-
$expectedErrors = [
22-
'PHPDoc tag @phpstan-require-extends has invalid value (): Unexpected token "\n ", expected type at offset 31' => 7,
23-
'Parameter #1 $class of attribute class PhpStaticAnalysis\Attributes\RequireExtends constructor expects string, int given.' => 7,
24-
'PHPDoc tag @phpstan-require-extends contains non-object type int.' => 12,
25-
'PHPDoc tag @phpstan-require-extends can only be used once.' => 17,
26-
'Attribute class PhpStaticAnalysis\Attributes\RequireExtends is not repeatable but is already present above the class.' => 18,
27-
'Attribute class PhpStaticAnalysis\Attributes\RequireExtends does not have the property target.' => 21,
28-
];
21+
if (self::getPhpStanVersion() < '2') {
22+
$expectedErrors = [
23+
'PHPDoc tag @phpstan-require-extends has invalid value (): Unexpected token "\n ", expected type at offset 31' => 7,
24+
'Parameter #1 $class of attribute class PhpStaticAnalysis\Attributes\RequireExtends constructor expects string, int given.' => 7,
25+
'PHPDoc tag @phpstan-require-extends contains non-object type int.' => 12,
26+
'PHPDoc tag @phpstan-require-extends can only be used once.' => 17,
27+
'Attribute class PhpStaticAnalysis\Attributes\RequireExtends is not repeatable but is already present above the class.' => 18,
28+
'Attribute class PhpStaticAnalysis\Attributes\RequireExtends does not have the property target.' => 21,
29+
];
30+
} else {
31+
$expectedErrors = [
32+
'Parameter #1 $class of attribute class PhpStaticAnalysis\Attributes\RequireExtends constructor expects string, int given.' => 7,
33+
'PHPDoc tag @phpstan-require-extends has invalid value (): Unexpected token "\n ", expected type at offset 31 on line 2' => 8,
34+
'PHPDoc tag @phpstan-require-extends contains non-object type int.' => 12,
35+
'PHPDoc tag @phpstan-require-extends can only be used once.' => 17,
36+
'Attribute class PhpStaticAnalysis\Attributes\RequireExtends is not repeatable but is already present above the class.' => 18,
37+
'Attribute class PhpStaticAnalysis\Attributes\RequireExtends does not have the property target.' => 21,
38+
];
39+
}
2940

3041
$this->checkExpectedErrors($errors, $expectedErrors);
3142
}

‎tests/RequireImplementsAttributeTest.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,21 @@ public function testInvalidClassRequireImplementsAttribute(): void
1818
{
1919
$errors = $this->analyse(__DIR__ . '/data/RequireImplements/InvalidTraitRequireImplementsAttribute.php');
2020

21-
$expectedErrors = [
22-
'PHPDoc tag @phpstan-require-implements has invalid value (): Unexpected token "\n ", expected type at offset 34' => 7,
23-
'Parameter #1 ...$interfaces of attribute class PhpStaticAnalysis\Attributes\RequireImplements constructor expects string, int given.' => 7,
24-
'PHPDoc tag @phpstan-require-implements contains non-object type int.' => 12,
25-
'Attribute class PhpStaticAnalysis\Attributes\RequireImplements does not have the property target.' => 15,
26-
];
21+
if (self::getPhpStanVersion() < '2') {
22+
$expectedErrors = [
23+
'PHPDoc tag @phpstan-require-implements has invalid value (): Unexpected token "\n ", expected type at offset 34' => 7,
24+
'Parameter #1 ...$interfaces of attribute class PhpStaticAnalysis\Attributes\RequireImplements constructor expects string, int given.' => 7,
25+
'PHPDoc tag @phpstan-require-implements contains non-object type int.' => 12,
26+
'Attribute class PhpStaticAnalysis\Attributes\RequireImplements does not have the property target.' => 15,
27+
];
28+
} else {
29+
$expectedErrors = [
30+
'Parameter #1 ...$interfaces of attribute class PhpStaticAnalysis\Attributes\RequireImplements constructor expects string, int given.' => 7,
31+
'PHPDoc tag @phpstan-require-implements has invalid value (): Unexpected token "\n ", expected type at offset 34 on line 2' => 8,
32+
'PHPDoc tag @phpstan-require-implements contains non-object type int.' => 12,
33+
'Attribute class PhpStaticAnalysis\Attributes\RequireImplements does not have the property target.' => 15,
34+
];
35+
}
2736

2837
$this->checkExpectedErrors($errors, $expectedErrors);
2938
}

‎tests/ReturnsAttributeTest.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,25 @@ public function testInvalidMethodReturnsAttribute(): void
2020
{
2121
$errors = $this->analyse(__DIR__ . '/data/Returns/InvalidMethodReturnsAttribute.php');
2222

23-
$expectedErrors = [
24-
'PHPDoc tag @return has invalid value (): Unexpected token "\n ", expected type at offset 14' => 9,
25-
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\Returns constructor expects string, int given.' => 9,
26-
'Attribute class PhpStaticAnalysis\Attributes\Returns is not repeatable but is already present above the method.' => 16,
27-
'Attribute class PhpStaticAnalysis\Attributes\Returns constructor invoked with 2 parameters, 1 required.' => 22,
28-
'PHPDoc tag @return has invalid value ($a + $b): Unexpected token "$a", expected type at offset 15' => 28,
29-
'Attribute class PhpStaticAnalysis\Attributes\Returns does not have the property target.' => 34,
30-
];
23+
if (self::getPhpStanVersion() < '2') {
24+
$expectedErrors = [
25+
'PHPDoc tag @return has invalid value (): Unexpected token "\n ", expected type at offset 14' => 9,
26+
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\Returns constructor expects string, int given.' => 9,
27+
'Attribute class PhpStaticAnalysis\Attributes\Returns is not repeatable but is already present above the method.' => 16,
28+
'Attribute class PhpStaticAnalysis\Attributes\Returns constructor invoked with 2 parameters, 1 required.' => 22,
29+
'PHPDoc tag @return has invalid value ($a + $b): Unexpected token "$a", expected type at offset 15' => 28,
30+
'Attribute class PhpStaticAnalysis\Attributes\Returns does not have the property target.' => 34,
31+
];
32+
} else {
33+
$expectedErrors = [
34+
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\Returns constructor expects string, int given.' => 9,
35+
'PHPDoc tag @return has invalid value (): Unexpected token "\n ", expected type at offset 14 on line 2' => 10,
36+
'Attribute class PhpStaticAnalysis\Attributes\Returns is not repeatable but is already present above the method.' => 16,
37+
'Attribute class PhpStaticAnalysis\Attributes\Returns constructor invoked with 2 parameters, 1 required.' => 22,
38+
'PHPDoc tag @return has invalid value ($a + $b): Unexpected token "$a", expected type at offset 15 on line 2' => 29,
39+
'Attribute class PhpStaticAnalysis\Attributes\Returns does not have the property target.' => 34,
40+
];
41+
}
3142

3243
$this->checkExpectedErrors($errors, $expectedErrors);
3344
}

‎tests/SelfOutAttributeTest.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@ public function testInvalidMethodSelfOutAttribute(): void
1414
{
1515
$errors = $this->analyse(__DIR__ . '/data/SelfOut/InvalidMethodSelfOutAttribute.php');
1616

17-
$expectedErrors = [
18-
'PHPDoc tag @phpstan-self-out has invalid value (): Unexpected token "\n ", expected type at offset 75' => 12,
19-
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\SelfOut constructor expects string, int given.' => 14,
20-
'Attribute class PhpStaticAnalysis\Attributes\SelfOut is not repeatable but is already present above the method.' => 22,
21-
'Attribute class PhpStaticAnalysis\Attributes\SelfOut does not have the property target.' => 27,
22-
];
17+
if (self::getPhpStanVersion() < '2') {
18+
$expectedErrors = [
19+
'PHPDoc tag @phpstan-self-out has invalid value (): Unexpected token "\n ", expected type at offset 75' => 12,
20+
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\SelfOut constructor expects string, int given.' => 14,
21+
'Attribute class PhpStaticAnalysis\Attributes\SelfOut is not repeatable but is already present above the method.' => 22,
22+
'Attribute class PhpStaticAnalysis\Attributes\SelfOut does not have the property target.' => 27,
23+
];
24+
} else {
25+
$expectedErrors = [
26+
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\SelfOut constructor expects string, int given.' => 14,
27+
'PHPDoc tag @phpstan-self-out has invalid value (): Unexpected token "\n ", expected type at offset 75 on line 4' => 15,
28+
'Attribute class PhpStaticAnalysis\Attributes\SelfOut is not repeatable but is already present above the method.' => 22,
29+
'Attribute class PhpStaticAnalysis\Attributes\SelfOut does not have the property target.' => 27,
30+
];
31+
}
2332

2433
$this->checkExpectedErrors($errors, $expectedErrors);
2534
}

‎tests/TemplateAttributeTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ public function testInvalidMethodTemplateAttribute(): void
3838
{
3939
$errors = $this->analyse(__DIR__ . '/data/Template/InvalidMethodTemplateAttribute.php');
4040

41-
$expectedErrors = [
42-
'PHPDoc tag @template has invalid value (): Unexpected token "\n ", expected type at offset 16' => 11,
43-
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\Template constructor expects string, int given.' => 11,
44-
'PHPDoc tag @template has invalid value (+5): Unexpected token "+5", expected type at offset 17' => 17,
45-
'Attribute class PhpStaticAnalysis\Attributes\Template does not have the property target.' => 23,
46-
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\Template constructor expects string|null, int given.' => 26
47-
];
41+
if (self::getPhpStanVersion() < '2') {
42+
$expectedErrors = [
43+
'PHPDoc tag @template has invalid value (): Unexpected token "\n ", expected type at offset 16' => 11,
44+
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\Template constructor expects string, int given.' => 11,
45+
'PHPDoc tag @template has invalid value (+5): Unexpected token "+5", expected type at offset 17' => 17,
46+
'Attribute class PhpStaticAnalysis\Attributes\Template does not have the property target.' => 23,
47+
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\Template constructor expects string|null, int given.' => 26
48+
];
49+
} else {
50+
$expectedErrors = [
51+
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\Template constructor expects string, int given.' => 11,
52+
'PHPDoc tag @template has invalid value (): Unexpected token "\n ", expected type at offset 16 on line 2' => 12,
53+
'PHPDoc tag @template has invalid value (+5): Unexpected token "+5", expected type at offset 17 on line 2' => 18,
54+
'Attribute class PhpStaticAnalysis\Attributes\Template does not have the property target.' => 23,
55+
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\Template constructor expects string|null, int given.' => 26,
56+
];
57+
}
4858

4959
$this->checkExpectedErrors($errors, $expectedErrors);
5060
}

‎tests/TemplateContravariantAttributeTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ public function testInvalidClassTemplateContravariantAttribute(): void
2626
{
2727
$errors = $this->analyse(__DIR__ . '/data/TemplateContravariant/InvalidClassTemplateContravariantAttribute.php');
2828

29-
$expectedErrors = [
30-
'PHPDoc tag @template-contravariant has invalid value (): Unexpected token "\n * ", expected type at offset 30' => 7,
31-
'PHPDoc tag @template-contravariant has invalid value (+5): Unexpected token "+5", expected type at offset 58' => 7,
32-
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\TemplateContravariant constructor expects string, int given.' => 7,
33-
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\TemplateContravariant constructor expects string|null, int given.' => 9,
34-
'Attribute class PhpStaticAnalysis\Attributes\TemplateContravariant does not have the property target.' => 12,
35-
];
29+
if (self::getPhpStanVersion() < '2') {
30+
$expectedErrors = [
31+
'PHPDoc tag @template-contravariant has invalid value (): Unexpected token "\n * ", expected type at offset 30' => 7,
32+
'PHPDoc tag @template-contravariant has invalid value (+5): Unexpected token "+5", expected type at offset 58' => 7,
33+
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\TemplateContravariant constructor expects string, int given.' => 7,
34+
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\TemplateContravariant constructor expects string|null, int given.' => 9,
35+
'Attribute class PhpStaticAnalysis\Attributes\TemplateContravariant does not have the property target.' => 12,
36+
];
37+
} else {
38+
$expectedErrors = [
39+
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\TemplateContravariant constructor expects string, int given.' => 7,
40+
'PHPDoc tag @template-contravariant has invalid value (): Unexpected token "\n * ", expected type at offset 30 on line 2' => 8,
41+
'PHPDoc tag @template-contravariant has invalid value (+5): Unexpected token "+5", expected type at offset 58 on line 3' => 9,
42+
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\TemplateContravariant constructor expects string|null, int given.' => 9,
43+
'Attribute class PhpStaticAnalysis\Attributes\TemplateContravariant does not have the property target.' => 12,
44+
];
45+
}
3646

3747
$this->checkExpectedErrors($errors, $expectedErrors);
3848
}

‎tests/TemplateCovariantAttributeTest.php

+25-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ class TemplateCovariantAttributeTest extends BaseAttributeTestCase
77
public function testClassTemplateCovariantAttribute(): void
88
{
99
$errors = $this->analyse(__DIR__ . '/data/TemplateCovariant/ClassTemplateCovariantAttribute.php');
10-
$this->assertCount(0, $errors);
10+
if (self::getPhpStanVersion() < '2') {
11+
$expectedErrors = [];
12+
} else {
13+
$expectedErrors = [
14+
'PHPDoc tag @var with type TCreable is not subtype of native type object.' => 28,
15+
];
16+
}
17+
$this->checkExpectedErrors($errors, $expectedErrors);
1118
}
1219

1320
public function testTraitTemplateCovariantAttribute(): void
@@ -26,13 +33,23 @@ public function testInvalidClassTemplateCovariantAttribute(): void
2633
{
2734
$errors = $this->analyse(__DIR__ . '/data/TemplateCovariant/InvalidClassTemplateCovariantAttribute.php');
2835

29-
$expectedErrors = [
30-
'PHPDoc tag @template-covariant has invalid value (): Unexpected token "\n * ", expected type at offset 26' => 7,
31-
'PHPDoc tag @template-covariant has invalid value (+5): Unexpected token "+5", expected type at offset 50' => 7,
32-
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\TemplateCovariant constructor expects string, int given.' => 7,
33-
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\TemplateCovariant constructor expects string|null, int given.' => 9,
34-
'Attribute class PhpStaticAnalysis\Attributes\TemplateCovariant does not have the property target.' => 12,
35-
];
36+
if (self::getPhpStanVersion() < '2') {
37+
$expectedErrors = [
38+
'PHPDoc tag @template-covariant has invalid value (): Unexpected token "\n * ", expected type at offset 26' => 7,
39+
'PHPDoc tag @template-covariant has invalid value (+5): Unexpected token "+5", expected type at offset 50' => 7,
40+
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\TemplateCovariant constructor expects string, int given.' => 7,
41+
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\TemplateCovariant constructor expects string|null, int given.' => 9,
42+
'Attribute class PhpStaticAnalysis\Attributes\TemplateCovariant does not have the property target.' => 12,
43+
];
44+
} else {
45+
$expectedErrors = [
46+
'Parameter #1 $name of attribute class PhpStaticAnalysis\Attributes\TemplateCovariant constructor expects string, int given.' => 7,
47+
'PHPDoc tag @template-covariant has invalid value (): Unexpected token "\n * ", expected type at offset 26 on line 2' => 8,
48+
'PHPDoc tag @template-covariant has invalid value (+5): Unexpected token "+5", expected type at offset 50 on line 3' => 9,
49+
'Parameter #2 $of of attribute class PhpStaticAnalysis\Attributes\TemplateCovariant constructor expects string|null, int given.' => 9,
50+
'Attribute class PhpStaticAnalysis\Attributes\TemplateCovariant does not have the property target.' => 12,
51+
];
52+
}
3653

3754
$this->checkExpectedErrors($errors, $expectedErrors);
3855
}

‎tests/TemplateExtendsAttributeTest.php

+21-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,27 @@ public function testInvalidClassTemplateExtendsAttribute(): void
1414
{
1515
$errors = $this->analyse(__DIR__ . '/data/TemplateExtends/InvalidClassTemplateExtendsAttribute.php');
1616

17-
$expectedErrors = [
18-
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild extends generic class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttribute but does not specify its types: T' => 13,
19-
'PHPDoc tag @template-extends has invalid value (): Unexpected token "\n ", expected type at offset 24' => 13,
20-
'Parameter #1 $class of attribute class PhpStaticAnalysis\Attributes\TemplateExtends constructor expects string, int given.' => 13,
21-
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild2 extends generic class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttribute but does not specify its types: T' => 18,
22-
'PHPDoc tag @template-extends has invalid value (+5): Unexpected token "+5", expected type at offset 25' => 18,
23-
'Attribute class PhpStaticAnalysis\Attributes\TemplateExtends is not repeatable but is already present above the class.' => 24,
24-
'Attribute class PhpStaticAnalysis\Attributes\TemplateExtends does not have the property target.' => 27,
25-
];
17+
if (self::getPhpStanVersion() < '2') {
18+
$expectedErrors = [
19+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild extends generic class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttribute but does not specify its types: T' => 13,
20+
'PHPDoc tag @template-extends has invalid value (): Unexpected token "\n ", expected type at offset 24' => 13,
21+
'Parameter #1 $class of attribute class PhpStaticAnalysis\Attributes\TemplateExtends constructor expects string, int given.' => 13,
22+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild2 extends generic class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttribute but does not specify its types: T' => 18,
23+
'PHPDoc tag @template-extends has invalid value (+5): Unexpected token "+5", expected type at offset 25' => 18,
24+
'Attribute class PhpStaticAnalysis\Attributes\TemplateExtends is not repeatable but is already present above the class.' => 24,
25+
'Attribute class PhpStaticAnalysis\Attributes\TemplateExtends does not have the property target.' => 27,
26+
];
27+
} else {
28+
$expectedErrors = [
29+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild extends generic class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttribute but does not specify its types: T' => 13,
30+
'Parameter #1 $class of attribute class PhpStaticAnalysis\Attributes\TemplateExtends constructor expects string, int given.' => 13,
31+
'PHPDoc tag @template-extends has invalid value (): Unexpected token "\n ", expected type at offset 24 on line 2' => 14,
32+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild2 extends generic class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateExtends\InvalidClassTemplateExtendsAttribute but does not specify its types: T' => 18,
33+
'PHPDoc tag @template-extends has invalid value (+5): Unexpected token "+5", expected type at offset 25 on line 2' => 19,
34+
'Attribute class PhpStaticAnalysis\Attributes\TemplateExtends is not repeatable but is already present above the class.' => 24,
35+
'Attribute class PhpStaticAnalysis\Attributes\TemplateExtends does not have the property target.' => 27,
36+
];
37+
}
2638

2739
$this->checkExpectedErrors($errors, $expectedErrors);
2840
}

‎tests/TemplateImplementsAttributeTest.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,25 @@ public function testInvalidInterfaceTemplateImplementsAttribute(): void
1414
{
1515
$errors = $this->analyse(__DIR__ . '/data/TemplateImplements/InvalidInterfaceTemplateImplementsAttribute.php');
1616

17-
$expectedErrors = [
18-
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidClassTemplateImplementsAttribute implements generic interface test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute but does not specify its types: T' => 13,
19-
'PHPDoc tag @template-implements has invalid value (): Unexpected token "\n ", expected type at offset 27' => 13,
20-
'Parameter #1 ...$interfaces of attribute class PhpStaticAnalysis\Attributes\TemplateImplements constructor expects string, int given.' => 13,
21-
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidClassTemplateImplementsAttribute2 implements generic interface test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute but does not specify its types: T' => 18,
22-
'PHPDoc tag @template-implements has invalid value (+5): Unexpected token "+5", expected type at offset 28' => 18,
23-
'Attribute class PhpStaticAnalysis\Attributes\TemplateImplements does not have the property target.' => 21,
24-
];
17+
if (self::getPhpStanVersion() < '2') {
18+
$expectedErrors = [
19+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidClassTemplateImplementsAttribute implements generic interface test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute but does not specify its types: T' => 13,
20+
'PHPDoc tag @template-implements has invalid value (): Unexpected token "\n ", expected type at offset 27' => 13,
21+
'Parameter #1 ...$interfaces of attribute class PhpStaticAnalysis\Attributes\TemplateImplements constructor expects string, int given.' => 13,
22+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidClassTemplateImplementsAttribute2 implements generic interface test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute but does not specify its types: T' => 18,
23+
'PHPDoc tag @template-implements has invalid value (+5): Unexpected token "+5", expected type at offset 28' => 18,
24+
'Attribute class PhpStaticAnalysis\Attributes\TemplateImplements does not have the property target.' => 21,
25+
];
26+
} else {
27+
$expectedErrors = [
28+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidClassTemplateImplementsAttribute implements generic interface test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute but does not specify its types: T' => 13,
29+
'Parameter #1 ...$interfaces of attribute class PhpStaticAnalysis\Attributes\TemplateImplements constructor expects string, int given.' => 13,
30+
'PHPDoc tag @template-implements has invalid value (): Unexpected token "\n ", expected type at offset 27 on line 2' => 14,
31+
'Class test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidClassTemplateImplementsAttribute2 implements generic interface test\PhpStaticAnalysis\PHPStanExtension\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute but does not specify its types: T' => 18,
32+
'PHPDoc tag @template-implements has invalid value (+5): Unexpected token "+5", expected type at offset 28 on line 2' => 19,
33+
'Attribute class PhpStaticAnalysis\Attributes\TemplateImplements does not have the property target.' => 21,
34+
];
35+
}
2536

2637
$this->checkExpectedErrors($errors, $expectedErrors);
2738
}

‎tests/ThrowsAttributeTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@ public function testInvalidMethodThrowsAttribute(): void
2424
{
2525
$errors = $this->analyse(__DIR__ . '/data/Throws/InvalidMethodThrowsAttribute.php');
2626

27-
$expectedErrors = [
28-
'PHPDoc tag @throws has invalid value (): Unexpected token "\n ", expected type at offset 14' => 10,
29-
'Parameter #1 ...$exceptions of attribute class PhpStaticAnalysis\Attributes\Throws constructor expects string, int given.' => 10,
30-
'Method test\PhpStaticAnalysis\PHPStanExtension\data\Throws\InvalidMethodThrowsAttribute::getOtherNameLength() has string in PHPDoc @throws tag but it\'s not thrown.' => 16,
31-
'PHPDoc tag @throws with type string is not subtype of Throwable' => 16,
32-
'Attribute class PhpStaticAnalysis\Attributes\Throws does not have the property target.' => 22,
33-
];
27+
if (self::getPhpStanVersion() < '2') {
28+
$expectedErrors = [
29+
'PHPDoc tag @throws has invalid value (): Unexpected token "\n ", expected type at offset 14' => 10,
30+
'Parameter #1 ...$exceptions of attribute class PhpStaticAnalysis\Attributes\Throws constructor expects string, int given.' => 10,
31+
'Method test\PhpStaticAnalysis\PHPStanExtension\data\Throws\InvalidMethodThrowsAttribute::getOtherNameLength() has string in PHPDoc @throws tag but it\'s not thrown.' => 16,
32+
'PHPDoc tag @throws with type string is not subtype of Throwable' => 16,
33+
'Attribute class PhpStaticAnalysis\Attributes\Throws does not have the property target.' => 22,
34+
];
35+
} else {
36+
$expectedErrors = [
37+
'Parameter #1 ...$exceptions of attribute class PhpStaticAnalysis\Attributes\Throws constructor expects string, int given.' => 10,
38+
'PHPDoc tag @throws has invalid value (): Unexpected token "\n ", expected type at offset 14 on line 2' => 11,
39+
'Method test\PhpStaticAnalysis\PHPStanExtension\data\Throws\InvalidMethodThrowsAttribute::getOtherNameLength() has string in PHPDoc @throws tag but it\'s not thrown.' => 16,
40+
'PHPDoc tag @throws with type string is not subtype of Throwable' => 16,
41+
'Attribute class PhpStaticAnalysis\Attributes\Throws does not have the property target.' => 22,
42+
];
43+
}
3444

3545
$this->checkExpectedErrors($errors, $expectedErrors);
3646
}

‎tests/TypeAttributeTest.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,25 @@ public function testInvalidPropertyTypeAttribute(): void
1414
{
1515
$errors = $this->analyse(__DIR__ . '/data/Type/InvalidPropertyTypeAttribute.php');
1616

17-
$expectedErrors = [
18-
'PHPDoc tag @var has invalid value (): Unexpected token "\n ", expected type at offset 11' => 9,
19-
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\Type constructor expects string, int given.' => 9,
20-
'Attribute class PhpStaticAnalysis\Attributes\Type is not repeatable but is already present above the property.' => 13,
21-
'Attribute class PhpStaticAnalysis\Attributes\Type constructor invoked with 2 parameters, 1 required.' => 16,
22-
'PHPDoc tag @var has invalid value ($a + $b): Unexpected token "$a", expected type at offset 12' => 19,
23-
'Attribute class PhpStaticAnalysis\Attributes\Type does not have the parameter target.' => 23,
24-
];
17+
if (self::getPhpStanVersion() < '2') {
18+
$expectedErrors = [
19+
'PHPDoc tag @var has invalid value (): Unexpected token "\n ", expected type at offset 11' => 9,
20+
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\Type constructor expects string, int given.' => 9,
21+
'Attribute class PhpStaticAnalysis\Attributes\Type is not repeatable but is already present above the property.' => 13,
22+
'Attribute class PhpStaticAnalysis\Attributes\Type constructor invoked with 2 parameters, 1 required.' => 16,
23+
'PHPDoc tag @var has invalid value ($a + $b): Unexpected token "$a", expected type at offset 12' => 19,
24+
'Attribute class PhpStaticAnalysis\Attributes\Type does not have the parameter target.' => 23,
25+
];
26+
} else {
27+
$expectedErrors = [
28+
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\Type constructor expects string, int given.' => 9,
29+
'PHPDoc tag @var has invalid value (): Unexpected token "\n ", expected type at offset 11 on line 2' => 10,
30+
'Attribute class PhpStaticAnalysis\Attributes\Type is not repeatable but is already present above the property.' => 13,
31+
'Attribute class PhpStaticAnalysis\Attributes\Type constructor invoked with 2 parameters, 1 required.' => 16,
32+
'PHPDoc tag @var has invalid value ($a + $b): Unexpected token "$a", expected type at offset 12 on line 2' => 20,
33+
'Attribute class PhpStaticAnalysis\Attributes\Type does not have the parameter target.' => 23,
34+
];
35+
}
2536

2637
$this->checkExpectedErrors($errors, $expectedErrors);
2738
}

‎tests/data/Throws/MethodThrowsAttribute.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public function countOtherTwoNames(string $name1, string $name2): int
7070
}
7171

7272
#[Throws(Exception::class)]
73-
public function countNoErrorName(string $name): int
73+
public function countNoErrorName(): void
7474
{
75-
return strlen($name);
7675
}
7776

7877
/**

0 commit comments

Comments
 (0)
Please sign in to comment.