Skip to content

Commit a057b3d

Browse files
authored
Fix multipleOf bugs in Number type
Fixes the multipleOf validation crashing when trying to use the modulo operator on a value that is zero, and an InvalidArgumentException when calling multipleOf() with `null` to reset it
1 parent e913512 commit a057b3d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Schema/Type/Number.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function validate(mixed $value, callable $fail): void
5050
}
5151
}
5252

53-
if ($this->multipleOf !== null && $value % $this->multipleOf !== 0) {
53+
if ($this->multipleOf !== null && (float) $value !== 0.0 && $value % $this->multipleOf !== 0) {
5454
$fail(sprintf('must be a multiple of %d', $this->multipleOf));
5555
}
5656
}
@@ -85,7 +85,7 @@ public function maximum(?float $maximum, bool $exclusive = false): static
8585

8686
public function multipleOf(?float $number): static
8787
{
88-
if ($number <= 0) {
88+
if ($number !== null && $number <= 0) {
8989
throw new InvalidArgumentException('multipleOf must be a positive number');
9090
}
9191

0 commit comments

Comments
 (0)