Skip to content

Commit 94389ef

Browse files
authored
Merge pull request #635 from PHPCSStandards/feature/phpstan-2.0-tweaks
PHPStan 2.0: update configuration
2 parents be5942a + e6423c2 commit 94389ef

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

.github/workflows/basics.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
name: "PHPStan"
9393
uses: PHPCSStandards/.github/.github/workflows/reusable-phpstan.yml@main
9494
with:
95-
phpstanVersion: '1.x'
95+
phpstanVersion: '2.x'
9696

9797
markdownlint:
9898
name: 'Lint Markdown'

PHPCSUtils/Internal/IsShortArrayOrList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ final class IsShortArrayOrList
163163
*
164164
* @var string
165165
*/
166-
private $phpcsVersion; // @phpstan-ignore-line
166+
private $phpcsVersion; // @phpstan-ignore property.onlyWritten
167167

168168
/**
169169
* Tokens which can open a short array or short list (PHPCS cross-version compatible).

Tests/TestUtils/UtilityMethodTestCase/SkipJSCSSTestsOnPHPCS4Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testSkipJsCss()
6464
$this->expectExceptionMessage($msg);
6565
} else {
6666
// Get rid of the "does not perform assertions" warning when run with PHPCS 3.x.
67-
$this->assertTrue(true);
67+
$this->assertTrue(true); // @phpstan-ignore method.alreadyNarrowedType
6868
}
6969

7070
parent::skipJSCSSTestsOnPHPCS4();

Tests/Utils/Lists/GetAssignmentsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testGetAssignments($testMarker, $targetToken, $expected)
127127
*
128128
* @see testGetAssignments() For the array format.
129129
*
130-
* @return array<string, array<string, int|string|array<int, array<string, int|string|bool>>>>
130+
* @return array<string, array<string, int|string|array<int|string, int|string|array<string, int|string|bool>>>>
131131
*/
132132
public static function dataGetAssignments()
133133
{

phpstan.neon.dist

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ parameters:
99
excludePaths:
1010
# This file needs to be excluded as the availability of the traits depends on which PHPUnit Polyfills version is loaded/installed.
1111
- Tests/PolyfilledTestCase.php
12+
# These will be seen as unused due to these only being used in conjunction with the above excluded TestCase.
13+
- Tests/AssertPropertySame.php
14+
- Tests/ExpectWithConsecutiveArgs.php
1215
bootstrapFiles:
1316
- Tests/bootstrap.php
1417
treatPhpDocTypesAsCertain: false
@@ -40,6 +43,7 @@ parameters:
4043
message: '`^Call to an undefined method PHP_CodeSniffer\\Config::__destruct\(\)\.$`'
4144
path: PHPCSUtils\TestUtils\UtilityMethodTestCase.php
4245
count: 1
46+
4347
# The setStaticConfigProperty() method exists on the ConfigDouble, not the PHPCS native Config. This is 100% okay.
4448
-
4549
message: '`^Call to an undefined method PHP_CodeSniffer\\Config::setStaticConfigProperty\(\)\.$`'
@@ -50,6 +54,7 @@ parameters:
5054
-
5155
message: '`^Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject::process\(\)\.$`'
5256
path: Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php
57+
5358
# Ignoring as availability depends on which PHPUnit version is loaded/installed. This is 100% okay.
5459
-
5560
message: '`^Call to an undefined method PHPUnit\\Framework\\MockObject\\MockBuilder<[^>]+>::setMethods\(\)\.$`'
@@ -64,33 +69,57 @@ parameters:
6469
path: Tests/BackCompat/Helper/GetCommandLineDataTest.php
6570

6671
# Level 4
72+
# Defensive coding as this project is not type safe. This is okay.
73+
-
74+
message: '`^Call to function is_string\(\) with string will always evaluate to true\.$`'
75+
path: PHPCSUtils/Utils/TypeString.php
76+
count: 1
77+
6778
# This is by design.
6879
-
6980
message: '`^Static method PHPCSUtils\\Tokens\\Collections::triggerDeprecation\(\) is unused\.$`'
7081
path: PHPCSUtils/Tokens/Collections.php
7182
count: 1
7283

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

7998
# Level 5
8099
# This is by design to test handling of incorrect input.
81100
-
82101
message: '`^Parameter #[0-9]+ \$\S+ of static method PHPCSUtils\\(?!Tests)[A-Za-z]+\\[A-Za-z]+::[A-Za-z]+\(\) expects [^,]+, \S+ given\.$`'
83102
paths:
84-
- Tests/*
103+
- Tests/
85104
-
86105
message: '`^Parameter #[0-9]+ \$\S+ of class PHPCSUtils\\(?!Tests)[A-Za-z]+\\[A-Za-z]+ [A-Za-z]+ expects [^,]+, \S+ given\.$`'
87106
path: Tests/Internal/IsShortArrayOrList/ConstructorTest.php
88107
count: 1
108+
-
109+
message: '`^Parameter #1 \$types of static method PHPCSUtils\\Utils\\TypeString::filter\S+\(\) expects array<[^<>]+(<[^<>]+>[^<>]+)*>, array<[^<>]+(<[^<>]+>[^<>]+)*> given\.$`'
110+
path: Tests/Utils/TypeString/FilterTypesTest.php
111+
count: 2
89112

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

96-
# yamllint enable rule:line-length
119+
# Shortcoming of PHPStan, not a real error.
120+
-
121+
message: '`^Parameter #1 \$expected of method PHPUnit\\Framework\\Assert::assertSame\(\) contains unresolvable type\.$`'
122+
paths:
123+
- Tests/
124+
125+
# yamllint enable rule:line-length

0 commit comments

Comments
 (0)