Style::jsonSerialize()   B
last analyzed

Complexity

Conditions 10
Paths 32

Size

Total Lines 21
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 21
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\Document;
6
7
class Style implements \JsonSerializable
8
{
9
    /**
10
     * @param string|null $description Optional description of this style
11
     * @param string[]|null $extend List of styles that this style inherits from (array)
12
     * @param string|null $extends Single style that this style inherits from (string)
13
     * @param StyleValue|null $value Single style value object
14
     * @param StyleValue[]|null $values Array of style value objects
15
     */
16 16
    public function __construct(
17
        public ?string $description = null,
18
        public ?array $extend = null,
19
        public ?string $extends = null,
20
        public ?StyleValue $value = null,
21
        public ?array $values = null,
22
    ) {
23 16
    }
24
25 12
    public function jsonSerialize(): array
26
    {
27 12
        $data = [];
28
29 12
        if ($this->description !== null && $this->description !== '') {
30 2
            $data['description'] = $this->description;
31
        }
32 12
        if ($this->extend !== null && $this->extend !== []) {
33 3
            $data['extend'] = $this->extend;
34
        }
35 12
        if ($this->extends !== null && $this->extends !== '') {
36 2
            $data['extends'] = $this->extends;
37
        }
38 12
        if ($this->value instanceof StyleValue) {
39 3
            $data['value'] = $this->value;
40
        }
41 12
        if ($this->values !== null && $this->values !== []) {
42 2
            $data['values'] = $this->values;
43
        }
44
45 12
        return $data;
46
    }
47
}
48