mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
parent
9ca6c868b7
commit
45ea5d0bfe
@ -2367,7 +2367,7 @@ class AssertionFinder
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
protected static function hasTrueVariable(PhpParser\Node\Expr\BinaryOp $conditional)
|
||||
public static function hasTrueVariable(PhpParser\Node\Expr\BinaryOp $conditional)
|
||||
{
|
||||
if ($conditional->right instanceof PhpParser\Node\Expr\ConstFetch
|
||||
&& strtolower($conditional->right->name->parts[0]) === 'true'
|
||||
|
@ -258,8 +258,11 @@ class Algebra
|
||||
}
|
||||
}
|
||||
|
||||
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Identical) {
|
||||
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Identical
|
||||
|| $conditional instanceof PhpParser\Node\Expr\BinaryOp\Equal
|
||||
) {
|
||||
$false_pos = AssertionFinder::hasFalseVariable($conditional);
|
||||
$true_pos = AssertionFinder::hasTrueVariable($conditional);
|
||||
|
||||
if ($false_pos === AssertionFinder::ASSIGNMENT_TO_RIGHT
|
||||
&& ($conditional->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd
|
||||
@ -276,7 +279,9 @@ class Algebra
|
||||
$inside_negation,
|
||||
$cache
|
||||
);
|
||||
} elseif ($false_pos === AssertionFinder::ASSIGNMENT_TO_LEFT
|
||||
}
|
||||
|
||||
if ($false_pos === AssertionFinder::ASSIGNMENT_TO_LEFT
|
||||
&& ($conditional->right instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd
|
||||
|| $conditional->right instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr)
|
||||
) {
|
||||
@ -292,6 +297,36 @@ class Algebra
|
||||
$cache
|
||||
);
|
||||
}
|
||||
|
||||
if ($true_pos === AssertionFinder::ASSIGNMENT_TO_RIGHT
|
||||
&& ($conditional->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd
|
||||
|| $conditional->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr)
|
||||
) {
|
||||
return self::getFormula(
|
||||
$object_id,
|
||||
$conditional->left,
|
||||
$this_class_name,
|
||||
$source,
|
||||
$codebase,
|
||||
$inside_negation,
|
||||
$cache
|
||||
);
|
||||
}
|
||||
|
||||
if ($true_pos === AssertionFinder::ASSIGNMENT_TO_LEFT
|
||||
&& ($conditional->right instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd
|
||||
|| $conditional->right instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr)
|
||||
) {
|
||||
return self::getFormula(
|
||||
$object_id,
|
||||
$conditional->right,
|
||||
$this_class_name,
|
||||
$source,
|
||||
$codebase,
|
||||
$inside_negation,
|
||||
$cache
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$assertions = null;
|
||||
|
@ -861,6 +861,15 @@ class SwitchTypeTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'switchTruthyWithBoolean' => [
|
||||
'<?php
|
||||
$a = rand(0,1) ? new \DateTime() : null;
|
||||
|
||||
switch(true) {
|
||||
case $a !== null && $a->format("Y") === "2020":
|
||||
$a->format("d-m-Y");
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user