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

ScrollCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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