Skip to content

Commit

Permalink
PHPStan 2.0: update configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Nov 11, 2024
1 parent be5942a commit ed18bb4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/basics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
name: "PHPStan"
uses: PHPCSStandards/.github/.github/workflows/reusable-phpstan.yml@main
with:
phpstanVersion: '1.x'
phpstanVersion: '2.x'

markdownlint:
name: 'Lint Markdown'
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Internal/IsShortArrayOrList.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ final class IsShortArrayOrList
*
* @var string
*/
private $phpcsVersion; // @phpstan-ignore-line
private $phpcsVersion; // @phpstan-ignore property.onlyWritten

/**
* Tokens which can open a short array or short list (PHPCS cross-version compatible).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testSkipJsCss()
$this->expectExceptionMessage($msg);
} else {
// Get rid of the "does not perform assertions" warning when run with PHPCS 3.x.
$this->assertTrue(true);
$this->assertTrue(true); // @phpstan-ignore method.alreadyNarrowedType
}

parent::skipJSCSSTestsOnPHPCS4();
Expand Down
2 changes: 1 addition & 1 deletion Tests/Utils/Lists/GetAssignmentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testGetAssignments($testMarker, $targetToken, $expected)
*
* @see testGetAssignments() For the array format.
*
* @return array<string, array<string, int|string|array<int, array<string, int|string|bool>>>>
* @return array<string, array<string, int|string|array<int|string, int|string>|array<int, array<string, int|string|bool>>>>

Check warning on line 130 in Tests/Utils/Lists/GetAssignmentsTest.php

View workflow job for this annotation

GitHub Actions / Basic CS and QA checks

Line exceeds 125 characters; contains 128 characters
*/
public static function dataGetAssignments()
{
Expand Down
33 changes: 31 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ parameters:
excludePaths:
# This file needs to be excluded as the availability of the traits depends on which PHPUnit Polyfills version is loaded/installed.
- Tests/PolyfilledTestCase.php
# These will be seen as unused due to these only being used in conjunction with the above excluded TestCase.
- Tests/AssertPropertySame.php
- Tests/ExpectWithConsecutiveArgs.php
bootstrapFiles:
- Tests/bootstrap.php
treatPhpDocTypesAsCertain: false
Expand Down Expand Up @@ -40,6 +43,7 @@ parameters:
message: '`^Call to an undefined method PHP_CodeSniffer\\Config::__destruct\(\)\.$`'
path: PHPCSUtils\TestUtils\UtilityMethodTestCase.php
count: 1

# The setStaticConfigProperty() method exists on the ConfigDouble, not the PHPCS native Config. This is 100% okay.
-
message: '`^Call to an undefined method PHP_CodeSniffer\\Config::setStaticConfigProperty\(\)\.$`'
Expand All @@ -50,6 +54,7 @@ parameters:
-
message: '`^Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject::process\(\)\.$`'
path: Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php

# Ignoring as availability depends on which PHPUnit version is loaded/installed. This is 100% okay.
-
message: '`^Call to an undefined method PHPUnit\\Framework\\MockObject\\MockBuilder<[^>]+>::setMethods\(\)\.$`'
Expand All @@ -64,33 +69,57 @@ parameters:
path: Tests/BackCompat/Helper/GetCommandLineDataTest.php

# Level 4
# Defensive coding as this project is not type safe. This is okay.
-
message: '`^Call to function is_string\(\) with string will always evaluate to true\.$`'
path: PHPCSUtils/Utils/TypeString.php
count: 1

# This is by design.
-
message: '`^Static method PHPCSUtils\\Tokens\\Collections::triggerDeprecation\(\) is unused\.$`'
path: PHPCSUtils/Tokens/Collections.php
count: 1

# Ignoring this as availability depends on which PHPUnit Polyfills version is loaded/installed. This is 100% okay.
# Ignoring these as availability depends on which PHPUnit/PHPUnit Polyfills version is loaded/installed. This is 100% okay.
-
message: "`^Call to function method_exists\\(\\) with \\$this\\([^)]+\\) and 'expectError' will always evaluate to false\\.$`"
path: Tests/Utils/TypeString/FilterTypesTest.php
count: 2
-
message: "`^Call to function method_exists\\(\\) with \\$this\\([^)]+\\) and 'expectException' will always evaluate to true\\.$`"
path: PHPCSUtils/TestUtils/UtilityMethodTestCase.php
count: 1
-
message: "`^Call to function method_exists\\(\\) with PHPUnit\\\\Framework\\\\MockObject\\\\MockBuilder and 'onlyMethods' will always evaluate to true\\.$`"
path: Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php
count: 1

# Level 5
# This is by design to test handling of incorrect input.
-
message: '`^Parameter #[0-9]+ \$\S+ of static method PHPCSUtils\\(?!Tests)[A-Za-z]+\\[A-Za-z]+::[A-Za-z]+\(\) expects [^,]+, \S+ given\.$`'
paths:
- Tests/*
- Tests/
-
message: '`^Parameter #[0-9]+ \$\S+ of class PHPCSUtils\\(?!Tests)[A-Za-z]+\\[A-Za-z]+ [A-Za-z]+ expects [^,]+, \S+ given\.$`'
path: Tests/Internal/IsShortArrayOrList/ConstructorTest.php
count: 1
-
message: '`^Parameter #1 \$types of static method PHPCSUtils\\Utils\\TypeString::filter\S+\(\) expects array<[^<>]+(<[^<>]+>[^<>]+)*>, array<[^<>]+(<[^<>]+>[^<>]+)*> given\.$`'
path: Tests/Utils/TypeString/FilterTypesTest.php
count: 2

# Ignoring as this is fine.
-
message: '`^Parameter #1 \$exception of method PHPUnit\\Framework\\TestCase::expectException\(\) expects class-string<Throwable>, string given\.$`'
path: Tests/Utils/TypeString/FilterTypesTest.php
count: 2

# Shortcoming of PHPStan, not a real error.
-
message: '`^Parameter #1 \$expected of method PHPUnit\\Framework\\Assert::assertSame\(\) contains unresolvable type\.$`'
paths:
- Tests/

# yamllint enable rule:line-length

0 comments on commit ed18bb4

Please sign in to comment.