Skip to content

Commit

Permalink
Add maybe redundant? non zero validation. See https://github.com/phps…
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed May 3, 2022
1 parent ef6111f commit 01c2761
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Analyser/MutatingScope.php
Expand Up @@ -2940,11 +2940,18 @@ private function calculateFromScalars(Expr $node, ConstantScalarType $leftType,
}

if ($node instanceof Node\Expr\BinaryOp\Div || $node instanceof Node\Expr\AssignOp\Div) {
if ($rightNumberValue === 0 || $rightNumberValue === 0.0) {
return new ErrorType();
}
return $this->getTypeFromValue($leftNumberValue / $rightNumberValue);
}

if ($node instanceof Node\Expr\BinaryOp\Mod || $node instanceof Node\Expr\AssignOp\Mod) {
return $this->getTypeFromValue(((int) $leftNumberValue) % ((int) $rightNumberValue));
$rightIntegerValue = (int) $rightNumberValue;
if ($rightIntegerValue === 0) {
return new ErrorType();
}
return $this->getTypeFromValue(((int) $leftNumberValue) % $rightIntegerValue);
}

if ($node instanceof Expr\BinaryOp\ShiftLeft || $node instanceof Expr\AssignOp\ShiftLeft) {
Expand Down

0 comments on commit 01c2761

Please sign in to comment.