Fix: Improve validateInteger ergonomics and fix BC break #57175
Merged
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.
This pull request addresses a breaking change from PR #56503 and improves the ergonomics of the validateInteger method.
The signature for validateInteger was updated in v12.22.0, introducing a new mandatory $parameters argument. This caused an ArgumentCountError for the common pattern of calling this method directly within a custom validation Closure, breaking backward compatibility.
Beyond just fixing the regression, this PR also improves the developer experience. Forcing developers to pass an empty array ([]) for the most common use case (a simple integer check without strict mode) adds unnecessary verbosity to the code.
An API should be simple for common tasks. By making the $parameters argument optional, we restore the previous behavior and also create a cleaner, more intuitive method call.
Before (in v12.22.0+ to avoid error):
After this PR:
Solution
This PR makes the $parameters argument optional by providing a default empty array. This change is completely backward compatible, fixes the breaking change, and simplifies the API for its primary use case, without affecting the new strict functionality.