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

Path::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 14
dl 0
loc 17
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGItem;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\AVGItemType;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\StrokeLineCap;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\StrokeLineJoin;
10
11
class Path extends AVGItem implements \JsonSerializable
12
{
13
    public const TYPE = AVGItemType::PATH;
14
15
    /**
16
     * @param string|null $fill Fill color
17
     * @param int|null $fillOpacity Fill opacity
18
     * @param string|null $fillTransform Fill transform
19
     * @param string|null $pathData Path data string
20
     * @param int|null $pathLength Path length
21
     * @param string|null $stroke Stroke color
22
     * @param int[]|null $strokeDashArray Array of dash lengths
23
     * @param int|null $strokeDashOffset Dash offset
24
     * @param StrokeLineCap|null $strokeLineCap Line cap style
25
     * @param StrokeLineJoin|null $strokeLineJoin Line join style
26
     * @param int|null $strokeMiterLimit Miter limit
27
     * @param int|null $strokeOpacity Stroke opacity
28
     * @param string|null $strokeTransform Stroke transform
29
     * @param int|null $strokeWidth Stroke width
30
     */
31 10
    public function __construct(
32
        public ?string $fill = null,
33
        public ?int $fillOpacity = null,
34
        public ?string $fillTransform = null,
35
        public ?string $pathData = null,
36
        public ?int $pathLength = null,
37
        public ?string $stroke = null,
38
        public ?array $strokeDashArray = null,
39
        public ?int $strokeDashOffset = null,
40
        public ?StrokeLineCap $strokeLineCap = null,
41
        public ?StrokeLineJoin $strokeLineJoin = null,
42
        public ?int $strokeMiterLimit = null,
43
        public ?int $strokeOpacity = null,
44
        public ?string $strokeTransform = null,
45
        public ?int $strokeWidth = null,
46
    ) {
47 10
        parent::__construct(self::TYPE);
48
    }
49
50 6
    public function jsonSerialize(): array
51
    {
52 6
        $data = parent::jsonSerialize();
53
54 6
        if ($this->fill !== null) {
55 1
            $data['fill'] = $this->fill;
56
        }
57
58 6
        if ($this->fillOpacity !== null) {
59 2
            $data['fillOpacity'] = $this->fillOpacity;
60
        }
61
62 6
        if ($this->fillTransform !== null) {
63 1
            $data['fillTransform'] = $this->fillTransform;
64
        }
65
66 6
        if ($this->pathData !== null) {
67 1
            $data['pathData'] = $this->pathData;
68
        }
69
70 6
        if ($this->pathLength !== null) {
71 2
            $data['pathLength'] = $this->pathLength;
72
        }
73
74 6
        if ($this->stroke !== null) {
75 1
            $data['stroke'] = $this->stroke;
76
        }
77
78 6
        if ($this->strokeDashArray !== null && !empty($this->strokeDashArray)) {
79 1
            $data['strokeDashArray'] = $this->strokeDashArray;
80
        }
81
82 6
        if ($this->strokeDashOffset !== null) {
83 2
            $data['strokeDashOffset'] = $this->strokeDashOffset;
84
        }
85
86 6
        if ($this->strokeLineCap !== null) {
87 2
            $data['strokeLineCap'] = $this->strokeLineCap->value;
88
        }
89
90 6
        if ($this->strokeLineJoin !== null) {
91 2
            $data['strokeLineJoin'] = $this->strokeLineJoin->value;
92
        }
93
94 6
        if ($this->strokeMiterLimit !== null) {
95 2
            $data['strokeMiterLimit'] = $this->strokeMiterLimit;
96
        }
97
98 6
        if ($this->strokeOpacity !== null) {
99 2
            $data['strokeOpacity'] = $this->strokeOpacity;
100
        }
101
102 6
        if ($this->strokeTransform !== null) {
103 1
            $data['strokeTransform'] = $this->strokeTransform;
104
        }
105
106 6
        if ($this->strokeWidth !== null) {
107 2
            $data['strokeWidth'] = $this->strokeWidth;
108
        }
109
110 6
        return $data;
111
    }
112
}
113