diff --git a/src/Rules/Comparison/ElseIfConstantConditionRule.php b/src/Rules/Comparison/ElseIfConstantConditionRule.php index 5ce0b17ff1..31e942f639 100644 --- a/src/Rules/Comparison/ElseIfConstantConditionRule.php +++ b/src/Rules/Comparison/ElseIfConstantConditionRule.php @@ -54,13 +54,7 @@ public function processNode( $errorBuilder = $addTip(RuleErrorBuilder::message(sprintf( 'Elseif condition is always %s.', $exprType->getValue() ? 'true' : 'false', - )))->line($node->cond->getLine()) - ->identifier('deadCode.elseifConstantCondition') - ->metadata([ - 'depth' => $node->getAttribute('statementDepth'), - 'order' => $node->getAttribute('statementOrder'), - 'value' => $exprType->getValue(), - ]); + )))->line($node->cond->getLine()); if ($exprType->getValue() && $isLast === false && !$this->reportAlwaysTrueInLastCondition) { $errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.'); diff --git a/src/Rules/Comparison/IfConstantConditionRule.php b/src/Rules/Comparison/IfConstantConditionRule.php index 0de33d796b..78184a7b4d 100644 --- a/src/Rules/Comparison/IfConstantConditionRule.php +++ b/src/Rules/Comparison/IfConstantConditionRule.php @@ -51,14 +51,7 @@ public function processNode( $addTip(RuleErrorBuilder::message(sprintf( 'If condition is always %s.', $exprType->getValue() ? 'true' : 'false', - )))->line($node->cond->getLine()) - ->identifier('deadCode.ifConstantCondition') - ->metadata([ - 'depth' => $node->getAttribute('statementDepth'), - 'order' => $node->getAttribute('statementOrder'), - 'value' => $exprType->getValue(), - ]) - ->build(), + )))->line($node->cond->getLine())->build(), ]; } diff --git a/src/Rules/Comparison/TernaryOperatorConstantConditionRule.php b/src/Rules/Comparison/TernaryOperatorConstantConditionRule.php index e608d7bfbd..6d26f17611 100644 --- a/src/Rules/Comparison/TernaryOperatorConstantConditionRule.php +++ b/src/Rules/Comparison/TernaryOperatorConstantConditionRule.php @@ -50,16 +50,7 @@ public function processNode( $addTip(RuleErrorBuilder::message(sprintf( 'Ternary operator condition is always %s.', $exprType->getValue() ? 'true' : 'false', - ))) - ->identifier('deadCode.ternaryConstantCondition') - ->metadata([ - 'statementDepth' => $node->getAttribute('statementDepth'), - 'statementOrder' => $node->getAttribute('statementOrder'), - 'depth' => $node->getAttribute('expressionDepth'), - 'order' => $node->getAttribute('expressionOrder'), - 'value' => $exprType->getValue(), - ]) - ->build(), + )))->build(), ]; } diff --git a/src/Rules/Comparison/UnreachableIfBranchesRule.php b/src/Rules/Comparison/UnreachableIfBranchesRule.php index 6b4921a5ba..427e16aae8 100644 --- a/src/Rules/Comparison/UnreachableIfBranchesRule.php +++ b/src/Rules/Comparison/UnreachableIfBranchesRule.php @@ -53,15 +53,7 @@ public function processNode(Node $node, Scope $scope): array foreach ($node->elseifs as $elseif) { if ($nextBranchIsDead) { - $errors[] = $addTip(RuleErrorBuilder::message('Elseif branch is unreachable because previous condition is always true.')->line($elseif->getLine())) - ->identifier('deadCode.unreachableElseif') - ->metadata([ - 'ifDepth' => $node->getAttribute('statementDepth'), - 'ifOrder' => $node->getAttribute('statementOrder'), - 'depth' => $elseif->getAttribute('statementDepth'), - 'order' => $elseif->getAttribute('statementOrder'), - ]) - ->build(); + $errors[] = $addTip(RuleErrorBuilder::message('Elseif branch is unreachable because previous condition is always true.')->line($elseif->getLine()))->build(); continue; } @@ -72,13 +64,7 @@ public function processNode(Node $node, Scope $scope): array } if ($node->else !== null && $nextBranchIsDead) { - $errors[] = $addTip(RuleErrorBuilder::message('Else branch is unreachable because previous condition is always true.'))->line($node->else->getLine()) - ->identifier('deadCode.unreachableElse') - ->metadata([ - 'ifDepth' => $node->getAttribute('statementDepth'), - 'ifOrder' => $node->getAttribute('statementOrder'), - ]) - ->build(); + $errors[] = $addTip(RuleErrorBuilder::message('Else branch is unreachable because previous condition is always true.'))->line($node->else->getLine())->build(); } return $errors; diff --git a/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php b/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php index 052e133c18..89d10f3d7c 100644 --- a/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php +++ b/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php @@ -55,13 +55,6 @@ public function processNode(Node $node, Scope $scope): array return [ $addTip(RuleErrorBuilder::message('Else branch is unreachable because ternary operator condition is always true.')) ->line($node->else->getLine()) - ->identifier('deadCode.unreachableTernaryElse') - ->metadata([ - 'statementDepth' => $node->getAttribute('statementDepth'), - 'statementOrder' => $node->getAttribute('statementOrder'), - 'depth' => $node->getAttribute('expressionDepth'), - 'order' => $node->getAttribute('expressionOrder'), - ]) ->build(), ]; } diff --git a/src/Rules/DeadCode/NoopRule.php b/src/Rules/DeadCode/NoopRule.php index cd18fda0ca..4963a18e8d 100644 --- a/src/Rules/DeadCode/NoopRule.php +++ b/src/Rules/DeadCode/NoopRule.php @@ -56,11 +56,6 @@ public function processNode(Node $node, Scope $scope): array 'Expression "%s" on a separate line does not do anything.', $this->exprPrinter->printExpr($originalExpr), ))->line($expr->getLine()) - ->identifier('deadCode.noopExpression') - ->metadata([ - 'depth' => $node->getAttribute('statementDepth'), - 'order' => $node->getAttribute('statementOrder'), - ]) ->build(), ]; } diff --git a/src/Rules/DeadCode/UnreachableStatementRule.php b/src/Rules/DeadCode/UnreachableStatementRule.php index ffe4876c6d..13f53cef65 100644 --- a/src/Rules/DeadCode/UnreachableStatementRule.php +++ b/src/Rules/DeadCode/UnreachableStatementRule.php @@ -22,13 +22,7 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { return [ - RuleErrorBuilder::message('Unreachable statement - code above always terminates.') - ->identifier('deadCode.unreachableStatement') - ->metadata([ - 'depth' => $node->getAttribute('statementDepth'), - 'order' => $node->getAttribute('statementOrder'), - ]) - ->build(), + RuleErrorBuilder::message('Unreachable statement - code above always terminates.')->build(), ]; } diff --git a/src/Rules/DeadCode/UnusedPrivateConstantRule.php b/src/Rules/DeadCode/UnusedPrivateConstantRule.php index 991d4d8dc5..f7a2484ad6 100644 --- a/src/Rules/DeadCode/UnusedPrivateConstantRule.php +++ b/src/Rules/DeadCode/UnusedPrivateConstantRule.php @@ -88,13 +88,6 @@ public function processNode(Node $node, Scope $scope): array foreach ($constants as $constantName => $constantNode) { $errors[] = RuleErrorBuilder::message(sprintf('Constant %s::%s is unused.', $classReflection->getDisplayName(), $constantName)) ->line($constantNode->getLine()) - ->identifier('deadCode.unusedClassConstant') - ->metadata([ - 'classOrder' => $node->getClass()->getAttribute('statementOrder'), - 'classDepth' => $node->getClass()->getAttribute('statementDepth'), - 'classStartLine' => $node->getClass()->getStartLine(), - 'constantName' => $constantName, - ]) ->tip(sprintf('See: %s', 'https://phpstan.org/developing-extensions/always-used-class-constants')) ->build(); } diff --git a/src/Rules/DeadCode/UnusedPrivateMethodRule.php b/src/Rules/DeadCode/UnusedPrivateMethodRule.php index ba3c58341f..c1e3d0fc79 100644 --- a/src/Rules/DeadCode/UnusedPrivateMethodRule.php +++ b/src/Rules/DeadCode/UnusedPrivateMethodRule.php @@ -154,13 +154,6 @@ public function processNode(Node $node, Scope $scope): array } $errors[] = RuleErrorBuilder::message(sprintf('%s %s::%s() is unused.', $methodType, $classReflection->getDisplayName(), $methodName)) ->line($method->getNode()->getLine()) - ->identifier('deadCode.unusedMethod') - ->metadata([ - 'classOrder' => $node->getClass()->getAttribute('statementOrder'), - 'classDepth' => $node->getClass()->getAttribute('statementDepth'), - 'classStartLine' => $node->getClass()->getStartLine(), - 'methodName' => $methodName, - ]) ->build(); } diff --git a/src/Rules/DeadCode/UnusedPrivatePropertyRule.php b/src/Rules/DeadCode/UnusedPrivatePropertyRule.php index c5e12e547d..38ad822652 100644 --- a/src/Rules/DeadCode/UnusedPrivatePropertyRule.php +++ b/src/Rules/DeadCode/UnusedPrivatePropertyRule.php @@ -175,13 +175,6 @@ public function processNode(Node $node, Scope $scope): array if (!$data['written']) { $errors[] = RuleErrorBuilder::message(sprintf('%s is unused.', $propertyName)) ->line($propertyNode->getStartLine()) - ->identifier('deadCode.unusedProperty') - ->metadata([ - 'classOrder' => $node->getClass()->getAttribute('statementOrder'), - 'classDepth' => $node->getClass()->getAttribute('statementDepth'), - 'classStartLine' => $node->getClass()->getStartLine(), - 'propertyName' => $name, - ]) ->tip($tip) ->build(); } else { diff --git a/src/Rules/Exceptions/MissingCheckedExceptionInFunctionThrowsRule.php b/src/Rules/Exceptions/MissingCheckedExceptionInFunctionThrowsRule.php index aa97cb9fdd..a0cf8e11b1 100644 --- a/src/Rules/Exceptions/MissingCheckedExceptionInFunctionThrowsRule.php +++ b/src/Rules/Exceptions/MissingCheckedExceptionInFunctionThrowsRule.php @@ -42,7 +42,6 @@ public function processNode(Node $node, Scope $scope): array $className, )) ->line($throwPointNode->getLine()) - ->identifier('exceptions.missingThrowsTag') ->build(); } diff --git a/src/Rules/Exceptions/MissingCheckedExceptionInMethodThrowsRule.php b/src/Rules/Exceptions/MissingCheckedExceptionInMethodThrowsRule.php index 40a398e25e..040b31b543 100644 --- a/src/Rules/Exceptions/MissingCheckedExceptionInMethodThrowsRule.php +++ b/src/Rules/Exceptions/MissingCheckedExceptionInMethodThrowsRule.php @@ -43,7 +43,6 @@ public function processNode(Node $node, Scope $scope): array $className, )) ->line($throwPointNode->getLine()) - ->identifier('exceptions.missingThrowsTag') ->build(); } diff --git a/src/Rules/Exceptions/TooWideFunctionThrowTypeRule.php b/src/Rules/Exceptions/TooWideFunctionThrowTypeRule.php index fff550cd41..002f6763d8 100644 --- a/src/Rules/Exceptions/TooWideFunctionThrowTypeRule.php +++ b/src/Rules/Exceptions/TooWideFunctionThrowTypeRule.php @@ -45,14 +45,7 @@ public function processNode(Node $node, Scope $scope): array 'Function %s() has %s in PHPDoc @throws tag but it\'s not thrown.', $functionReflection->getName(), $throwClass, - )) - ->identifier('exceptions.tooWideThrowType') - ->metadata([ - 'exceptionName' => $throwClass, - 'statementDepth' => $node->getAttribute('statementDepth'), - 'statementOrder' => $node->getAttribute('statementOrder'), - ]) - ->build(); + ))->build(); } return $errors; diff --git a/src/Rules/Exceptions/TooWideMethodThrowTypeRule.php b/src/Rules/Exceptions/TooWideMethodThrowTypeRule.php index 3a26b6843e..1556872e4d 100644 --- a/src/Rules/Exceptions/TooWideMethodThrowTypeRule.php +++ b/src/Rules/Exceptions/TooWideMethodThrowTypeRule.php @@ -65,14 +65,7 @@ public function processNode(Node $node, Scope $scope): array $methodReflection->getDeclaringClass()->getDisplayName(), $methodReflection->getName(), $throwClass, - )) - ->identifier('exceptions.tooWideThrowType') - ->metadata([ - 'exceptionName' => $throwClass, - 'statementDepth' => $node->getAttribute('statementDepth'), - 'statementOrder' => $node->getAttribute('statementOrder'), - ]) - ->build(); + ))->build(); } return $errors; diff --git a/src/Rules/PhpDoc/IncompatiblePhpDocTypeRule.php b/src/Rules/PhpDoc/IncompatiblePhpDocTypeRule.php index ebfdba824f..e935d2222d 100644 --- a/src/Rules/PhpDoc/IncompatiblePhpDocTypeRule.php +++ b/src/Rules/PhpDoc/IncompatiblePhpDocTypeRule.php @@ -78,7 +78,7 @@ public function processNode(Node $node, Scope $scope): array 'PHPDoc tag %s references unknown parameter: $%s', $tagName, $parameterName, - ))->identifier('phpDoc.unknownParameter')->metadata(['parameterName' => $parameterName])->build(); + ))->build(); } elseif ( $this->unresolvableTypeHelper->containsUnresolvableType($phpDocParamType) diff --git a/src/Rules/Playground/FunctionNeverRule.php b/src/Rules/Playground/FunctionNeverRule.php index 0100035ffa..8997681c92 100644 --- a/src/Rules/Playground/FunctionNeverRule.php +++ b/src/Rules/Playground/FunctionNeverRule.php @@ -50,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array 'Function %s() always %s, it should have return type "never".', $function->getName(), count($helperResult) === 0 ? 'throws an exception' : 'terminates script execution', - ))->identifier('phpstanPlayground.never')->build(), + ))->build(), ]; } diff --git a/src/Rules/Playground/MethodNeverRule.php b/src/Rules/Playground/MethodNeverRule.php index 7bba0df997..1b87aedd00 100644 --- a/src/Rules/Playground/MethodNeverRule.php +++ b/src/Rules/Playground/MethodNeverRule.php @@ -51,7 +51,7 @@ public function processNode(Node $node, Scope $scope): array $method->getDeclaringClass()->getDisplayName(), $method->getName(), count($helperResult) === 0 ? 'throws an exception' : 'terminates script execution', - ))->identifier('phpstanPlayground.never')->build(), + ))->build(), ]; } diff --git a/src/Rules/UnusedFunctionParametersCheck.php b/src/Rules/UnusedFunctionParametersCheck.php index 66ba1ad27a..760139716d 100644 --- a/src/Rules/UnusedFunctionParametersCheck.php +++ b/src/Rules/UnusedFunctionParametersCheck.php @@ -47,7 +47,7 @@ public function getUnusedParameters( foreach (array_keys($unusedParameters) as $name) { $errors[] = RuleErrorBuilder::message( sprintf($unusedParameterMessage, $name), - )->identifier($identifier)->metadata($additionalMetadata + ['variableName' => $name])->build(); + )->build(); } return $errors; diff --git a/src/Rules/Variables/DefinedVariableRule.php b/src/Rules/Variables/DefinedVariableRule.php index 3b756df99c..db1c6e130c 100644 --- a/src/Rules/Variables/DefinedVariableRule.php +++ b/src/Rules/Variables/DefinedVariableRule.php @@ -52,16 +52,6 @@ public function processNode(Node $node, Scope $scope): array if ($scope->hasVariableType($node->name)->no()) { return [ RuleErrorBuilder::message(sprintf('Undefined variable: $%s', $node->name)) - ->identifier('variable.undefined') - ->metadata([ - 'variableName' => $node->name, - 'statementDepth' => $node->getAttribute('statementDepth'), - 'statementOrder' => $node->getAttribute('statementOrder'), - 'depth' => $node->getAttribute('expressionDepth'), - 'order' => $node->getAttribute('expressionOrder'), - 'variables' => $scope->getDefinedVariables(), - 'parentVariables' => $this->getParentVariables($scope), - ]) ->build(), ]; } elseif ( @@ -69,37 +59,11 @@ public function processNode(Node $node, Scope $scope): array && !$scope->hasVariableType($node->name)->yes() ) { return [ - RuleErrorBuilder::message(sprintf('Variable $%s might not be defined.', $node->name)) - ->identifier('variable.maybeUndefined') - ->metadata([ - 'variableName' => $node->name, - 'statementDepth' => $node->getAttribute('statementDepth'), - 'statementOrder' => $node->getAttribute('statementOrder'), - 'depth' => $node->getAttribute('expressionDepth'), - 'order' => $node->getAttribute('expressionOrder'), - 'variables' => $scope->getDefinedVariables(), - 'parentVariables' => $this->getParentVariables($scope), - ]) - ->build(), + RuleErrorBuilder::message(sprintf('Variable $%s might not be defined.', $node->name))->build(), ]; } return []; } - /** - * @return array> - */ - private function getParentVariables(Scope $scope): array - { - $variables = []; - $parent = $scope->getParentScope(); - while ($parent !== null) { - $variables[] = $parent->getDefinedVariables(); - $parent = $parent->getParentScope(); - } - - return $variables; - } - }