phpinspectionsea icon indicating copy to clipboard operation
phpinspectionsea copied to clipboard

[FR] problematic hard-coded floats in int function

Open orklah opened this issue 4 years ago • 3 comments

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

orklah avatar Nov 07 '19 17:11 orklah

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?

kalessil avatar Nov 25 '19 09:11 kalessil

Yeah totally, we should have used usleep from beggining

orklah avatar Nov 25 '19 09:11 orklah

Great, then it'll be a new inspection 👍

kalessil avatar Nov 25 '19 09:11 kalessil