Conditions | 3 |
Paths | 3 |
Total Lines | 23 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
29 | 4 | public function validate($value, $parameter, Validator $validator) |
|
30 | { |
||
31 | Assert::type($parameter, 'number', self::KEYWORD, $validator->getPointer()); |
||
32 | 4 | Assert::nonNegative($parameter, self::KEYWORD, $validator->getPointer()); |
|
33 | 4 | ||
34 | 4 | if (!is_numeric($value)) { |
|
35 | 4 | return null; |
|
36 | 4 | } |
|
37 | 4 | ||
38 | 4 | $quotient = bcdiv($value, $parameter, $this->precision); |
|
39 | $mod = bcsub($quotient, floor($quotient), $this->precision); |
||
40 | if (bccomp($mod, 0, $this->precision) === 0) { |
||
41 | return null; |
||
42 | } |
||
43 | |||
44 | return new ValidationError( |
||
45 | 'Number {value} is not a multiple of {multiple_of}', |
||
46 | self::KEYWORD, |
||
47 | $value, |
||
48 | $validator->getPointer(), |
||
49 | ['value' => $value, 'multiple_of' => $parameter] |
||
50 | ); |
||
51 | } |
||
52 | } |
||
53 |