Skip to content

Fix implicit float to int conversion in randomTimeSchedule#7

Merged
skywarth merged 1 commit into
skywarth:masterfrom
rik-legger:fix/implicit-float-int-conversion
May 10, 2026
Merged

Fix implicit float to int conversion in randomTimeSchedule#7
skywarth merged 1 commit into
skywarth:masterfrom
rik-legger:fix/implicit-float-int-conversion

Conversation

@rik-legger

Copy link
Copy Markdown

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:

Implicit conversion from float to int loses precision in
src/Services/ChaoticSchedule.php on line 129

Switching to intdiv() performs an integer division up front and avoids the deprecation. The result is mathematically identical for any valid $randomMOTD in 0..1439 (the bounds enforced by setRandomTimeOnSchedule), so existing behavior is preserved.

Change

- \$designatedHour=(\$randomMOTD/60)%24;
+ \$designatedHour=intdiv(\$randomMOTD,60)%24;

Test plan

  • CI: vendor/bin/phpunit passes (the existing RandomTimeScheduleTest covers this code path).
  • CI: vendor/bin/phpstan analyse passes.
  • Manual: with LOG_DEPRECATIONS_CHANNEL configured, no Implicit conversion from float to int warning appears for scheduled commands using randomTimeSchedule.

Note: I couldn't run the test suite locally — composer install fails because orchestra/testbench ^6.28 resolves to Laravel 8 versions blocked by security advisories. CI on PHP 8.4 should run cleanly.

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'.
@darkest-pr

darkest-pr Bot commented May 7, 2026

Copy link
Copy Markdown

📜 Brigands have run of these lanes. Keep to the side path; the Hamlet is just ahead.

@sonarqubecloud

sonarqubecloud Bot commented May 7, 2026

Copy link
Copy Markdown

@skywarth

Copy link
Copy Markdown
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

@darkest-pr

darkest-pr Bot commented May 10, 2026

Copy link
Copy Markdown

🕯️ Room by room, hall by hall, we reclaim what is ours.

@skywarth skywarth merged commit 5ef2c57 into skywarth:master May 10, 2026
2 of 5 checks passed
@darkest-pr

darkest-pr Bot commented May 10, 2026

Copy link
Copy Markdown

🕯️ Our supplies are replenished, the soldiers will feast tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants