Passed
Pull Request — master (#97)
by Maximilian
03:52
created

Command::jsonSerialize()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 10
nc 16
nop 0
dl 0
loc 21
ccs 11
cts 11
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\Document;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
8
9
class Command implements \JsonSerializable
10
{
11
    /**
12
     * @param Parameter[]|null $parameters Array of parameter definitions
13
     * @param AbstractStandardCommand|null $command Single command to run
14
     * @param AbstractStandardCommand[]|null $commands Array of commands to run
15
     * @param string|null $description Description of this command
16
     */
17 10
    public function __construct(
18
        public ?array $parameters = null,
19
        public ?AbstractStandardCommand $command = null,
20
        public ?array $commands = null,
21
        public ?string $description = null,
22
    ) {
23 10
    }
24
25 6
    public function jsonSerialize(): array
26
    {
27 6
        $data = [];
28
29 6
        if ($this->parameters !== null) {
30 2
            $data['parameters'] = $this->parameters;
31
        }
32
33 6
        if ($this->command !== null) {
34 2
            $data['command'] = $this->command;
35
        }
36
37 6
        if ($this->commands !== null) {
38 2
            $data['commands'] = $this->commands;
39
        }
40
41 6
        if ($this->description !== null) {
42 3
            $data['description'] = $this->description;
43
        }
44
45 6
        return $data;
46
    }
47
}
48