Passed
Push — master ( a53d55...43aca1 )
by Maximilian
03:50
created

SpeakItemCommand::jsonSerialize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
nc 4
nop 0
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\HighlightMode;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\ScrollAlign;
9
10
class SpeakItemCommand extends AbstractStandardCommand implements \JsonSerializable
11
{
12
    public const TYPE = 'SpeakItem';
13
14
    /**
15
     * @param string|null $componentId ID of the component to speak
16
     * @param ScrollAlign $align Alignment when scrolling to the item
17
     * @param HighlightMode $highlightMode How to highlight the item being spoken
18
     * @param int|null $minimumDwellTime Minimum time to dwell on each item in milliseconds
19
     */
20 8
    public function __construct(
21
        public ?string $componentId = null,
22
        public ScrollAlign $align = ScrollAlign::VISIBLE,
23
        public HighlightMode $highlightMode = HighlightMode::BLOCK,
24
        public ?int $minimumDwellTime = null,
25
    ) {
26 8
        parent::__construct(self::TYPE);
27
    }
28
29 6
    public function jsonSerialize(): array
30
    {
31 6
        $data = parent::jsonSerialize();
32
33 6
        if ($this->componentId !== null) {
34 5
            $data['componentId'] = $this->componentId;
35
        }
36
37 6
        $data['align'] = $this->align->value;
38 6
        $data['highlightMode'] = $this->highlightMode->value;
39
40 6
        if ($this->minimumDwellTime !== null) {
41 2
            $data['minimumDwellTime'] = $this->minimumDwellTime;
42
        }
43
44 6
        return $data;
45
    }
46
}
47