Round MySQL Database Size to Nearest Integer to Prevent Precision Loss #182
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.
I've discovered an issue in the
getMySQLDatabaseSize()
method that can lead to PHP warnings about precision loss. Specifically, the MySQL query in this function employs the ROUND() function with one decimal place, sometimes resulting in a float. However, the function's type hint specifies an integer return type, and thus when the float is implicitly converted to an integer, PHP logs a warning about precision loss.For example:
This pull request proposes a simple but effective fix to this problem: adjusting the ROUND() function in the MySQL query to round to the nearest whole number, thereby ensuring that an integer is always returned.
The primary change in this PR includes:
Modification of the MySQL query within
getMySQLDatabaseSize()
to round to the nearest integer instead of returning a float.This fix will ensure that the method maintains type consistency as per its integer type hint, preventing PHP from logging precision loss warnings. It will also uphold the integrity of the Laravel Health package, ensuring that it consistently delivers reliable and error-free performance.
I've conducted thorough testing of this solution and confirmed that it resolves the issue effectively, with the function continuing to deliver the expected output.
I would be grateful if you could review this change and consider it for inclusion in the next package release.