File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -52,9 +52,12 @@ public function validate(mixed $value, callable $fail): void
52
52
53
53
// Divide the value by multipleOf instead of using the modulo operator to avoid bugs when using a multipleOf
54
54
// that has decimal places. (Since the modulo operator converts the multipleOf to int)
55
+ // Note that dividing two integers returns another integer if the result is a whole number. So to make the
56
+ // comparison work at all times we need to cast the result to float. Casting both to integer will not work
57
+ // as intended since then the result of the division would also be rounded.
55
58
if (
56
59
$ this ->multipleOf !== null &&
57
- $ value / $ this ->multipleOf !== round ($ value / $ this ->multipleOf )
60
+ ( float ) ( $ value / $ this ->multipleOf ) !== round ($ value / $ this ->multipleOf )
58
61
) {
59
62
$ fail (sprintf ('must be a multiple of %d ' , $ this ->multipleOf ));
60
63
}
You can’t perform that action at this time.
0 commit comments