diff --git a/.gitignore b/.gitignore index 382f83c8..232352a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor composer.lock +.idea .phpunit.cache diff --git a/src/Rules/NarrowPrivateClassMethodParamTypeRule.php b/src/Rules/NarrowPrivateClassMethodParamTypeRule.php index 73146a2a..907402eb 100644 --- a/src/Rules/NarrowPrivateClassMethodParamTypeRule.php +++ b/src/Rules/NarrowPrivateClassMethodParamTypeRule.php @@ -175,6 +175,7 @@ private function validateParam(Param $param, int $position, Expr $expr, Scope $s $errorMessage = sprintf(self::ERROR_MESSAGE, $position + 1, $argTypeAsString); return RuleErrorBuilder::message($errorMessage) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) ->line($param->getLine()) ->build(); } diff --git a/src/Rules/NarrowPublicClassMethodParamTypeRule.php b/src/Rules/NarrowPublicClassMethodParamTypeRule.php index 99423020..1211642e 100644 --- a/src/Rules/NarrowPublicClassMethodParamTypeRule.php +++ b/src/Rules/NarrowPublicClassMethodParamTypeRule.php @@ -73,6 +73,7 @@ public function processNode(Node $node, Scope $scope): array } $ruleErrors[] = RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $uniqueCollectedArgTypesString)) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) ->file($filePath) ->line($line) ->build(); diff --git a/src/Rules/NarrowReturnObjectTypeRule.php b/src/Rules/NarrowReturnObjectTypeRule.php index dc56e489..b80668ed 100644 --- a/src/Rules/NarrowReturnObjectTypeRule.php +++ b/src/Rules/NarrowReturnObjectTypeRule.php @@ -11,6 +11,8 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; @@ -47,7 +49,7 @@ public function getNodeType(): string /** * @param ClassMethod $node - * @return mixed[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -94,7 +96,12 @@ public function processNode(Node $node, Scope $scope): array /** @var TypeWithClassName $returnExprType */ $errorMessage = sprintf(self::ERROR_MESSAGE, $returnExprType->getClassName()); - return [$errorMessage]; + + return [ + RuleErrorBuilder::message($errorMessage) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), + ]; } private function shouldSkipReturnObjectType(ObjectType $objectType): bool diff --git a/src/Rules/NoArrayAccessOnObjectRule.php b/src/Rules/NoArrayAccessOnObjectRule.php index ea7aaf31..0a364593 100644 --- a/src/Rules/NoArrayAccessOnObjectRule.php +++ b/src/Rules/NoArrayAccessOnObjectRule.php @@ -8,6 +8,8 @@ use PhpParser\Node\Expr\ArrayDimFetch; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; /** @@ -36,7 +38,7 @@ public function getNodeType(): string /** * @param ArrayDimFetch $node - * @return string[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -50,7 +52,9 @@ public function processNode(Node $node, Scope $scope): array } return [ - self::ERROR_MESSAGE, + RuleErrorBuilder::message(self::ERROR_MESSAGE) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), ]; } diff --git a/src/Rules/NoEmptyOnObjectRule.php b/src/Rules/NoEmptyOnObjectRule.php index 7e40d732..90bd2051 100644 --- a/src/Rules/NoEmptyOnObjectRule.php +++ b/src/Rules/NoEmptyOnObjectRule.php @@ -8,6 +8,8 @@ use PhpParser\Node\Expr\Empty_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use Rector\TypePerfect\Guard\EmptyIssetGuard; /** @@ -32,7 +34,7 @@ public function getNodeType(): string /** * @param Empty_ $node - * @return string[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -41,7 +43,9 @@ public function processNode(Node $node, Scope $scope): array } return [ - self::ERROR_MESSAGE, + RuleErrorBuilder::message(self::ERROR_MESSAGE) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), ]; } } diff --git a/src/Rules/NoIssetOnObjectRule.php b/src/Rules/NoIssetOnObjectRule.php index e4b55c0e..0af939c8 100644 --- a/src/Rules/NoIssetOnObjectRule.php +++ b/src/Rules/NoIssetOnObjectRule.php @@ -8,6 +8,8 @@ use PhpParser\Node\Expr\Isset_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use Rector\TypePerfect\Guard\EmptyIssetGuard; /** @@ -34,7 +36,7 @@ public function getNodeType(): string /** * @param Isset_ $node * - * @return string[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -44,7 +46,9 @@ public function processNode(Node $node, Scope $scope): array } return [ - self::ERROR_MESSAGE, + RuleErrorBuilder::message(self::ERROR_MESSAGE) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), ]; } diff --git a/src/Rules/NoMixedMethodCallerRule.php b/src/Rules/NoMixedMethodCallerRule.php index 690b0cf1..7ba5292c 100644 --- a/src/Rules/NoMixedMethodCallerRule.php +++ b/src/Rules/NoMixedMethodCallerRule.php @@ -9,6 +9,8 @@ use PhpParser\PrettyPrinter\Standard; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ErrorType; use PHPStan\Type\MixedType; use Rector\TypePerfect\Configuration; @@ -40,7 +42,7 @@ public function getNodeType(): string /** * @param MethodCall $node - * @return mixed[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -66,7 +68,9 @@ public function processNode(Node $node, Scope $scope): array $printedMethodCall = $this->printerStandard->prettyPrintExpr($node->var); return [ - sprintf(self::ERROR_MESSAGE, $printedMethodCall), + RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $printedMethodCall)) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), ]; } diff --git a/src/Rules/NoMixedPropertyFetcherRule.php b/src/Rules/NoMixedPropertyFetcherRule.php index 992d4ae1..0d15db08 100644 --- a/src/Rules/NoMixedPropertyFetcherRule.php +++ b/src/Rules/NoMixedPropertyFetcherRule.php @@ -9,6 +9,8 @@ use PhpParser\PrettyPrinter\Standard; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\MixedType; use Rector\TypePerfect\Configuration; @@ -39,7 +41,7 @@ public function getNodeType(): string /** * @param PropertyFetch $node - * @return mixed[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -54,6 +56,10 @@ public function processNode(Node $node, Scope $scope): array $printedVar = $this->standard->prettyPrintExpr($node->var); - return [sprintf(self::ERROR_MESSAGE, $printedVar)]; + return [ + RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $printedVar)) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), + ]; } } diff --git a/src/Rules/NoParamTypeRemovalRule.php b/src/Rules/NoParamTypeRemovalRule.php index 40ffb35b..6c9ced13 100644 --- a/src/Rules/NoParamTypeRemovalRule.php +++ b/src/Rules/NoParamTypeRemovalRule.php @@ -9,6 +9,8 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\Php\PhpMethodReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\MixedType; use PHPStan\Type\Type; use Rector\TypePerfect\Reflection\MethodNodeAnalyser; @@ -39,7 +41,7 @@ public function getNodeType(): string /** * @param ClassMethod $node - * @return string[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -68,7 +70,11 @@ public function processNode(Node $node, Scope $scope): array } // removed param type! - return [self::ERROR_MESSAGE]; + return [ + RuleErrorBuilder::message(self::ERROR_MESSAGE) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), + ]; } return []; diff --git a/src/Rules/ReturnNullOverFalseRule.php b/src/Rules/ReturnNullOverFalseRule.php index 1853e500..6b58f2ef 100644 --- a/src/Rules/ReturnNullOverFalseRule.php +++ b/src/Rules/ReturnNullOverFalseRule.php @@ -11,6 +11,8 @@ use PhpParser\NodeFinder; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantBooleanType; use Rector\TypePerfect\Configuration; @@ -44,7 +46,7 @@ public function getNodeType(): string /** * @param ClassMethod $node - * @return string[] + * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { @@ -90,7 +92,9 @@ public function processNode(Node $node, Scope $scope): array if (! $hasTrueType && $hasFalseType) { return [ - self::ERROR_MESSAGE, + RuleErrorBuilder::message(self::ERROR_MESSAGE) + ->identifier(ucfirst(basename(str_replace('\\', '/', self::class)))) + ->build(), ]; } diff --git a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipRecursive.php b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipRecursive.php index b0984640..7ebbdc60 100644 --- a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipRecursive.php +++ b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipRecursive.php @@ -13,7 +13,7 @@ class SkipRecursive /** * @param SomeStaticCall|MethodCall $node */ - public function processNode(Node $node) + public function processNode(Node $node): void { $this->run($node); } @@ -21,7 +21,7 @@ public function processNode(Node $node) /** * @param SomeStaticCall|MethodCall $node */ - private function run(Node $node) + private function run(Node $node): void { if ($node->name instanceof MethodCall) { $this->run($node->name);