Total Complexity | 8 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
12 | final class EnableByMatchingSegment implements ToggleStrategy |
||
13 | { |
||
14 | public const NAME = 'enable_by_matching_segment'; |
||
15 | private string $id; |
||
16 | private Segments $segments; |
||
17 | |||
18 | 8 | public function __construct(string $id, Segments $segments) |
|
19 | { |
||
20 | 8 | $this->id = $id; |
|
21 | 8 | $this->segments = $segments; |
|
22 | 8 | } |
|
23 | |||
24 | 3 | public function id(): string |
|
27 | } |
||
28 | |||
29 | 3 | public function type(): string |
|
30 | { |
||
31 | 3 | return self::NAME; |
|
32 | } |
||
33 | |||
34 | 6 | public function isSatisfiedBy(ConsumerIdentity $identity): bool |
|
35 | { |
||
36 | 6 | foreach ($this->segments->all() as $segment) { |
|
37 | 5 | if ($segment->match($identity->payload())) { |
|
38 | 3 | return true; |
|
39 | } |
||
40 | } |
||
41 | |||
42 | 3 | return false; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return array<string, string|array> |
||
47 | */ |
||
48 | 1 | public function toArray(): array |
|
56 | ), |
||
57 | ]; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return array<string, string|array> |
||
62 | */ |
||
63 | 1 | public function jsonSerialize(): array |
|
66 | } |
||
67 | } |
||
68 |