Passed
Pull Request — master (#97)
by Maximilian
04:17
created

ScrollToComponentCommand::jsonSerialize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
nc 4
nop 0
dl 0
loc 15
ccs 8
cts 8
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\ScrollAlign;
8
9
class ScrollToComponentCommand extends AbstractStandardCommand implements \JsonSerializable
10
{
11
    public const TYPE = 'ScrollToComponent';
12
13
    /**
14
     * @param string|null $componentId ID of the component to scroll to
15
     * @param ScrollAlign $align Alignment of the component when scrolled to
16
     * @param int|null $targetDuration Duration of the scroll animation in milliseconds
17
     */
18 6
    public function __construct(
19
        public ?string $componentId = null,
20
        public ScrollAlign $align = ScrollAlign::VISIBLE,
21
        public ?int $targetDuration = null,
22
    ) {
23 6
        parent::__construct(self::TYPE);
24
    }
25
26 4
    public function jsonSerialize(): array
27
    {
28 4
        $data = parent::jsonSerialize();
29
30 4
        if ($this->componentId !== null) {
31 3
            $data['componentId'] = $this->componentId;
32
        }
33
34 4
        $data['align'] = $this->align->value;
35
36 4
        if ($this->targetDuration !== null) {
37 2
            $data['targetDuration'] = $this->targetDuration;
38
        }
39
40 4
        return $data;
41
    }
42
}
43