ScrollToIndexCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A jsonSerialize() 0 19 4
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 ScrollToIndexCommand extends AbstractStandardCommand implements \JsonSerializable
10
{
11
    public const TYPE = 'ScrollToIndex';
12
13
    /**
14
     * @param string|null $componentId ID of the component to scroll
15
     * @param int|null $index Index to scroll to
16
     * @param ScrollAlign $align Alignment when scrolled to index
17
     * @param int|null $targetDuration Duration of the scroll animation in milliseconds
18
     */
19 7
    public function __construct(
20
        public ?string $componentId = null,
21
        public ?int $index = null,
22
        public ScrollAlign $align = ScrollAlign::VISIBLE,
23
        public ?int $targetDuration = null,
24
    ) {
25 7
        parent::__construct(self::TYPE);
26
    }
27
28 5
    public function jsonSerialize(): array
29
    {
30 5
        $data = parent::jsonSerialize();
31
32 5
        if ($this->componentId !== null) {
33 4
            $data['componentId'] = $this->componentId;
34
        }
35
36 5
        if ($this->index !== null) {
37 4
            $data['index'] = $this->index;
38
        }
39
40 5
        $data['align'] = $this->align->value;
41
42 5
        if ($this->targetDuration !== null) {
43 1
            $data['targetDuration'] = $this->targetDuration;
44
        }
45
46 5
        return $data;
47
    }
48
}
49