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

SetPageCommand   A

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\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