NoaaAlert::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 51
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 26
c 0
b 0
f 0
nc 2
nop 23
dl 0
loc 51
ccs 26
cts 26
cp 1
crap 2
rs 9.504

How to fix   Long Method    Many Parameters   

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:

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
namespace NoaaCapAlerts\Model;
4
5
use NoaaCapAlerts\Model\Polygon\Polygon;
6
7
class NoaaAlert
8
{
9
    protected string $idString;
10
    protected string $idKey;
11
    protected \DateTime $updatedTime;
12
    protected \DateTime $publishedTime;
13
    protected string $authorName;
14
    protected string $title;
15
    protected string $link;
16
    protected string $summary;
17
    protected string $capEvent;
18
    protected ?\DateTime $capEffectiveTime;
19
    protected ?\DateTime $capExpiresTime;
20
    protected string $capStatus;
21
    protected string $capMsgType;
22
    protected string $capCategory;
23
    protected string $capUrgencyExpected;
24
    protected string $capSeverity;
25
    protected string $capCertainty;
26
    protected string $capAreaDesc;
27
    protected array $capPolygon;
28
    protected array $capGeo;
29
    protected string $capGeoString;
30
    protected string $vtec;
31
    protected Polygon $polygon;
32
33 4
    public function __construct(string $idString,
34
                                string $idKey,
35
                                \DateTime $updatedTime,
36
                                \DateTime $publishedTime,
37
                                string $authorName,
38
                                string $title,
39
                                string $link,
40
                                string $summary,
41
                                string $capEvent,
42
                                ? \DateTime $capEffectiveTime,
43
                                ? \DateTime $capExpiresTime,
44
                                string $capStatus,
45
                                string $capMsgType,
46
                                string $capCategory,
47
                                string $capUrgencyExpected,
48
                                string $capSeverity,
49
                                string $capCertainty,
50
                                string $capAreaDesc,
51
                                array $capPolygon,
52
                                array $capGeo,
53
                                string $capGeoString,
54
                                string $vtec,
55
                                ?Polygon $polygon = null)
56
    {
57 4
        $this->idString = $idString;
58 4
        $this->idKey = $idKey;
59 4
        $this->updatedTime = $updatedTime;
60 4
        $this->publishedTime = $publishedTime;
61 4
        $this->authorName = $authorName;
62 4
        $this->title = $title;
63 4
        $this->link = $link;
64 4
        $this->summary = $summary;
65 4
        $this->capEvent = $capEvent;
66 4
        $this->capEffectiveTime = $capEffectiveTime;
67 4
        $this->capExpiresTime = $capExpiresTime;
68 4
        $this->capStatus = $capStatus;
69 4
        $this->capMsgType = $capMsgType;
70 4
        $this->capCategory = $capCategory;
71 4
        $this->capUrgencyExpected = $capUrgencyExpected;
72 4
        $this->capSeverity = $capSeverity;
73 4
        $this->capCertainty = $capCertainty;
74 4
        $this->capAreaDesc = $capAreaDesc;
75 4
        $this->capPolygon = $capPolygon;
76 4
        $this->capGeo = $capGeo;
77 4
        $this->capGeoString = $capGeoString;
78 4
        $this->vtec = $vtec;
79
80 4
        if ($polygon !== null) {
81 2
            $this->polygon = $polygon;
82
        } else {
83 2
            $this->polygon = new Polygon();
84
        }
85 4
    }
86
87 1
    public function toArray(): array
88
    {
89
        return [
90 1
            'idString' => $this->idString,
91 1
            'idKey' => $this->idKey,
92 1
            'updatedTime' => $this->updatedTime,
93 1
            'publishedTime' => $this->publishedTime,
94 1
            'authorName' => $this->authorName,
95 1
            'title' => $this->title,
96 1
            'link' => $this->link,
97 1
            'summary' => $this->summary,
98 1
            'capEvent' => $this->capEvent,
99 1
            'capEffectiveTime' => $this->capEffectiveTime,
100 1
            'capExpiresTime' => $this->capExpiresTime,
101 1
            'capStatus' => $this->capStatus,
102 1
            'capMsgType' => $this->capMsgType,
103 1
            'capCategory' => $this->capCategory,
104 1
            'capUrgencyExpected' => $this->capUrgencyExpected,
105 1
            'capSeverity' => $this->capSeverity,
106 1
            'capCertainty' => $this->capCertainty,
107 1
            'capAreaDesc' => $this->capAreaDesc,
108 1
            'capPolygon' => $this->capPolygon,
109 1
            'capGeo' => $this->capGeo,
110 1
            'capGeoString' => $this->capGeoString,
111 1
            'vtec' => $this->vtec,
112
        ];
113
    }
114
115 1
    public function getIdString(): string
116
    {
117 1
        return $this->idString;
118
    }
119
120 1
    public function getIdKey(): string
121
    {
122 1
        return $this->idKey;
123
    }
124
125 1
    public function getUpdatedTime(): \DateTime
126
    {
127 1
        return $this->updatedTime;
128
    }
129
130 1
    public function getPublishedTime(): \DateTime
131
    {
132 1
        return $this->publishedTime;
133
    }
134
135 1
    public function getAuthorName(): string
136
    {
137 1
        return $this->authorName;
138
    }
139
140 1
    public function getTitle(): string
141
    {
142 1
        return $this->title;
143
    }
144
145 1
    public function getLink(): string
146
    {
147 1
        return $this->link;
148
    }
149
150 1
    public function getSummary(): string
151
    {
152 1
        return $this->summary;
153
    }
154
155 1
    public function getCapEvent(): string
156
    {
157 1
        return $this->capEvent;
158
    }
159
160 1
    public function getCapEffectiveTime(): ?\DateTime
161
    {
162 1
        return $this->capEffectiveTime;
163
    }
164
165 1
    public function getCapExpiresTime(): ?\DateTime
166
    {
167 1
        return $this->capExpiresTime;
168
    }
169
170 1
    public function getCapStatus(): string
171
    {
172 1
        return $this->capStatus;
173
    }
174
175 1
    public function getCapMsgType(): string
176
    {
177 1
        return $this->capMsgType;
178
    }
179
180 1
    public function getCapCategory(): string
181
    {
182 1
        return $this->capCategory;
183
    }
184
185 1
    public function getCapUrgencyExpected(): string
186
    {
187 1
        return $this->capUrgencyExpected;
188
    }
189
190 1
    public function getCapSeverity(): string
191
    {
192 1
        return $this->capSeverity;
193
    }
194
195 1
    public function getCapCertainty(): string
196
    {
197 1
        return $this->capCertainty;
198
    }
199
200 1
    public function getCapAreaDesc(): string
201
    {
202 1
        return $this->capAreaDesc;
203
    }
204
205 1
    public function getCapPolygon(): array
206
    {
207 1
        return $this->capPolygon;
208
    }
209
210 1
    public function getCapGeo(): array
211
    {
212 1
        return $this->capGeo;
213
    }
214
215 1
    public function getCapGeoString(): string
216
    {
217 1
        return $this->capGeoString;
218
    }
219
220 1
    public function getVtec(): string
221
    {
222 1
        return $this->vtec;
223
    }
224
}