Skip to content

Commit

Permalink
UnreachableIfBranchesRule - identifiers and metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 17, 2020
1 parent e604a7b commit bed8fc0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Rules/Comparison/UnreachableIfBranchesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ 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.')->line($elseif->getLine()))
->identifier('deadCode.unreachableElseif')
->metadata([
'depth' => $elseif->getAttribute('statementDepth'),
'order' => $elseif->getAttribute('statementOrder'),
])
->build();
continue;
}

Expand All @@ -62,7 +68,13 @@ 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.'))->line($node->else->getLine())
->identifier('deadCode.unreachableElse')
->metadata([
'parentDepth' => $node->getAttribute('statementDepth'),
'parentOrder' => $node->getAttribute('statementOrder'),
])
->build();
}

return $errors;
Expand Down

0 comments on commit bed8fc0

Please sign in to comment.