Total Complexity | 11 |
Total Lines | 64 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | trait Compares |
||
11 | { |
||
12 | /** |
||
13 | * Determine whether the enum includes the given target. |
||
14 | */ |
||
15 | 32 | public static function has(mixed $target): bool |
|
16 | { |
||
17 | 32 | foreach (self::cases() as $case) { |
|
18 | 32 | if ($case->is($target)) { |
|
19 | 8 | return true; |
|
20 | } |
||
21 | } |
||
22 | |||
23 | 24 | return false; |
|
24 | } |
||
25 | |||
26 | /** |
||
27 | * Determine whether the enum does not include the given target. |
||
28 | */ |
||
29 | 16 | public static function doesntHave(mixed $target): bool |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Determine whether this case matches the given target. |
||
36 | */ |
||
37 | 98 | public function is(mixed $target): bool |
|
38 | { |
||
39 | 98 | return in_array($target, [$this, self::isPure() ? $this->name : $this->value], true); |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * Determine whether this case does not match the given target. |
||
44 | */ |
||
45 | 16 | public function isNot(mixed $target): bool |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * Determine whether this case matches at least one of the given targets. |
||
52 | * |
||
53 | * @param iterable<array-key, mixed> $targets |
||
54 | */ |
||
55 | 32 | public function in(iterable $targets): bool |
|
56 | { |
||
57 | 32 | foreach ($targets as $target) { |
|
58 | 32 | if ($this->is($target)) { |
|
59 | 8 | return true; |
|
60 | } |
||
61 | } |
||
62 | |||
63 | 24 | return false; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Determine whether this case does not match any of the given targets. |
||
68 | * |
||
69 | * @param iterable<array-key, mixed> $targets |
||
70 | */ |
||
71 | 16 | public function notIn(iterable $targets): bool |
|
74 | } |
||
75 | } |
||
76 |