diff --git a/composer.json b/composer.json index a909f8ae..48919f1c 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ }, "require": { "php": ">=7.2", - "ext-bcmath": "*", "ext-json": "*", "devizzent/cebe-php-openapi": "^1.0", "league/uri": "^6.3", diff --git a/src/Schema/Keywords/MultipleOf.php b/src/Schema/Keywords/MultipleOf.php index 71666008..c1990f35 100644 --- a/src/Schema/Keywords/MultipleOf.php +++ b/src/Schema/Keywords/MultipleOf.php @@ -10,12 +10,14 @@ use Respect\Validation\Validator; use Throwable; -use function bcdiv; use function class_exists; +use function round; use function sprintf; class MultipleOf extends BaseKeyword { + private const EPSILON = 0.00000001; + /** * The value of "multipleOf" MUST be a number, strictly greater than 0. * A numeric instance is only valid if division by this keyword's value results in an integer. @@ -39,9 +41,9 @@ public function validate($data, $multipleOf): void throw InvalidSchema::becauseDefensiveSchemaValidationFailed($e); } - $value = (float) bcdiv((string) $data, (string) $multipleOf, 1); - if ($value - (int) $value !== 0.0) { - throw KeywordMismatch::fromKeyword('multipleOf', $data, sprintf('Division by %d did not resulted in integer', $multipleOf)); + $value = round($data / $multipleOf, 8); + if ($value - (int) $value > self::EPSILON) { + throw KeywordMismatch::fromKeyword('multipleOf', $data, sprintf('Division by %s did not resulted in integer', $multipleOf)); } } } diff --git a/tests/Schema/Keywords/MultipleOfTest.php b/tests/Schema/Keywords/MultipleOfTest.php index 66514fc3..68a3db31 100644 --- a/tests/Schema/Keywords/MultipleOfTest.php +++ b/tests/Schema/Keywords/MultipleOfTest.php @@ -35,6 +35,7 @@ public function invalidDatasets(): array [10, .11], [9.9, .451], [.94, .03], + [1, .3333333], ]; }