ParallelCommand::jsonSerialize()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 6
nc 4
nop 0
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 5
rs 9.6111
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 ParallelCommand extends AbstractStandardCommand
8
{
9
    public const TYPE = 'Parallel';
10
11
    /**
12
     * @param array|null $data Array of data to iterate over
13
     * @param AbstractStandardCommand[]|null $commands Commands to run in parallel
14
     */
15 7
    public function __construct(
16
        public ?array $data = null,
17
        public ?array $commands = null,
18
    ) {
19 7
        parent::__construct(self::TYPE);
20
    }
21
22 5
    public function jsonSerialize(): array
23
    {
24 5
        $data = parent::jsonSerialize();
25
26 5
        if ($this->data !== null && !empty($this->data)) {
27 2
            $data['data'] = $this->data;
28
        }
29
30 5
        if ($this->commands !== null && !empty($this->commands)) {
31 2
            $data['commands'] = $this->commands;
32
        }
33
34 5
        return $data;
35
    }
36
}
37