Lines 85.71% 6 / 7
Functions and Methods 75.00% 3 / 4
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
AnswerComponentCommand 85.71% 6 / 7 75.00% 3 / 4 5.07 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% 4 / 4 100.00% 1 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Client\Connection\Command\Component;
6
7use Stewart\Client\Component\ComponentCommandAnswer;
8use Stewart\Client\Connection\Command\HaCommand;
9
10final readonly class AnswerComponentCommand implements HaCommand
11{
12    public function __construct(public ComponentCommandAnswer $answer) {}
13
14    public function type(): string
15    {
16        return 'stewart/command/result';
17    }
18
19    public function describe(): string
20    {
21        return \sprintf('%s %s', $this->type(), $this->answer->commandId);
22    }
23
24    public function toMessage(): array
25    {
26        $message = ['type' => $this->type(), 'command_id' => $this->answer->commandId, 'ok' => $this->answer->accepted];
27
28        if ($this->answer->message !== null) {
29            $message['message'] = $this->answer->message;
30        }
31
32        return $message;
33    }
34}