Skip to content

Commit

Permalink
Deny phpstan-ignore-line in favour of phpstan-ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed May 14, 2024
1 parent 8ae5cb4 commit a894f62
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 8 deletions.
33 changes: 33 additions & 0 deletions bin/verify-inline-ignore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types = 1);

$error = false;
$paths = [
__DIR__ . '/../src',
__DIR__ . '/../tests',
];

foreach ($paths as $path) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));

foreach ($iterator as $entry) {
/** @var DirectoryIterator $entry */
if (!$entry->isFile() || $entry->getExtension() !== 'php') {
continue;
}

$realpath = realpath($entry->getPathname());
$contents = file_get_contents($realpath);
if (strpos($contents, '@phpstan-ignore-') !== false) {
$error = true;
echo $realpath . ' uses @phpstan-ignore-line, use \'@phpstan-ignore identifier (reason)\' instead' . PHP_EOL;
}
}
}

if ($error) {
exit(1);
} else {
echo 'Ok, no non-identifier based inline ignore found' . PHP_EOL;
exit(0);
}

2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@
"@check:tests",
"@check:dependencies",
"@check:collisions",
"@check:ignores",
"@check:readme"
],
"check:collisions": "detect-collisions src tests",
"check:composer": "composer normalize --dry-run --no-check-lock --no-update-lock",
"check:cs": "phpcs",
"check:dependencies": "composer-dependency-analyser",
"check:ec": "ec src tests",
"check:ignores": "php bin/verify-inline-ignore.php",
"check:readme": "php bin/verify-readme-default-config.php",
"check:tests": "phpunit -vvv tests",
"check:types": "phpstan analyse -vvv --ansi",
Expand Down
4 changes: 2 additions & 2 deletions src/Rule/EnforceNativeReturnTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private function getUnionTypehint(
foreach ($type->getTypes() as $subtype) {
$wrap = false;

if ($subtype instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection
if ($subtype instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType
if ($this->phpVersion->getVersionId() < 80_200) { // DNF
return null;
}
Expand Down Expand Up @@ -286,7 +286,7 @@ private function getIntersectionTypehint(
bool $alwaysThrowsException
): ?string
{
if (!$type instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection
if (!$type instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Rule/ForbidVariableTypeOverwritingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function generalize(Type $type): Type
if (
$type->isConstantValue()->yes()
|| $type instanceof IntegerRangeType
|| $type instanceof EnumCaseObjectType // @phpstan-ignore-line ignore instanceof warning
|| $type instanceof EnumCaseObjectType // @phpstan-ignore phpstanApi.instanceofType
) {
$type = $type->generalize(GeneralizePrecision::lessSpecific());
}
Expand All @@ -108,7 +108,7 @@ private function removeNullAccessoryAndSubtractedTypes(Type $type): Type
return $type;
}

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

foreach ($type->getTypes() as $innerType) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/EnforceClosureParamNativeTypehintRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testNoErrorOnPhp74(): void

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

}
2 changes: 1 addition & 1 deletion tests/Rule/EnforceNativeReturnTypehintRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testPhp74(): void

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

}
2 changes: 1 addition & 1 deletion tests/Rule/EnforceReadonlyPublicPropertyRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testPhp80(): void

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

}
2 changes: 1 addition & 1 deletion tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function getRule(): Rule
return new ForbidCheckedExceptionInCallableRule(
self::getContainer()->getByType(NodeScopeResolver::class),
self::getContainer()->getByType(ReflectionProvider::class),
new DefaultExceptionTypeResolver( // @phpstan-ignore-line ignore BC promise
new DefaultExceptionTypeResolver( // @phpstan-ignore phpstanApi.constructor
self::getContainer()->getByType(ReflectionProvider::class),
[],
[],
Expand Down

0 comments on commit a894f62

Please sign in to comment.