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

FrameComponent::jsonSerialize()   F

Complexity

Conditions 14
Paths 4096

Size

Total Lines 53
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 14.0797

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 14
eloc 26
nc 4096
nop 0
dl 0
loc 53
ccs 25
cts 27
cp 0.9259
crap 14.0797
rs 2.1
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\Component;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Gradient;
9
10
class FrameComponent extends APLBaseComponent implements \JsonSerializable
11
{
12
    public const TYPE = APLComponentType::FRAME;
13
14
    /**
15
     * @param Gradient|string|null $background Background fill that allows either a color or gradient
16
     * @param string|null $backgroundColor Background color (ignored if background is provided)
17
     * @param string|null $borderBottomLeftRadius Radius of the bottom-left corner
18
     * @param string|null $borderBottomRightRadius Radius of the bottom-right corner
19
     * @param string|null $borderColor Color of the border
20
     * @param string $borderRadius Corner radius for rounded-rectangle variant
21
     * @param string|null $borderStrokeWidth Width of the border stroke
22
     * @param string|null $borderTopLeftRadius Radius of the top-left corner
23
     * @param string|null $borderTopRightRadius Radius of the top-right corner
24
     * @param string $borderWidth Width of the border
25
     * @param APLBaseComponent|null $item Single child component to display inside the Frame
26
     * @param APLBaseComponent[]|null $items Array of child components to display inside the Frame
27
     */
28 10
    public function __construct(
29
        public Gradient|string|null $background = null,
30
        public ?string $backgroundColor = null,
31
        public ?string $borderBottomLeftRadius = null,
32
        public ?string $borderBottomRightRadius = null,
33
        public ?string $borderColor = null,
34
        public string $borderRadius = '0',
35
        public ?string $borderStrokeWidth = null,
36
        public ?string $borderTopLeftRadius = null,
37
        public ?string $borderTopRightRadius = null,
38
        public string $borderWidth = '0',
39
        public ?APLBaseComponent $item = null,
40
        public ?array $items = null,
41
    ) {
42 10
        parent::__construct(self::TYPE);
43
    }
44
45 5
    public function jsonSerialize(): array
46
    {
47 5
        $data = parent::jsonSerialize();
48
49 5
        if ($this->background !== null) {
50 1
            $data['background'] = $this->background;
51
        }
52
53 5
        if ($this->backgroundColor !== null) {
54 1
            $data['backgroundColor'] = $this->backgroundColor;
55
        }
56
57 5
        if ($this->borderBottomLeftRadius !== null) {
58 1
            $data['borderBottomLeftRadius'] = $this->borderBottomLeftRadius;
59
        }
60
61 5
        if ($this->borderBottomRightRadius !== null) {
62
            $data['borderBottomRightRadius'] = $this->borderBottomRightRadius;
63
        }
64
65 5
        if ($this->borderColor !== null) {
66 1
            $data['borderColor'] = $this->borderColor;
67
        }
68
69 5
        if ($this->borderRadius !== '0') {
70 2
            $data['borderRadius'] = $this->borderRadius;
71
        }
72
73 5
        if ($this->borderStrokeWidth !== null) {
74 1
            $data['borderStrokeWidth'] = $this->borderStrokeWidth;
75
        }
76
77 5
        if ($this->borderTopLeftRadius !== null) {
78
            $data['borderTopLeftRadius'] = $this->borderTopLeftRadius;
79
        }
80
81 5
        if ($this->borderTopRightRadius !== null) {
82 1
            $data['borderTopRightRadius'] = $this->borderTopRightRadius;
83
        }
84
85 5
        if ($this->borderWidth !== '0') {
86 2
            $data['borderWidth'] = $this->borderWidth;
87
        }
88
89 5
        if ($this->item !== null) {
90 1
            $data['item'] = $this->item;
91
        }
92
93 5
        if ($this->items !== null && !empty($this->items)) {
94 1
            $data['items'] = $this->items;
95
        }
96
97 5
        return $data;
98
    }
99
}
100