Passed
Pull Request — master (#97)
by Maximilian
04:17
created

Resource::jsonSerialize()   F

Complexity

Conditions 25
Paths > 20000

Size

Total Lines 54
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 35
CRAP Score 25

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 25
eloc 34
nc 65536
nop 0
dl 0
loc 54
ccs 35
cts 35
cp 1
crap 25
rs 0
c 1
b 0
f 1

How to fix   Long Method    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 Resource implements \JsonSerializable
8
{
9
    /**
10
     * @param bool|null $boolean Single boolean value
11
     * @param array<string,bool>|null $booleans Map of boolean name to boolean value
12
     * @param string|null $color Single color value
13
     * @param array<string,string>|null $colors Map of color name to color value
14
     * @param string|null $description Description of this resource block
15
     * @param string|null $dimension Single dimension value
16
     * @param array<string,string>|null $dimensions Map of dimension name to dimension value
17
     * @param string|null $easing Single easing function
18
     * @param array<string,string>|null $easings Map of name to easing function definition
19
     * @param Gradient|null $gradient Single gradient definition
20
     * @param array<string,Gradient>|null $gradients Map of gradient name to gradient definition
21
     * @param string|null $number Single number value
22
     * @param array<string,string>|null $numbers Map of name to number
23
     * @param string|null $string Single string value
24
     * @param array<string,string>|null $strings Map of name to string
25
     * @param string|null $when APL boolean expression controlling whether this resource is considered
26
     */
27 13
    public function __construct(
28
        public ?bool $boolean = null,
29
        public ?array $booleans = null,
30
        public ?string $color = null,
31
        public ?array $colors = null,
32
        public ?string $description = null,
33
        public ?string $dimension = null,
34
        public ?array $dimensions = null,
35
        public ?string $easing = null,
36
        public ?array $easings = null,
37
        public ?Gradient $gradient = null,
38
        public ?array $gradients = null,
39
        public ?string $number = null,
40
        public ?array $numbers = null,
41
        public ?string $string = null,
42
        public ?array $strings = null,
43
        public ?string $when = null,
44
    ) {
45 13
    }
46
47 8
    public function jsonSerialize(): array
48
    {
49 8
        $data = [];
50
51 8
        if ($this->boolean !== null) {
52 3
            $data['boolean'] = $this->boolean;
53
        }
54 8
        if ($this->booleans !== null && $this->booleans !== []) {
55 2
            $data['booleans'] = $this->booleans;
56
        }
57 8
        if ($this->color !== null) {
58 1
            $data['color'] = $this->color;
59
        }
60 8
        if ($this->colors !== null && $this->colors !== []) {
61 2
            $data['colors'] = $this->colors;
62
        }
63 8
        if ($this->description !== null && $this->description !== '') {
64 1
            $data['description'] = $this->description;
65
        }
66 8
        if ($this->dimension !== null) {
67 1
            $data['dimension'] = $this->dimension;
68
        }
69 8
        if ($this->dimensions !== null && $this->dimensions !== []) {
70 2
            $data['dimensions'] = $this->dimensions;
71
        }
72 8
        if ($this->easing !== null) {
73 1
            $data['easing'] = $this->easing;
74
        }
75 8
        if ($this->easings !== null && $this->easings !== []) {
76 2
            $data['easings'] = $this->easings;
77
        }
78 8
        if ($this->gradient !== null) {
79 1
            $data['gradient'] = $this->gradient;
80
        }
81 8
        if ($this->gradients !== null && $this->gradients !== []) {
82 2
            $data['gradients'] = $this->gradients;
83
        }
84 8
        if ($this->number !== null) {
85 1
            $data['number'] = $this->number;
86
        }
87 8
        if ($this->numbers !== null && $this->numbers !== []) {
88 2
            $data['numbers'] = $this->numbers;
89
        }
90 8
        if ($this->string !== null) {
91 1
            $data['string'] = $this->string;
92
        }
93 8
        if ($this->strings !== null && $this->strings !== []) {
94 2
            $data['strings'] = $this->strings;
95
        }
96 8
        if ($this->when !== null) {
97 2
            $data['when'] = $this->when;
98
        }
99
100 8
        return $data;
101
    }
102
}
103