Skip to content

Commit

Permalink
Update to PHPStan 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-granados committed Dec 24, 2024
1 parent 8d59337 commit 733d862
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 111 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/all_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
fail-fast: false
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: "Checkout"
Expand All @@ -44,4 +44,8 @@ jobs:
run: "composer install --no-interaction --no-progress"

- name: "Run tests"
run: "composer tests"
run: "composer tests-without-psalm"

- name: "Run Psalm"
if: matrix.php-version != '8.4' # Psalm does not fully support PHP 8.4 yet
run: "composer psalm"
24 changes: 16 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.0",
"php-static-analysis/attributes": "^0.3.1 || dev-main",
"php-static-analysis/node-visitor": "^0.3.1 || dev-main",
"phpstan/phpstan": "^1.8",
"php": ">=8.1",
"php-static-analysis/attributes": "^0.4.0 || dev-main",
"php-static-analysis/node-visitor": "^0.4.0 || dev-main",
"phpstan/phpstan": "^2.0",
"webmozart/assert": "^1.11"
},
"require-dev": {
"php-static-analysis/psalm-plugin": "dev-main",
"phpstan/phpstan-deprecation-rules": "^1.1",
"php-static-analysis/psalm-plugin": "^0.4.0 || dev-main",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpunit/phpunit": "^9.0",
"symplify/easy-coding-standard": "^12.1",
"vimeo/psalm": "^5"
"vimeo/psalm": "dev-master"
},
"extra": {
"phpstan": {
Expand All @@ -44,7 +44,10 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-static-analysis/psalm-plugin": true
}
},
"scripts": {
"phpstan": "phpstan analyse",
Expand All @@ -58,6 +61,11 @@
"@phpstan",
"@phpunit",
"@psalm"
],
"tests-without-psalm": [
"@ecs",
"@phpstan",
"@phpunit"
]
}
}
5 changes: 2 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
includes:
- extension.neon
- phar://phpstan.phar/conf/bleedingEdge.neon

parameters:
level: max
Expand All @@ -11,8 +10,8 @@ parameters:
- tests/data/*
ignoreErrors:
-
message: '#^Accessing [a-zA-Z\\]+::class is not covered by backward compatibility promise. The class might change in a minor PHPStan version.$#'
identifier: phpstanApi.classConstant
path: tests/BaseAttributeTestCase.php
-
message: '#^Calling [a-zA-Z\\]+::[a-zA-Z]+\(\) is not covered by backward compatibility promise. The method might change in a minor PHPStan version.$#'
identifier: phpstanApi.method
path: tests/BaseAttributeTestCase.php
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
<directory name="tests/data" />
</ignoreFiles>
</projectFiles>
Expand Down
2 changes: 1 addition & 1 deletion tests/AssertAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testInvalidMethodAssertAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/Assert/InvalidMethodAssertAttribute.php');

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

Expand Down
2 changes: 1 addition & 1 deletion tests/AssertIfFalseAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testInvalidMethodAssertIfFalseAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/AssertIfFalse/InvalidMethodAssertIfFalseAttribute.php');

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

Expand Down
2 changes: 1 addition & 1 deletion tests/AssertIfTrueAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testInvalidMethodAssertIfTrueAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/AssertIfTrue/InvalidMethodAssertIfTrueAttribute.php');

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

Expand Down
7 changes: 3 additions & 4 deletions tests/DefineTypeAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ public function testInvalidClassDefineTypeAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/DefineType/InvalidClassDefineTypeAttribute.php');

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

Expand Down
1 change: 0 additions & 1 deletion tests/DeprecatedAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function testInvalidMethodDeprecatedAttribute(): void

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

$this->checkExpectedErrors($errors, $expectedErrors);
Expand Down
4 changes: 3 additions & 1 deletion tests/ImmutableAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public function testClassImmutableAttribute(): void
{
$errors = $this->analyse(__DIR__ . '/data/Immutable/ClassImmutableAttribute.php');
$expectedErrors = [
'@readonly property cannot have a default value.' => 10,
'@readonly property test\PhpStaticAnalysis\PHPStanExtension\data\Immutable\ClassImmutableAttribute::$name is assigned outside of its declaring class.' => 14,
];

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

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

$this->checkExpectedErrors($errors, $expectedErrors);
Expand Down
3 changes: 1 addition & 2 deletions tests/ImportTypeAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public function testInvalidClassImportTypeAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/ImportType/InvalidClassImportTypeAttribute.php');

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

Expand Down
2 changes: 1 addition & 1 deletion tests/ImpureAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testInvalidMethodImpureAttribute(): void

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

$this->checkExpectedErrors($errors, $expectedErrors);
Expand Down
2 changes: 0 additions & 2 deletions tests/InternalAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public function testInvalidMethodInternalAttribute(): void
{
$errors = $this->analyse(__DIR__ . '/data/Internal/InvalidMethodInternalAttribute.php');
$expectedErrors = [
'Parameter #1 $namespace of attribute class PhpStaticAnalysis\Attributes\Internal constructor expects string|null, int given.' => 9,
'Attribute class PhpStaticAnalysis\Attributes\Internal does not have the parameter target.' => 15,
'Attribute class PhpStaticAnalysis\Attributes\Internal is not repeatable but is already present above the method.' => 22,
];

$this->checkExpectedErrors($errors, $expectedErrors);
Expand Down
12 changes: 0 additions & 12 deletions tests/IsReadOnlyAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,9 @@ public function testInvalidPropertyIsReadOnlyAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/IsReadOnly/InvalidPropertyIsReadOnlyAttribute.php');

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

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

public static function getAdditionalConfigFiles(): array
{
return array_merge(
parent::getAdditionalConfigFiles(),
[
__DIR__ . '/conf/readonly.neon',
]
);
}
}
5 changes: 2 additions & 3 deletions tests/MethodAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public function testInvalidClassMethodAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/Method/InvalidClassMethodAttribute.php');

$expectedErrors = [
'PHPDoc tag @method has invalid value (): Unexpected token "\n * ", expected type at offset 14' => 8,
'PHPDoc tag @method has invalid value (string): Unexpected token "\n * ", expected \'(\' at offset 32' => 8,
'Parameter #1 ...$methods of attribute class PhpStaticAnalysis\Attributes\Method constructor expects string, int given.' => 8,
'PHPDoc tag @method has invalid value (): Unexpected token "\n * ", expected type at offset 14 on line 2' => 9,
'PHPDoc tag @method has invalid value (string): Unexpected token "\n * ", expected \'(\' at offset 32 on line 3' => 10,
'Attribute class PhpStaticAnalysis\Attributes\Method does not have the method target.' => 13,
'Call to an undefined method test\PhpStaticAnalysis\PHPStanExtension\data\Method\InvalidClassMethodAttribute::badFunction().' => 31,
];
Expand Down
5 changes: 2 additions & 3 deletions tests/MixinAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public function testInvalidClassMixinAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/Mixin/InvalidClassMixinAttribute.php');

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

Expand Down
7 changes: 3 additions & 4 deletions tests/ParamAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public function testInvalidMethodParamAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/Param/InvalidMethodParamAttribute.php');

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

Expand Down
7 changes: 3 additions & 4 deletions tests/ParamOutAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public function testInvalidMethodParamOutAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/ParamOut/InvalidMethodParamOutAttribute.php');

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

Expand Down
7 changes: 3 additions & 4 deletions tests/PropertyAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public function testInvalidClassPropertyAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/Property/InvalidClassPropertyAttribute.php');

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

Expand Down
7 changes: 3 additions & 4 deletions tests/PropertyReadAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public function testInvalidClassPropertyReadAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/PropertyRead/InvalidClassPropertyReadAttribute.php');

$expectedErrors = [
'PHPDoc tag @property-read has invalid value (): Unexpected token "\n * ", expected type at offset 21' => 7,
'PHPDoc tag @property-read has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 70' => 7,
'PHPDoc tag @property-read has invalid value (string): Unexpected token "\n * ", expected variable at offset 46' => 7,
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyRead constructor expects string, int given.' => 7,
'PHPDoc tag @property-read has invalid value (): Unexpected token "\n * ", expected type at offset 21 on line 2' => 8,
'PHPDoc tag @property-read has invalid value (string): Unexpected token "\n * ", expected variable at offset 46 on line 3' => 9,
'PHPDoc tag @property-read has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 70 on line 4' => 10,
'Attribute class PhpStaticAnalysis\Attributes\PropertyRead does not have the method target.' => 13,
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead\ClassPropertyReadAttribute::$age is not writable.' => 21,
];
Expand Down
7 changes: 3 additions & 4 deletions tests/PropertyWriteAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public function testInvalidClassPropertyWriteAttribute(): void
$errors = $this->analyse(__DIR__ . '/data/PropertyWrite/InvalidClassPropertyWriteAttribute.php');

$expectedErrors = [
'PHPDoc tag @property-write has invalid value (): Unexpected token "\n * ", expected type at offset 22' => 7,
'PHPDoc tag @property-write has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 73' => 7,
'PHPDoc tag @property-write has invalid value (string): Unexpected token "\n * ", expected variable at offset 48' => 7,
'Parameter #1 ...$properties of attribute class PhpStaticAnalysis\Attributes\PropertyWrite constructor expects string, int given.' => 7,
'PHPDoc tag @property-write has invalid value (): Unexpected token "\n * ", expected type at offset 22 on line 2' => 8,
'PHPDoc tag @property-write has invalid value (string): Unexpected token "\n * ", expected variable at offset 48 on line 3' => 9,
'PHPDoc tag @property-write has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 73 on line 4' => 10,
'Attribute class PhpStaticAnalysis\Attributes\PropertyWrite does not have the method target.' => 13,
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyWrite\ClassPropertyWriteAttribute::$age is not readable.' => 21,
];
Expand Down
2 changes: 1 addition & 1 deletion tests/PureAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testInvalidMethodPureAttribute(): void

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

$this->checkExpectedErrors($errors, $expectedErrors);
Expand Down
Loading

0 comments on commit 733d862

Please sign in to comment.