Lines
90.90%
10 / 11
Functions and Methods
75.00%
3 / 4
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| CallService | 90.90% | 10 / 11 | 75.00% | 3 / 4 | 8.05 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| type | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| describe | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| toMessage | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 5 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Client\Connection\Command; | |
| 6 | ||
| 7 | use Stewart\Contracts\Service\ServiceTarget; | |
| 8 | ||
| 9 | final readonly class CallService implements HaCommand | |
| 10 | { | |
| 11 | /** @param array<string, mixed> $data */ | |
| 12 | public function __construct( | |
| 13 | public string $domain, | |
| 14 | public string $service, | |
| 15 | public array $data = [], | |
| 16 | public ?ServiceTarget $target = null, | |
| 17 | public bool $returnResponse = false, | |
| 18 | ) {} | |
| 19 | ||
| 20 | public function type(): string | |
| 21 | { | |
| 22 | return 'call_service'; | |
| 23 | } | |
| 24 | ||
| 25 | public function describe(): string | |
| 26 | { | |
| 27 | return \sprintf('call_service %s.%s', $this->domain, $this->service); | |
| 28 | } | |
| 29 | ||
| 30 | public function toMessage(): array | |
| 31 | { | |
| 32 | $message = ['type' => $this->type(), 'domain' => $this->domain, 'service' => $this->service]; | |
| 33 | ||
| 34 | if ($this->data !== []) { | |
| 35 | $message['service_data'] = $this->data; | |
| 36 | } | |
| 37 | ||
| 38 | if ($this->target !== null && !$this->target->isEmpty()) { | |
| 39 | $message['target'] = $this->target->toArray(); | |
| 40 | } | |
| 41 | ||
| 42 | if ($this->returnResponse) { | |
| 43 | $message['return_response'] = true; | |
| 44 | } | |
| 45 | ||
| 46 | return $message; | |
| 47 | } | |
| 48 | } |