1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #1545 - improve handling of negated binary ops

This commit is contained in:
Brown 2019-04-11 18:51:21 -04:00
parent 7848e97f36
commit a9b8952ea2
2 changed files with 30 additions and 0 deletions

View File

@ -127,6 +127,20 @@ class Algebra
return self::combineOredClauses($left_clauses, $right_clauses);
}
if ($conditional instanceof PhpParser\Node\Expr\BooleanNot
&& $conditional->expr instanceof PhpParser\Node\Expr\BinaryOp
) {
$negated_clauses = self::getFormula(
$conditional->expr,
$this_class_name,
$source,
$codebase,
!$inside_negation
);
return self::negateFormula($negated_clauses);
}
AssertionFinder::scrapeAssertions(
$conditional,
$this_class_name,

View File

@ -902,6 +902,22 @@ class TypeAlgebraTest extends TestCase
}
}',
],
'invertEquation' => [
'<?php
/**
* @param mixed $width
* @param mixed $height
*
* @throws RuntimeException
*/
function Foo($width, $height) : void {
if (!(is_int($width) || is_float($width)) || !(is_int($height) || is_float($height))) {
throw new RuntimeException("bad");
}
echo sprintf("padding-top:%s%%;", 100 * ($height/$width));
}'
],
];
}