Conditions | 5 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | public function check($value): bool |
||
25 | { |
||
26 | // A CIDR should consist of an IP part and a mask bit number delimited by a `/` |
||
27 | |||
28 | // split by the slash that should be there |
||
29 | 2 | $parts = explode('/', $value, 2); |
|
30 | // we should have 2 parts (the ip and mask) |
||
31 | if (count($parts) !== 2) { |
||
32 | 2 | return false; |
|
33 | } |
||
34 | |||
35 | // validate the ip part |
||
36 | if (filter_var($parts[0], FILTER_VALIDATE_IP) === false) { |
||
37 | 2 | return false; |
|
38 | } |
||
39 | |||
40 | // check the mask part |
||
41 | // first of all, this should be an integer |
||
42 | if (filter_var($parts[1], FILTER_VALIDATE_INT) === false) { |
||
43 | 2 | return false; |
|
44 | } |
||
45 | |||
46 | // and it should be between 0 and 32 inclusive |
||
47 | 2 | return ! ($parts[1] < 0 || $parts[1] > 32); |
|
48 | } |
||
50 |