Add PossiblyDivisionByZero rule
First try of the implementation of PossiblyDivisionByZero
The config declaration is missing. At which level should I add this @ondrejmirtes ? (with a conditional tag ?)
Friendly ping @ondrejmirtes.
To finish this PR I just need to know to which level I should add this rule ? Should it be under bleeding edge ?
Hi, let's try it on level 7 to see how annoying it'd be. It's correct but I worry too annoying in practice.
I want to see it without bleedingEdge first, to test it on real projects in CI.
Also - base it on 1.9.x.
As a followup it might be usefull to cover modulo division by zero?
As a followup it might be usefull to cover modulo division by zero?
Nice idea. I've added the support. I just need now to understand what is wrong with my config.
The PR is now ready :)
The pipeline results show that although correct, this would really be annoying in practice...
The pipeline results show that although correct, this would really be annoying in practice...
For every projects tested where there is failure about possibly division by zero there is not a lot and adding a check wouldn't hurt. But I understand the "annoying" thing.
Should it be an option then ?
I feel like PHPStan doesn't have to contain every custom rule idea under an option. I encourage you to publish and market your own package for this problem. Similar to how https://github.com/Roave/no-floaters is done.
I feel like PHPStan doesn't have to contain every custom rule idea under an option. I encourage you to publish and market your own package for this problem. Similar to how https://github.com/Roave/no-floaters is done.
I just had a new thought about this rule and start to think this is not needed, and maybe should not exists.
The following code could be considered as correct
/**
* @throws DivisionByZeroError
*/
public function compute(int $int): float {
return 42 / $int;
}
And PHPStan is already correctly reporting the DivisionByZeroError when using the exception features.
I totally forgot about this because I had
exceptions:
uncheckedExceptionClasses:
- Error
I guess I cannot modify the config to say "I'd like to ignore all the Error, except DivisionByZeroError". ^^'