Skip to content

Commit 04cf295

Browse files
authored
Deny @phpstan-ignore-line in favour of @phpstan-ignore (#246)
1 parent 8ae5cb4 commit 04cf295

8 files changed

+43
-8
lines changed

bin/verify-inline-ignore.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types = 1);
2+
3+
$error = false;
4+
$paths = [
5+
__DIR__ . '/../src',
6+
__DIR__ . '/../tests',
7+
];
8+
9+
foreach ($paths as $path) {
10+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
11+
12+
foreach ($iterator as $entry) {
13+
/** @var DirectoryIterator $entry */
14+
if (!$entry->isFile() || $entry->getExtension() !== 'php') {
15+
continue;
16+
}
17+
18+
$realpath = realpath($entry->getPathname());
19+
$contents = file_get_contents($realpath);
20+
if (strpos($contents, '@phpstan-ignore-') !== false) {
21+
$error = true;
22+
echo $realpath . ' uses @phpstan-ignore-line, use \'@phpstan-ignore identifier (reason)\' instead' . PHP_EOL;
23+
}
24+
}
25+
}
26+
27+
if ($error) {
28+
exit(1);
29+
} else {
30+
echo 'Ok, no non-identifier based inline ignore found' . PHP_EOL;
31+
exit(0);
32+
}
33+

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@
6060
"@check:tests",
6161
"@check:dependencies",
6262
"@check:collisions",
63+
"@check:ignores",
6364
"@check:readme"
6465
],
6566
"check:collisions": "detect-collisions src tests",
6667
"check:composer": "composer normalize --dry-run --no-check-lock --no-update-lock",
6768
"check:cs": "phpcs",
6869
"check:dependencies": "composer-dependency-analyser",
6970
"check:ec": "ec src tests",
71+
"check:ignores": "php bin/verify-inline-ignore.php",
7072
"check:readme": "php bin/verify-readme-default-config.php",
7173
"check:tests": "phpunit -vvv tests",
7274
"check:types": "phpstan analyse -vvv --ansi",

src/Rule/EnforceNativeReturnTypehintRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private function getUnionTypehint(
255255
foreach ($type->getTypes() as $subtype) {
256256
$wrap = false;
257257

258-
if ($subtype instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection
258+
if ($subtype instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType
259259
if ($this->phpVersion->getVersionId() < 80_200) { // DNF
260260
return null;
261261
}
@@ -286,7 +286,7 @@ private function getIntersectionTypehint(
286286
bool $alwaysThrowsException
287287
): ?string
288288
{
289-
if (!$type instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection
289+
if (!$type instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType
290290
return null;
291291
}
292292

src/Rule/ForbidVariableTypeOverwritingRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function generalize(Type $type): Type
8585
if (
8686
$type->isConstantValue()->yes()
8787
|| $type instanceof IntegerRangeType
88-
|| $type instanceof EnumCaseObjectType // @phpstan-ignore-line ignore instanceof warning
88+
|| $type instanceof EnumCaseObjectType // @phpstan-ignore phpstanApi.instanceofType
8989
) {
9090
$type = $type->generalize(GeneralizePrecision::lessSpecific());
9191
}
@@ -108,7 +108,7 @@ private function removeNullAccessoryAndSubtractedTypes(Type $type): Type
108108
return $type;
109109
}
110110

111-
if ($type instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection
111+
if ($type instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType
112112
$newInnerTypes = [];
113113

114114
foreach ($type->getTypes() as $innerType) {

tests/Rule/EnforceClosureParamNativeTypehintRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testNoErrorOnPhp74(): void
5858

5959
private function createPhpVersion(int $version): PhpVersion
6060
{
61-
return new PhpVersion($version); // @phpstan-ignore-line ignore bc promise
61+
return new PhpVersion($version); // @phpstan-ignore phpstanApi.constructor
6262
}
6363

6464
}

tests/Rule/EnforceNativeReturnTypehintRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testPhp74(): void
6363

6464
private function createPhpVersion(int $version): PhpVersion
6565
{
66-
return new PhpVersion($version); // @phpstan-ignore-line ignore bc promise
66+
return new PhpVersion($version); // @phpstan-ignore phpstanApi.constructor
6767
}
6868

6969
}

tests/Rule/EnforceReadonlyPublicPropertyRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testPhp80(): void
3434

3535
private function createPhpVersion(int $version): PhpVersion
3636
{
37-
return new PhpVersion($version); // @phpstan-ignore-line ignore bc promise
37+
return new PhpVersion($version); // @phpstan-ignore phpstanApi.constructor
3838
}
3939

4040
}

tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function getRule(): Rule
3535
return new ForbidCheckedExceptionInCallableRule(
3636
self::getContainer()->getByType(NodeScopeResolver::class),
3737
self::getContainer()->getByType(ReflectionProvider::class),
38-
new DefaultExceptionTypeResolver( // @phpstan-ignore-line ignore BC promise
38+
new DefaultExceptionTypeResolver( // @phpstan-ignore phpstanApi.constructor
3939
self::getContainer()->getByType(ReflectionProvider::class),
4040
[],
4141
[],

0 commit comments

Comments
 (0)