Skip to content
Permalink
Browse files

Fix #1545 - improve handling of negated binary ops

  • Loading branch information...
muglug committed Apr 11, 2019
1 parent 7848e97 commit a9b8952ea28bc25a90a7136a03dc2f3f142f1509
Showing with 30 additions and 0 deletions.
  1. +14 −0 src/Psalm/Type/Algebra.php
  2. +16 −0 tests/TypeAlgebraTest.php
@@ -127,6 +127,20 @@ public static function getFormula(
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,
@@ -902,6 +902,22 @@ function bad(A $x) : void {
}
}',
],
'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));
}'
],
];
}

0 comments on commit a9b8952

Please sign in to comment.
You can’t perform that action at this time.