SequentialCommand::jsonSerialize()   B
last analyzed

Complexity

Conditions 10
Paths 32

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 10

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 10
eloc 12
nc 32
nop 0
dl 0
loc 25
ccs 13
cts 13
cp 1
crap 10
rs 7.6666
c 1
b 0
f 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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