Conditions | 3 |
Paths | 3 |
Total Lines | 26 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 3 |
1 | <?php |
||
14 | 2 | public static function validate($value, $multiple, $pointer = null) |
|
15 | { |
||
16 | 2 | if (!is_numeric($value)) { |
|
17 | 2 | 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 | 2 | $quotient = $value / $multiple; |
|
22 | 2 | $mod = $quotient - floor($quotient); |
|
23 | 2 | if ($mod == 0) { |
|
24 | 2 | return null; |
|
25 | } |
||
26 | |||
27 | 2 | $message = sprintf( |
|
28 | 2 | 'Number "%d" is not a multiple of "%d"', |
|
29 | 2 | JsonGuard\asString($value), |
|
30 | 2 | JsonGuard\asString($multiple) |
|
31 | 2 | ); |
|
32 | 2 | return new ValidationError( |
|
33 | 2 | $message, |
|
34 | 2 | ErrorCode::INVALID_MULTIPLE, |
|
35 | 2 | $value, |
|
36 | 2 | $pointer, |
|
37 | 2 | ['multiple_of' => $multiple] |
|
38 | 2 | ); |
|
39 | } |
||
40 | } |
||
41 |