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

ScrollToComponentCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A jsonSerialize() 0 15 3
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