Skip to content

Commit

Permalink
Enhancement: Add rule error identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Nov 30, 2024
1 parent b7a42f7 commit 11a8eb5
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

For a full diff see [`2.4.0...main`][2.4.0...main].

### Added

- Added rule error identifiers ([#875]), by [@localheinz]

## [`2.4.0`][2.4.0]

For a full diff see [`2.3.0...2.4.0`][2.3.0...2.4.0].
Expand Down Expand Up @@ -523,6 +527,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0].
[#735]: https://github.com/ergebnis/phpstan-rules/pull/735
[#862]: https://github.com/ergebnis/phpstan-rules/pull/862
[#872]: https://github.com/ergebnis/phpstan-rules/pull/872
[#875]: https://github.com/ergebnis/phpstan-rules/pull/875

[@enumag]: https://github.com/enumag
[@ergebnis]: https://github.com/ergebnis
Expand Down
7 changes: 6 additions & 1 deletion src/Classes/FinalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.final';
}

/**
* This method is inspired by the work on PhpCsFixer\Fixer\ClassNotation\FinalClassFixer and
* PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer contributed by Dariusz Rumiński, Filippo Tessarotto, and
Expand Down
9 changes: 7 additions & 2 deletions src/Classes/NoExtendsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

Expand All @@ -94,7 +94,12 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.noExtends';
}
}
7 changes: 6 additions & 1 deletion src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.classes.phpunit.framework.testCaseWithSuffix';
}
}
7 changes: 6 additions & 1 deletion src/Closures/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Closure has a nullable return type declaration.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

Expand All @@ -73,4 +73,9 @@ private static function hasNullableReturnType(Node\Expr\Closure $node): bool

return false;
}

private static function identifier(): string
{
return 'ergebnis.noNullableReturnTypeDeclaration';
}
}
7 changes: 6 additions & 1 deletion src/Closures/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}, $params);
}

private static function identifier(): string
{
return 'ergebnis.noParameterWithNullDefaultValue';
}
}
7 changes: 6 additions & 1 deletion src/Closures/NoParameterWithNullableTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}, $params);
}

Expand All @@ -90,4 +90,9 @@ private static function isNullable(Node\Param $node): bool

return false;
}

private static function identifier(): string
{
return 'ergebnis.noParameterWithNullableTypeDeclaration';
}
}
7 changes: 6 additions & 1 deletion src/Expressions/NoCompactRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Function compact() should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.noCompact';
}
}
7 changes: 6 additions & 1 deletion src/Expressions/NoErrorSuppressionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Error suppression via "@" should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.noErrorSuppression';
}
}
7 changes: 6 additions & 1 deletion src/Expressions/NoEvalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct eval() should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.noEval';
}
}
7 changes: 6 additions & 1 deletion src/Expressions/NoIssetRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct isset() should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.noIsset';
}
}
7 changes: 6 additions & 1 deletion src/Files/DeclareStrictTypesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('File is missing a "declare(strict_types=1)" declaration.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.declareStrictTypes';
}
}
7 changes: 6 additions & 1 deletion src/Functions/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

Expand All @@ -80,4 +80,9 @@ private static function hasNullableReturnType(Node\Stmt\Function_ $node): bool

return false;
}

private static function identifier(): string
{
return 'ergebnis.functions.noNullableReturnTypeDeclaration';
}
}
7 changes: 6 additions & 1 deletion src/Functions/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}, $params);
}

private static function identifier(): string
{
return 'ergebnis.functions.noParameterWithNullDefaultValue';
}
}
7 changes: 6 additions & 1 deletion src/Functions/NoParameterWithNullableTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}, $params);
}

Expand All @@ -93,4 +93,9 @@ private static function isNullable(Node\Param $node): bool

return false;
}

private static function identifier(): string
{
return 'ergebnis.functions.noParameterWithNullableTypeDeclaration';
}
}
7 changes: 6 additions & 1 deletion src/Methods/FinalInAbstractClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

private static function identifier(): string
{
return 'ergebnis.methods.finalInAbstractClass';
}
}
7 changes: 6 additions & 1 deletion src/Methods/NoConstructorParameterWithDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}, $params);
}

Expand All @@ -93,4 +93,9 @@ public function processNode(
);
}, $params);
}

private static function identifier(): string
{
return 'ergebnis.methods.noConstructorParameterWithDefaultValue';
}
}
9 changes: 7 additions & 2 deletions src/Methods/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

Expand All @@ -66,7 +66,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(self::identifier())->build(),
];
}

Expand All @@ -92,4 +92,9 @@ private static function hasNullableReturnType(Node\Stmt\ClassMethod $node): bool

return false;
}

private static function identifier(): string
{
return 'ergebnis.methods.noNullableReturnTypeDeclaration';
}
}
9 changes: 7 additions & 2 deletions src/Methods/NoParameterWithContainerTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private static function createError(
$classUsedInTypeDeclaration->getName(),
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}

$ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf(
Expand All @@ -178,6 +178,11 @@ private static function createError(
$classUsedInTypeDeclaration->getName(),
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}

private static function identifier(): string
{
return 'ergebnis.methods.noParameterWithContainerTypeDeclaration';
}
}
13 changes: 9 additions & 4 deletions src/Methods/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(self::identifier())->build();
}, $params);
}

$className = $classReflection->getName();

return \array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError {
return \array_values(\array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError {
/** @var Node\Expr\Variable $variable */
$variable = $node->var;

Expand All @@ -96,7 +96,12 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
}, $params);
return $ruleErrorBuilder->identifier(self::identifier())->build();
}, $params));
}

private static function identifier(): string
{
return 'ergebnis.methods.noParameterWithNullDefaultValue';
}
}
Loading

0 comments on commit 11a8eb5

Please sign in to comment.