Total Complexity | 6 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | #[Attribute] |
||
10 | class LargerThan implements Rule |
||
11 | { |
||
12 | 1 | public function __construct(private float|int $largerThan){} |
|
13 | |||
14 | 1 | public function applicableToTypes(): array |
|
15 | { |
||
16 | 1 | return [Type::float, Type::int, Type::array, Type::string]; |
|
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 | return count($value) > $this->largerThan; |
|
26 | } |
||
27 | |||
28 | 1 | if (is_string($value)) { |
|
29 | 1 | return mb_strlen($value) > $this->largerThan; |
|
30 | } |
||
31 | |||
32 | 1 | return $value > $this->largerThan; |
|
33 | } |
||
34 | |||
35 | 1 | public function getMessage(): string |
|
38 | } |
||
39 | } |
||
40 |