SequentialCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 5
dl 0
loc 8
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 SequentialCommand extends AbstractStandardCommand implements \JsonSerializable
8
{
9
    public const TYPE = 'Sequential';
10
11
    /**
12
     * @param AbstractStandardCommand[]|null $catch Commands to run if an error occurs
13
     * @param AbstractStandardCommand[]|null $commands Commands to run sequentially
14
     * @param array|null $data Array of data to iterate over
15
     * @param int|null $repeatCount Number of times to repeat the sequence
16
     * @param AbstractStandardCommand[]|null $finally Commands to run after completion
17
     */
18 7
    public function __construct(
19
        public ?array $catch = null,
20
        public ?array $commands = null,
21
        public ?array $data = null,
22
        public ?int $repeatCount = null,
23
        public ?array $finally = 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->catch !== null && !empty($this->catch)) {
33 1
            $data['catch'] = $this->catch;
34
        }
35
36 5
        if ($this->commands !== null && !empty($this->commands)) {
37 2
            $data['commands'] = $this->commands;
38
        }
39
40 5
        if ($this->data !== null && !empty($this->data)) {
41 1
            $data['data'] = $this->data;
42
        }
43
44 5
        if ($this->repeatCount !== null) {
45 3
            $data['repeatCount'] = $this->repeatCount;
46
        }
47
48 5
        if ($this->finally !== null && !empty($this->finally)) {
49 1
            $data['finally'] = $this->finally;
50
        }
51
52 5
        return $data;
53
    }
54
}
55