ImportPackageCommand::jsonSerialize()   B
last analyzed

Complexity

Conditions 9
Paths 64

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 9
eloc 14
nc 64
nop 0
dl 0
loc 29
ccs 15
cts 15
cp 1
crap 9
rs 8.0555
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 ImportPackageCommand extends AbstractStandardCommand
8
{
9
    public const TYPE = 'ImportPackage';
10
11
    /**
12
     * @param string|null $accept Package accept property
13
     * @param string|null $name Package name property
14
     * @param AbstractStandardCommand[]|null $onFail Commands to run if import fails
15
     * @param AbstractStandardCommand[]|null $onLoad Commands to run when import loads
16
     * @param string|null $source Package source property
17
     * @param string|null $version Package version property
18
     */
19 6
    public function __construct(
20
        public ?string $accept = null,
21
        public ?string $name = null,
22
        public ?array $onFail = null,
23
        public ?array $onLoad = null,
24
        public ?string $source = null,
25
        public ?string $version = null,
26
    ) {
27 6
        parent::__construct(self::TYPE);
28
    }
29
30 4
    public function jsonSerialize(): array
31
    {
32 4
        $data = parent::jsonSerialize();
33
34 4
        if ($this->accept !== null) {
35 2
            $data['accept'] = $this->accept;
36
        }
37
38 4
        if ($this->name !== null) {
39 2
            $data['name'] = $this->name;
40
        }
41
42 4
        if ($this->onFail !== null && !empty($this->onFail)) {
43 1
            $data['onFail'] = $this->onFail;
44
        }
45
46 4
        if ($this->onLoad !== null && !empty($this->onLoad)) {
47 1
            $data['onLoad'] = $this->onLoad;
48
        }
49
50 4
        if ($this->source !== null) {
51 1
            $data['source'] = $this->source;
52
        }
53
54 4
        if ($this->version !== null) {
55 1
            $data['version'] = $this->version;
56
        }
57
58 4
        return $data;
59
    }
60
}
61