Skip to content

Commit

Permalink
Add missing error identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 4, 2023
1 parent 37dbb8c commit f59c093
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 deletions.
25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,6 @@ parameters:
count: 1
path: src/Rules/Api/NodeConnectingVisitorAttributesRule.php

-
message: "#^Method PHPStan\\\\Rules\\\\Arrays\\\\AppendedArrayItemTypeRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\{PHPStan\\\\Rules\\\\TipRuleError\\}\\.$#"
count: 1
path: src/Rules/Arrays/AppendedArrayItemTypeRule.php

-
message: "#^Method PHPStan\\\\Rules\\\\Arrays\\\\AppendedArrayKeyTypeRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> 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
Expand Down Expand Up @@ -526,11 +516,6 @@ parameters:
count: 4
path: src/Rules/Comparison/MatchExpressionRule.php

-
message: "#^Method PHPStan\\\\Rules\\\\Comparison\\\\MatchExpressionRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\|PHPStan\\\\Rules\\\\LineRuleError\\>\\.$#"
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
Expand All @@ -551,21 +536,11 @@ parameters:
count: 1
path: src/Rules/Comparison/UnreachableIfBranchesRule.php

-
message: "#^Method PHPStan\\\\Rules\\\\Comparison\\\\UnreachableIfBranchesRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns list\\<PHPStan\\\\Rules\\\\RuleError\\>\\.$#"
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\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> 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
Expand Down
5 changes: 4 additions & 1 deletion src/Rules/Arrays/AppendedArrayItemTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Arrays/AppendedArrayKeyTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}

Expand Down
5 changes: 4 additions & 1 deletion src/Rules/Comparison/MatchExpressionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 9 additions & 2 deletions src/Rules/Comparison/UnreachableIfBranchesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Rules/Comparison/UnreachableTernaryElseBranchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
Expand Down

0 comments on commit f59c093

Please sign in to comment.