phpinspectionsea
phpinspectionsea copied to clipboard
[FR] problematic hard-coded floats in int function
Description (screenshot):
Hi!
I'm currently working to make a fully type hinted version of the phpstorm stubs. I tried it at work today and it highlighted a lot of issues in our code.
There was one in particular that was problematic:
sleep(0.5);
The sleep function only takes int parameter, so when we try to push a float, it is casted to int and the output is 0.
So while PHPStorm didn't complain, the call to sleep was just useless and we didn't have a real way to detect the issue.
It could be useful to have an inspection that checks hard-coded floats in sleep function. This could be extended to other functions if there are other functions with the same kind of issue (set_time_limit ?)
Thanks
Not aware of other functions with similar issue, but this one I see from time to time. Will it be fine for you if we suggest using 'usleep' for this cases?
Yeah totally, we should have used usleep from beggining
Great, then it'll be a new inspection 👍