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

SetValueCommand::jsonSerialize()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

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