| Total Complexity | 10 |
| Total Lines | 56 |
| 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 string $id; |
||
| 17 | private Segments $segments; |
||
| 18 | |||
| 19 | 6 | public function __construct(string $id, Segments $segments) |
|
| 20 | { |
||
| 21 | 6 | foreach ($segments->all() as $segment) { |
|
| 22 | 4 | if (false === $segment instanceof IdentitySegment) { |
|
| 23 | 1 | throw new InvalidArgumentException(sprintf( |
|
| 24 | 'Enable by matching identity id segment must be instance of %s class.', |
||
| 25 | IdentitySegment::class |
||
| 26 | )); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | 5 | $this->id = $id; |
|
| 30 | 5 | $this->segments = $segments; |
|
| 31 | } |
||
| 32 | |||
| 33 | 1 | public function id(): string |
|
| 34 | { |
||
| 35 | 1 | return $this->id; |
|
| 36 | } |
||
| 37 | |||
| 38 | 1 | public function type(): string |
|
| 39 | { |
||
| 40 | 1 | return self::NAME; |
|
| 41 | } |
||
| 42 | |||
| 43 | 3 | public function isSatisfiedBy(ConsumerIdentity $identity): bool |
|
| 52 | } |
||
| 53 | |||
| 54 | 1 | public function toArray(): array |
|
| 55 | { |
||
| 56 | return [ |
||
| 57 | 1 | 'id' => $this->id, |
|
| 58 | 'type' => self::NAME, |
||
| 59 | 1 | 'segments' => array_map( |
|
| 60 | 1 | static fn(ISegment $segment): array => $segment->toArray(), |
|
| 61 | 1 | $this->segments->all() |
|
| 62 | ), |
||
| 63 | ]; |
||
| 64 | } |
||
| 65 | |||
| 66 | 1 | public function jsonSerialize(): array |
|
| 69 | } |
||
| 70 | } |
||
| 71 |