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