Skip to content

Commit

Permalink
Match expression - fix default handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 9, 2020
1 parent ccd6f88 commit 1dfade1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
9 changes: 0 additions & 9 deletions src/Rules/Comparison/MatchExpressionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ public function processNode(Node $node, Scope $scope): array
$armConditions = $arm->getConditions();
if (count($armConditions) === 0) {
$hasDefault = true;
$nextArmIsDead = true;
if (
$this->checkAlwaysTrueStrictComparison
&& ($i !== $armsCount - 1 || $i === 0)
) {
$errors[] = RuleErrorBuilder::message(
'Match arm comparison is always true.'
)->line($arm->getLine())->build();
}
}
foreach ($armConditions as $armCondition) {
$armConditionScope = $armCondition->getScope();
Expand Down
12 changes: 0 additions & 12 deletions tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@ public function testRule(): void
'Match arm comparison between 1 and 1 is always true.',
70,
],
[
'Match arm comparison is always true.',
74,
],
[
'Match arm comparison is always true.',
78,
],
[
'Match arm is unreachable because previous comparison is always true.',
79,
],
[
'Match arm comparison between true and false is always false.',
86,
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Rules/Comparison/data/match-expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public function doFoo(int $i): void
};

match ($i) {
default => 1, // always true - report with strict-rules
default => 1,
};

match ($i) {
default => 1, // always true - report with strict-rules
1 => 2, // unreachable
default => 1,
1 => 2,
};
}

Expand Down

0 comments on commit 1dfade1

Please sign in to comment.