| Total Complexity | 8 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class EnableByMatchingIdentityId implements ToggleStrategy |
||
| 14 | { |
||
| 15 | public const NAME = 'enable_by_matching_identity_id'; |
||
| 16 | private Segments $segments; |
||
| 17 | |||
| 18 | 6 | public function __construct(Segments $segments) |
|
| 19 | { |
||
| 20 | 6 | foreach ($segments->all() as $segment) { |
|
| 21 | 4 | if (false === $segment instanceof IdentitySegment) { |
|
| 22 | 1 | throw new InvalidArgumentException(sprintf( |
|
| 23 | 1 | 'Enable by matching identity id segment must be instance of %s class.', |
|
| 24 | 1 | IdentitySegment::class |
|
| 25 | )); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | 5 | $this->segments = $segments; |
|
| 29 | 5 | } |
|
| 30 | |||
| 31 | 3 | public function isSatisfiedBy(ConsumerIdentity $identity): bool |
|
| 40 | } |
||
| 41 | |||
| 42 | 1 | public function toArray(): array |
|
| 43 | { |
||
| 44 | return [ |
||
| 45 | 1 | 'type' => self::NAME, |
|
| 46 | 1 | 'segments' => array_map( |
|
| 47 | 1 | static fn(ISegment $segment): array => $segment->toArray(), |
|
| 48 | 1 | $this->segments->all() |
|
| 49 | ), |
||
| 50 | ]; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return array<string, string|array> |
||
| 55 | */ |
||
| 56 | 1 | public function jsonSerialize(): array |
|
| 59 | } |
||
| 60 | } |
||
| 61 |