Conditions | 5 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | public function check($value): bool |
||
25 | { |
||
26 | if (! is_numeric($value)) { |
||
27 | return false; |
||
28 | } |
||
29 | |||
30 | $this->requireParameters(['min']); |
||
31 | |||
32 | $min = $this->parameter('min'); |
||
33 | $max = $this->parameter('max'); |
||
34 | |||
35 | $matches = []; |
||
36 | |||
37 | if (preg_match('/^[+-]?\d*\.?(\d*)$/', $value, $matches) !== 1) { |
||
38 | return false; |
||
39 | } |
||
40 | |||
41 | $decimals = strlen(end($matches)); |
||
42 | |||
43 | if (empty($max)) { |
||
44 | return (int) $decimals === (int) $min; |
||
45 | } |
||
46 | |||
47 | return $decimals >= $min && $decimals <= $max; |
||
48 | } |
||
50 |