Total Complexity | 9 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | #[Attribute] |
||
10 | class Between implements Rule |
||
11 | { |
||
12 | 1 | public function __construct(private float|int $largerThanOrEquals, private float|int $smallerThanOrEquals){} |
|
13 | |||
14 | 1 | public function applicableToTypes(): array |
|
17 | } |
||
18 | |||
19 | /** |
||
20 | * @param int|float|string|mixed[] $value |
||
21 | */ |
||
22 | 1 | public function isValid(mixed $value): bool |
|
23 | { |
||
24 | 1 | if (is_array($value)) { |
|
25 | 1 | $nrOfItemsInArray = count($value); |
|
26 | |||
27 | 1 | return $nrOfItemsInArray >= $this->largerThanOrEquals && $nrOfItemsInArray <= $this->smallerThanOrEquals; |
|
28 | } |
||
29 | |||
30 | 1 | if (is_string($value)) { |
|
31 | 1 | $nrOfCharacters = mb_strlen($value); |
|
32 | |||
33 | 1 | return $nrOfCharacters >= $this->largerThanOrEquals && $nrOfCharacters <= $this->smallerThanOrEquals; |
|
34 | } |
||
35 | |||
36 | 1 | return $value >= $this->largerThanOrEquals && $value <= $this->smallerThanOrEquals; |
|
37 | } |
||
38 | |||
39 | 1 | public function getMessage(): string |
|
42 | } |
||
43 | } |
||
44 |