Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxValue Rule should only fail, when $value is higher than the given maximal value #75

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

remiebelingmerifond
Copy link
Contributor

Description of the Issue

The failure message in the MaxValueRule currently states:
The {attribute} must be less than or equal to {value}

However, the corresponding if condition in the implementation looks like this:

if ($minorValue >= $this->max) {  
    // fail  
}  

This causes the maximum value itself to be incorrectly treated as invalid.

Example

  • Configured max value: 10
  • Input value: 10

Expected outcome: The validation should pass, as the input meets the "less than or equal to" condition.
Actual outcome: The validation fails with the error message:
The reduction must be less than or equal to 10

Proposed Fix

The issue lies in the use of the >= operator in the condition. To align the behavior with the intended rule, the check should verify only if the value is strictly greater than the maximum:

if ($minorValue > $this->max) {  
    // fail  
}  

This ensures that the maximum value is accepted as valid, consistent with the rule's message.

@pelmered
Copy link
Owner

pelmered commented Dec 4, 2024

You are 100 % right. Thank you!

@pelmered pelmered merged commit 580e031 into pelmered:main Dec 4, 2024
13 of 15 checks passed
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.

2 participants