website/errors/mod.leftNonNumeric.md
<?php declare(strict_types = 1);
function remainder(bool $flag, int $b): int
{
return $flag % $b;
}
The left operand of the modulo operator (%) is not a numeric type. PHP will attempt to coerce non-numeric values to numbers at runtime, which can lead to unexpected results or TypeError exceptions in strict mode. Only int and float types should be used in arithmetic operations.
This rule is provided by the phpstan-strict-rules package.
Ensure the left operand is a numeric type before performing the modulo operation:
-function remainder(bool $flag, int $b): int
+function remainder(int $a, int $b): int
{
- return $flag % $b;
+ return $a % $b;
}
Or cast the value explicitly:
function remainder(bool $flag, int $b): int
{
- return $flag % $b;
+ return (int) $flag % $b;
}