MIR0229
DivisionByZero
A division operation uses a divisor that is statically known to be zero, which will cause a runtime error.
Example
Section titled “Example”<?phpfunction calculate(int $value): float { return $value / 0; // Division by zero}How to fix
Section titled “How to fix”Ensure the divisor is not zero, or add a check before division:
<?phpfunction calculate(int $value, int $divisor): float { if ($divisor === 0) { throw new InvalidArgumentException('Divisor cannot be zero'); } return $value / $divisor;}