Conditions | 3 |
Paths | 3 |
Total Lines | 21 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
14 | 4 | public static function validate($value, $multiple, $pointer = null) |
|
15 | { |
||
16 | 4 | if (!is_numeric($value)) { |
|
17 | 4 | return null; |
|
18 | } |
||
19 | |||
20 | // for some reason fmod does not return 0 for cases like fmod(0.0075,0.0001) so I'm doing this manually. |
||
21 | 4 | $quotient = $value / $multiple; |
|
22 | 4 | $mod = $quotient - floor($quotient); |
|
23 | 4 | if ($mod == 0) { |
|
24 | 4 | return null; |
|
25 | } |
||
26 | |||
27 | 4 | return new ValidationError( |
|
28 | 4 | 'Number {value} is not a multiple of {multiple_of}', |
|
29 | 4 | ErrorCode::INVALID_MULTIPLE, |
|
30 | 4 | $value, |
|
31 | 4 | $pointer, |
|
32 | 4 | ['value' => $value, 'multiple_of' => $multiple] |
|
33 | 4 | ); |
|
34 | 4 | } |
|
35 | } |
||
36 |