Fix implicit float to int conversion in randomTimeSchedule#7
Merged
skywarth merged 1 commit intoMay 10, 2026
Merged
Conversation
PHP 8.1+ emits a deprecation warning when the result of `$randomMOTD/60` (a float when not evenly divisible) is implicitly cast to int by the modulo operator. Switching to intdiv() performs an integer division and removes the warning while producing identical results for all valid inputs (0..1439). Reproduction: any deprecation-aware logger (e.g. LOG_DEPRECATIONS_CHANNEL=slack) will surface 'Implicit conversion from float to int loses precision in .../ChaoticSchedule.php on line 129'.
📜 Brigands have run of these lanes. Keep to the side path; the Hamlet is just ahead. |
|
Owner
|
Hey @rik-legger, good catch! Thanks for the contribution. LGTM ✔️ FYI: working on upgrading to the latest stable version of Laravel and PHP, so the security advisories and installation issues should disappear afterwards. Check the PR here if interested: #8 |
skywarth
approved these changes
May 10, 2026
🕯️ Room by room, hall by hall, we reclaim what is ours. |
🕯️ Our supplies are replenished, the soldiers will feast tonight. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
ChaoticSchedule::randomTimeSchedule()divides an integer by 60 and then applies the modulo operator (%), which implicitly casts the float result back to int. PHP 8.1+ emits this deprecation:Switching to
intdiv()performs an integer division up front and avoids the deprecation. The result is mathematically identical for any valid$randomMOTDin 0..1439 (the bounds enforced bysetRandomTimeOnSchedule), so existing behavior is preserved.Change
Test plan
vendor/bin/phpunitpasses (the existingRandomTimeScheduleTestcovers this code path).vendor/bin/phpstan analysepasses.LOG_DEPRECATIONS_CHANNELconfigured, noImplicit conversion from float to intwarning appears for scheduled commands usingrandomTimeSchedule.Note: I couldn't run the test suite locally —
composer installfails becauseorchestra/testbench ^6.28resolves to Laravel 8 versions blocked by security advisories. CI on PHP 8.4 should run cleanly.