mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #3091 - simplify elseif negated clauses where possible
This commit is contained in:
parent
41b165c096
commit
61c979136f
@ -1517,9 +1517,11 @@ class IfAnalyzer
|
||||
}
|
||||
|
||||
try {
|
||||
$if_scope->negated_clauses = array_merge(
|
||||
$if_scope->negated_clauses,
|
||||
Algebra::negateFormula($elseif_clauses)
|
||||
$if_scope->negated_clauses = Algebra::simplifyCNF(
|
||||
array_merge(
|
||||
$if_scope->negated_clauses,
|
||||
Algebra::negateFormula($elseif_clauses)
|
||||
)
|
||||
);
|
||||
} catch (\Psalm\Exception\ComplicatedExpressionException $e) {
|
||||
$if_scope->negated_clauses = [];
|
||||
|
@ -1145,6 +1145,18 @@ class TypeAlgebraTest extends \Psalm\Tests\TestCase
|
||||
echo $array["other"];',
|
||||
'error_message' => 'InvalidArrayOffset',
|
||||
],
|
||||
'redundantTwoVarInElseif' => [
|
||||
'<?php
|
||||
class A {}
|
||||
|
||||
$from = rand(0, 1) ? new A() : null;
|
||||
$to = rand(0, 1) ? new A() : null;
|
||||
|
||||
if ($from === null && $to === null) {
|
||||
} elseif ($from !== null) {
|
||||
} elseif ($to !== null) {}',
|
||||
'error_message' => 'RedundantCondition',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user