spatie / statamic-responsive-images

Responsive images for Statamic 3
MIT License
104 stars 29 forks source link

Implicit conversion from float to int #150

Closed aerni closed 2 years ago

aerni commented 2 years ago

I noticed that if I have Ray open and I load a page that uses this addon I'm getting loads of the following warnings that brings down the site. I have to close Ray to make the site load.

Implicit conversion from float 144558.80871039993 to int loses precision in /Users/michael/Code/tdsaarau/vendor/spatie/statamic-responsive-images/src/WidthCalculator.php on line 50

I tracked it down to this line in the code: https://github.com/spatie/statamic-responsive-images/blob/6aa75914a6ef5572ef68c00afd4cc79be20e4b19/src/WidthCalculator.php#L32

If I round the value, the warning disappears.

$predictedFileSize = round($predictedFileSize * 0.7);

I'm not sure about the implications of this change. So asking here first before submitting a PR to fix this.

ncla commented 2 years ago

I think this is okay. You can just submit PR and see if the tests fail, there are tests that should fail if there is differing amount of image URLs outputted.

WidthCalculator is responsible for how many image width variants will be generated for breakpoints.

Could also maybe just change the finishedCalculating method argument type to float.