Lines
90.90%
10 / 11
Methods
75.00%
3 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| type | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| describe | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| toMessage | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 2 | ||
| 10 | final readonly class SubscribeTrigger implements SubscriptionCommand | |
| 11 | { | |
| 12 | /** @param array<string, mixed> $variables */ | |
| 13 | public function __construct( | |
| 14 | public HaTriggerCollection $triggers, | |
| 15 | public array $variables = [], | |
| 16 | ) {} | |
| 17 | ||
| 18 | public function type(): string | |
| 19 | { | |
| 20 | return 'subscribe_trigger'; | |
| 21 | } | |
| 22 | ||
| 23 | public function describe(): string | |
| 24 | { | |
| 25 | $platforms = $this->triggers->mapToList(static fn(HaTrigger $trigger): string => $trigger->getPlatform()); | |
| 26 | ||
| 27 | return \sprintf('subscribe_trigger "%s"', implode(',', $platforms)); | |
| 28 | } | |
| 29 | ||
| 30 | public function toMessage(): array | |
| 31 | { | |
| 32 | $message = [ | |
| 33 | 'type' => $this->type(), | |
| 34 | 'trigger' => $this->triggers->mapToList(static fn(HaTrigger $trigger): array => $trigger->toArray()), | |
| 35 | ]; | |
| 36 | ||
| 37 | if ($this->variables !== []) { | |
| 38 | $message['variables'] = $this->variables; | |
| 39 | } | |
| 40 | ||
| 41 | return $message; | |
| 42 | } | |
| 43 | } |