Total Complexity | 19 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
16 | class Range extends AbstractRule |
||
17 | { |
||
18 | /** |
||
19 | * @var mixed|null |
||
20 | */ |
||
21 | protected $min; |
||
22 | |||
23 | /** |
||
24 | * @var mixed|null |
||
25 | */ |
||
26 | protected $max; |
||
27 | |||
28 | /** |
||
29 | * Range constructor. |
||
30 | * |
||
31 | * @param mixed $min |
||
32 | * @param mixed $max |
||
33 | */ |
||
34 | public function __construct($min = null, $max = null) |
||
35 | { |
||
36 | if ($min === null && $max === null) { |
||
37 | throw new InvalidArgumentException('Either option "min" or "max" must be given.'); |
||
38 | } |
||
39 | |||
40 | if ($min !== null && $max !== null && $min > $max) { |
||
41 | throw new LogicException('"Min" option cannot be greater that "max".'); |
||
42 | } |
||
43 | |||
44 | if ($max !== null && $max < $min) { |
||
45 | throw new LogicException('"Max" option cannot be less that "min".'); |
||
46 | } |
||
47 | |||
48 | $this->min = $min; |
||
49 | $this->max = $max; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Validates input. |
||
54 | * |
||
55 | * @param mixed $input |
||
56 | * |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function isValid($input = null) |
||
94 | } |
||
95 | } |
||
96 |