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

SetPageCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
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 4
dl 0
loc 7
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
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SetPagePosition;
8
9
class SetPageCommand extends AbstractStandardCommand implements \JsonSerializable
10
{
11
    public const TYPE = 'SetPage';
12
13
    /**
14
     * @param string|null $componentId ID of the component to set page on
15
     * @param SetPagePosition $position Position type for the page change
16
     * @param int|null $transitionDuration Duration of the page transition in milliseconds
17
     * @param int|null $value Page value to set
18
     */
19 7
    public function __construct(
20
        public ?string $componentId = null,
21
        public SetPagePosition $position = SetPagePosition::ABSOLUTE,
22
        public ?int $transitionDuration = null,
23
        public ?int $value = 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
        $data['position'] = $this->position->value;
37
38 5
        if ($this->transitionDuration !== null) {
39 3
            $data['transitionDuration'] = $this->transitionDuration;
40
        }
41
42 5
        if ($this->value !== null) {
43 3
            $data['value'] = $this->value;
44
        }
45
46 5
        return $data;
47
    }
48
}
49