From f59c09388661d961627faa39edb04bad5ad8cc25 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 4 Sep 2023 11:31:33 +0200 Subject: [PATCH] Add missing error identifiers --- phpstan-baseline.neon | 25 ------------------- .../Arrays/AppendedArrayItemTypeRule.php | 5 +++- src/Rules/Arrays/AppendedArrayKeyTypeRule.php | 2 +- src/Rules/Comparison/MatchExpressionRule.php | 5 +++- .../Comparison/UnreachableIfBranchesRule.php | 11 ++++++-- .../UnreachableTernaryElseBranchRule.php | 1 + 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7c0be7659b..880dc5d7e8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -438,16 +438,6 @@ parameters: count: 1 path: src/Rules/Api/NodeConnectingVisitorAttributesRule.php - - - message: "#^Method PHPStan\\\\Rules\\\\Arrays\\\\AppendedArrayItemTypeRule\\:\\:processNode\\(\\) should return list\\ but returns array\\{PHPStan\\\\Rules\\\\TipRuleError\\}\\.$#" - count: 1 - path: src/Rules/Arrays/AppendedArrayItemTypeRule.php - - - - message: "#^Method PHPStan\\\\Rules\\\\Arrays\\\\AppendedArrayKeyTypeRule\\:\\:processNode\\(\\) should return list\\ but returns array\\{PHPStan\\\\Rules\\\\RuleError\\}\\.$#" - count: 1 - path: src/Rules/Arrays/AppendedArrayKeyTypeRule.php - - message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#" count: 1 @@ -526,11 +516,6 @@ parameters: count: 4 path: src/Rules/Comparison/MatchExpressionRule.php - - - message: "#^Method PHPStan\\\\Rules\\\\Comparison\\\\MatchExpressionRule\\:\\:processNode\\(\\) should return list\\ but returns list\\\\.$#" - count: 1 - path: src/Rules/Comparison/MatchExpressionRule.php - - message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantBooleanType is error\\-prone and deprecated\\. Use Type\\:\\:isTrue\\(\\) or Type\\:\\:isFalse\\(\\) instead\\.$#" count: 2 @@ -551,21 +536,11 @@ parameters: count: 1 path: src/Rules/Comparison/UnreachableIfBranchesRule.php - - - message: "#^Method PHPStan\\\\Rules\\\\Comparison\\\\UnreachableIfBranchesRule\\:\\:processNode\\(\\) should return list\\ but returns list\\\\.$#" - count: 1 - path: src/Rules/Comparison/UnreachableIfBranchesRule.php - - message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantBooleanType is error\\-prone and deprecated\\. Use Type\\:\\:isTrue\\(\\) or Type\\:\\:isFalse\\(\\) instead\\.$#" count: 1 path: src/Rules/Comparison/UnreachableTernaryElseBranchRule.php - - - message: "#^Method PHPStan\\\\Rules\\\\Comparison\\\\UnreachableTernaryElseBranchRule\\:\\:processNode\\(\\) should return list\\ but returns array\\{PHPStan\\\\Rules\\\\LineRuleError\\}\\.$#" - count: 1 - path: src/Rules/Comparison/UnreachableTernaryElseBranchRule.php - - message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantBooleanType is error\\-prone and deprecated\\. Use Type\\:\\:isTrue\\(\\) or Type\\:\\:isFalse\\(\\) instead\\.$#" count: 1 diff --git a/src/Rules/Arrays/AppendedArrayItemTypeRule.php b/src/Rules/Arrays/AppendedArrayItemTypeRule.php index c9679f24fb..96409f9aa1 100644 --- a/src/Rules/Arrays/AppendedArrayItemTypeRule.php +++ b/src/Rules/Arrays/AppendedArrayItemTypeRule.php @@ -80,7 +80,10 @@ public function processNode(Node $node, Scope $scope): array 'Array (%s) does not accept %s.', $assignedToType->describe($verbosityLevel), $assignedValueType->describe($verbosityLevel), - ))->acceptsReasonsTip($accepts->reasons)->build(), + )) + ->acceptsReasonsTip($accepts->reasons) + ->identifier('array.valueType') + ->build(), ]; } diff --git a/src/Rules/Arrays/AppendedArrayKeyTypeRule.php b/src/Rules/Arrays/AppendedArrayKeyTypeRule.php index 1e1d2d83a0..cf35062faf 100644 --- a/src/Rules/Arrays/AppendedArrayKeyTypeRule.php +++ b/src/Rules/Arrays/AppendedArrayKeyTypeRule.php @@ -79,7 +79,7 @@ public function processNode(Node $node, Scope $scope): array 'Array (%s) does not accept key %s.', $arrayType->describe($verbosity), $keyType->describe(VerbosityLevel::value()), - ))->build(), + ))->identifier('array.keyType')->build(), ]; } diff --git a/src/Rules/Comparison/MatchExpressionRule.php b/src/Rules/Comparison/MatchExpressionRule.php index 53360c665e..d7d318322e 100644 --- a/src/Rules/Comparison/MatchExpressionRule.php +++ b/src/Rules/Comparison/MatchExpressionRule.php @@ -55,7 +55,10 @@ public function processNode(Node $node, Scope $scope): array || ($nextArmIsDeadForType && $this->treatPhpDocTypesAsCertain) ) { if (!$this->disableUnreachable) { - $errors[] = RuleErrorBuilder::message('Match arm is unreachable because previous comparison is always true.')->line($arm->getLine())->build(); + $errors[] = RuleErrorBuilder::message('Match arm is unreachable because previous comparison is always true.') + ->identifier('match.unreachable') + ->line($arm->getLine()) + ->build(); } continue; } diff --git a/src/Rules/Comparison/UnreachableIfBranchesRule.php b/src/Rules/Comparison/UnreachableIfBranchesRule.php index 427e16aae8..70cc687129 100644 --- a/src/Rules/Comparison/UnreachableIfBranchesRule.php +++ b/src/Rules/Comparison/UnreachableIfBranchesRule.php @@ -38,6 +38,7 @@ public function processNode(Node $node, Scope $scope): array $conditionType = $this->treatPhpDocTypesAsCertain ? $scope->getType($condition) : $scope->getNativeType($condition); $conditionBooleanType = $conditionType->toBoolean(); $nextBranchIsDead = $conditionBooleanType->isTrue()->yes() && $this->helper->shouldSkip($scope, $node->cond) && !$this->helper->shouldReportAlwaysTrueByDefault($node->cond); + $addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, &$condition): RuleErrorBuilder { if (!$this->treatPhpDocTypesAsCertain) { return $ruleErrorBuilder; @@ -53,7 +54,10 @@ 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()))->build(); + $errors[] = $addTip(RuleErrorBuilder::message('Elseif branch is unreachable because previous condition is always true.')) + ->identifier('elseif.unreachable') + ->line($elseif->getLine()) + ->build(); continue; } @@ -64,7 +68,10 @@ 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())->build(); + $errors[] = $addTip(RuleErrorBuilder::message('Else branch is unreachable because previous condition is always true.')) + ->identifier('else.unreachable') + ->line($node->else->getLine()) + ->build(); } return $errors; diff --git a/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php b/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php index 89d10f3d7c..b6572d16d8 100644 --- a/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php +++ b/src/Rules/Comparison/UnreachableTernaryElseBranchRule.php @@ -54,6 +54,7 @@ public function processNode(Node $node, Scope $scope): array }; return [ $addTip(RuleErrorBuilder::message('Else branch is unreachable because ternary operator condition is always true.')) + ->identifier('ternary.elseUnreachable') ->line($node->else->getLine()) ->build(), ];