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

SelectCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 1
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B jsonSerialize() 0 21 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand;
6
7
class SelectCommand extends AbstractStandardCommand implements \JsonSerializable
8
{
9
    public const TYPE = 'Select';
10
11
    /**
12
     * @param string|null $componentId ID of the component to select
13
     * @param AbstractStandardCommand[]|null $commands Commands to run when condition is true
14
     * @param array|null $data Array of data to iterate over
15
     * @param AbstractStandardCommand[]|null $otherwise Commands to run when condition is false
16
     */
17 6
    public function __construct(
18
        public ?string $componentId = null,
19
        public ?array $commands = null,
20
        public ?array $data = null,
21
        public ?array $otherwise = null,
22
    ) {
23 6
        parent::__construct(self::TYPE);
24
    }
25
26 4
    public function jsonSerialize(): array
27
    {
28 4
        $data = parent::jsonSerialize();
29
30 4
        if ($this->componentId !== null) {
31 3
            $data['componentId'] = $this->componentId;
32
        }
33
34 4
        if ($this->commands !== null && !empty($this->commands)) {
35 2
            $data['commands'] = $this->commands;
36
        }
37
38 4
        if ($this->data !== null && !empty($this->data)) {
39 1
            $data['data'] = $this->data;
40
        }
41
42 4
        if ($this->otherwise !== null && !empty($this->otherwise)) {
43 1
            $data['otherwise'] = $this->otherwise;
44
        }
45
46 4
        return $data;
47
    }
48
}
49