Skip to content

Commit

Permalink
Fix ParadoxicalCondition with complex match expression
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed May 4, 2023
1 parent a5effd2 commit ac8d489
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ public static function analyze(
$stmt->cond->getAttributes(),
);
}
} elseif ($stmt->cond instanceof PhpParser\Node\Expr\FuncCall
|| $stmt->cond instanceof PhpParser\Node\Expr\MethodCall
|| $stmt->cond instanceof PhpParser\Node\Expr\StaticCall
} elseif ($stmt->cond instanceof PhpParser\Node\Expr\ConstFetch
&& $stmt->cond->name->toString() === 'true'
) {
// do nothing
} else {
$switch_var_id = '$__tmp_switch__' . (int) $stmt->cond->getAttribute('startFilePos');

$condition_type = $statements_analyzer->node_data->getType($stmt->cond) ?? Type::getMixed();
Expand Down
14 changes: 14 additions & 0 deletions tests/MatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ function test(array $array): array
'ignored_issues' => [],
'php_version' => '8.1',
],
'multipleIdenticalChecksInOneArm' => [
'code' => '<?php
function foo(?string $t1, string $t2): string
{
return match ($t1 ?? $t2) {
"type1", "type2", "type3" => "1 or 2 or 3",
"type4", "type5", "type6" => "4 or 5 or 6",
default => "rest",
};
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
'multipleInstanceOfConditionsInOneArm' => [
'code' => '<?php
interface Foo {}
Expand Down

0 comments on commit ac8d489

Please sign in to comment.