mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Get or LHS clauses after evaluating statements
This commit is contained in:
parent
f5ca4b1c52
commit
02dcb2be95
@ -895,21 +895,6 @@ class ExpressionChecker
|
||||
} elseif ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr ||
|
||||
$stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr
|
||||
) {
|
||||
$left_clauses = AlgebraChecker::getFormula(
|
||||
$stmt->left,
|
||||
$statements_checker->getFQCLN(),
|
||||
$statements_checker
|
||||
);
|
||||
|
||||
$rhs_clauses = AlgebraChecker::simplifyCNF(
|
||||
array_merge(
|
||||
$context->clauses,
|
||||
AlgebraChecker::negateFormula($left_clauses)
|
||||
)
|
||||
);
|
||||
|
||||
$negated_type_assertions = AlgebraChecker::getTruthsFromFormula($rhs_clauses);
|
||||
|
||||
$pre_referenced_var_ids = $context->referenced_var_ids;
|
||||
$context->referenced_var_ids = [];
|
||||
|
||||
@ -926,6 +911,21 @@ class ExpressionChecker
|
||||
|
||||
$new_referenced_var_ids = array_diff_key($new_referenced_var_ids, $new_assigned_var_ids);
|
||||
|
||||
$left_clauses = AlgebraChecker::getFormula(
|
||||
$stmt->left,
|
||||
$statements_checker->getFQCLN(),
|
||||
$statements_checker
|
||||
);
|
||||
|
||||
$rhs_clauses = AlgebraChecker::simplifyCNF(
|
||||
array_merge(
|
||||
$context->clauses,
|
||||
AlgebraChecker::negateFormula($left_clauses)
|
||||
)
|
||||
);
|
||||
|
||||
$negated_type_assertions = AlgebraChecker::getTruthsFromFormula($rhs_clauses);
|
||||
|
||||
$changed_var_ids = [];
|
||||
|
||||
// while in an or, we allow scope to boil over to support
|
||||
|
@ -124,6 +124,26 @@ class RedundantConditionTest extends TestCase
|
||||
'assertions' => [],
|
||||
'error_levels' => ['PossiblyUndefinedVariable'],
|
||||
],
|
||||
'noRedundantConditionAfterFromDocblockRemoval' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function foo() : void{}
|
||||
public function bar() : void{}
|
||||
}
|
||||
|
||||
/** @return A */
|
||||
function makeA() {
|
||||
return new A;
|
||||
}
|
||||
|
||||
$a = makeA();
|
||||
|
||||
if ($a === null) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($a->foo() || $a->bar()) {}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user