Passed
Push — master ( 0057b2...3e8fcf )
by Marek
02:11
created

Ticket   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 379
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 55
lcom 3
cbo 2
dl 0
loc 379
ccs 157
cts 157
cp 1
rs 6.8
c 0
b 0
f 0

48 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 31 1
A compareStatus() 0 5 1
A id() 0 4 1
A key() 0 4 1
A assigneeName() 0 4 1
A assigneeDisplayName() 0 4 1
A assigneeEmail() 0 4 1
A isAssigneeActive() 0 4 1
A ticketStatus() 0 4 1
A ticketStatusCategory() 0 4 1
A components() 0 4 1
A type() 0 4 1
A project() 0 4 1
A fixVersion() 0 4 1
A summary() 0 4 1
A branch() 0 4 1
A lastUpdate() 0 4 1
A url() 0 4 1
A pullRquestStatus() 0 4 1
A repository() 0 4 1
A hasDirectory() 0 4 1
A directory() 0 4 1
A pullRequestName() 0 4 1
A isDone() 0 4 1
A hasBranch() 0 4 1
A setRepository() 0 4 1
A setIsDone() 0 7 2
A setHasBranch() 0 7 2
A setId() 0 7 2
A setKey() 0 7 2
A setAssigneeName() 0 4 1
A setAssigneeDisplayName() 0 4 1
A setAssigneeEmail() 0 4 1
A setIsAssigneeActive() 0 4 1
A setTicketStatus() 0 7 2
A setTicketStatusCategory() 0 4 1
A setComponents() 0 4 1
A setType() 0 4 1
A setProject() 0 7 2
A setFixVersion() 0 4 1
A setSummary() 0 4 1
A setBranch() 0 4 1
A setLastUpdate() 0 4 1
A setUrl() 0 4 1
A setPullRequestStatus() 0 4 1
A setHasDirectory() 0 7 2
A setDirectory() 0 4 1
A setPullRequestName() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Ticket often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Ticket, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace AppBuilder\Application\Model\ValueObject;
6
7
use AppBuilder\Application\Model\Exception\NullArgumentException;
8
use AppBuilder\Application\Module\Jira\ValueObject\JiraTicketStatus;
9
10
/**
11
 * Class represents complete ticket.
12
 */
13
class Ticket
14
{
15
    /** @var string */
16
    private const DONE_STATUS = 'Done';
17
18
    /** @var ?int */
19
    private $id;
20
21
    /** @var ?string */
22
    private $key;
23
24
    /** @var ?string */
25
    private $assigneeName;
26
27
    /** @var ?string */
28
    private $assigneeDisplayName;
29
30
    /** @var ?string */
31
    private $assigneeEmail;
32
33
    /** @var ?bool */
34
    private $isAssigneeActive;
35
36
    /** @var ?string */
37
    private $ticketStatus;
38
39
    /** @var bool */
40
    private $isDone;
41
42
    /** @var ?string */
43
    private $ticketStatusCategory;
44
45
    /** @var ?string */
46
    private $components;
47
48
    /** @var ?string */
49
    private $type;
50
51
    /** @var ?string */
52
    private $project;
53
54
    /** @var ?string */
55
    private $fixVersion;
56
57
    /** @var ?string */
58
    private $summary;
59
60
    /** @var ?string */
61
    private $branch;
62
63
    /** @var bool */
64
    private $hasBranch;
65
66
    /** @var ?string */
67
    private $lastUpdate;
68
69
    /** @var ?string */
70
    private $url;
71
72
    /** @var ?string */
73
    private $pullRequestStatus;
74
75
    /** @var ?string */
76
    private $pullRequestName;
77
78
    /** @var ?string */
79
    private $repository;
80
81
    /** @var ?bool */
82
    private $hasDirectory;
83
84
    /** @var ?string */
85
    private $directory;
86
87 10
    public function __construct(
88
        array $ticketData,
89
        array $prData,
90
        array $dirData
91
    ) {
92 10
        $this->setId($ticketData['id']);
93 9
        $this->setKey($ticketData['ticket_key']);
94 8
        $this->setAssigneeName($ticketData['assignee_name']);
95 8
        $this->setAssigneeDisplayName($ticketData['assignee_display_name']);
96 8
        $this->setAssigneeEmail($ticketData['assignee_email']);
97 8
        $this->setIsAssigneeActive($ticketData['assignee_active']);
98 8
        $this->setTicketStatus($ticketData['status']);
99 7
        $this->setIsDone($ticketData['status']);
100 7
        $this->setTicketStatusCategory($ticketData['status_category']);
101 7
        $this->setComponents($ticketData['components']);
102 7
        $this->setType($ticketData['ticket_type']);
103 7
        $this->setProject($ticketData['project']);
104 6
        $this->setFixVersion($ticketData['fix_version']);
105 6
        $this->setSummary($ticketData['summary']);
106
107 6
        $this->setBranch($prData['pull_request_branch']);
108 6
        $this->setHasBranch($prData['pull_request_branch']);
109 6
        $this->setLastUpdate($prData['pull_request_last_update']);
110 6
        $this->setUrl($prData['pull_request_url']);
111 6
        $this->setPullRequestStatus($prData['pull_request_status']);
112 6
        $this->setPullRequestName($prData['pull_request_name']);
113 6
        $this->setRepository($prData['repository']);
114
115 6
        $this->setHasDirectory($dirData['ticketExists']);
116 5
        $this->setDirectory($dirData['ticketDir']);
117 5
    }
118
119
    /**
120
     * Compares passed status to tickets status.
121
     * Returns true if same, false if not.
122
     */
123 2
    public function compareStatus(string $status) : bool
124
    {
125 2
        return mb_strtolower(JiraTicketStatus::createFromString($status)->status())
126 2
            === mb_strtolower($this->ticketStatus);
127
    }
128
129 2
    public function id() : int
130
    {
131 2
        return $this->id;
132
    }
133
134 2
    public function key() : string
135
    {
136 2
        return $this->key;
137
    }
138
139 2
    public function assigneeName() : ?string
140
    {
141 2
        return $this->assigneeName;
142
    }
143
144 2
    public function assigneeDisplayName() : ?string
145
    {
146 2
        return $this->assigneeDisplayName;
147
    }
148
149 2
    public function assigneeEmail() : ?string
150
    {
151 2
        return $this->assigneeEmail;
152
    }
153
154 2
    public function isAssigneeActive() : ?bool
155
    {
156 2
        return $this->isAssigneeActive;
157
    }
158
159 2
    public function ticketStatus() : string
160
    {
161 2
        return $this->ticketStatus;
162
    }
163
164 2
    public function ticketStatusCategory() : ?string
165
    {
166 2
        return $this->ticketStatusCategory;
167
    }
168
169 2
    public function components() : ?string
170
    {
171 2
        return $this->components;
172
    }
173
174 2
    public function type() : ?string
175
    {
176 2
        return $this->type;
177
    }
178
179 2
    public function project() : string
180
    {
181 2
        return $this->project;
182
    }
183
184 2
    public function fixVersion() : ?string
185
    {
186 2
        return $this->fixVersion;
187
    }
188
189 2
    public function summary() : ?string
190
    {
191 2
        return $this->summary;
192
    }
193
194 2
    public function branch() : ?string
195
    {
196 2
        return $this->branch;
197
    }
198
199 2
    public function lastUpdate() : string
200
    {
201 2
        return $this->lastUpdate;
202
    }
203
204 2
    public function url() : ?string
205
    {
206 2
        return $this->url;
207
    }
208
209 2
    public function pullRquestStatus() : ?string
210
    {
211 2
        return $this->pullRequestStatus;
212
    }
213
214 2
    public function repository() : ?string
215
    {
216 2
        return $this->repository;
217
    }
218
219 2
    public function hasDirectory() : bool
220
    {
221 2
        return $this->hasDirectory;
222
    }
223
224 2
    public function directory() : ?string
225
    {
226 2
        return $this->directory;
227
    }
228
229 2
    public function pullRequestName() : ?string
230
    {
231 2
        return $this->pullRequestName;
232
    }
233
234 2
    public function isDone() : bool
235
    {
236 2
        return $this->isDone;
237
    }
238
239 3
    public function hasBranch() : bool
240
    {
241 3
        return $this->hasBranch;
242
    }
243
244 6
    public function setRepository(?string $repository) : void
245
    {
246 6
        $this->repository = $repository;
247 6
    }
248
249 7
    public function setIsDone(string $status) : void
250
    {
251 7
        $this->isDone = false;
252 7
        if (static::DONE_STATUS === $status) {
253 7
            $this->isDone = true;
254
        }
255 7
    }
256
257 6
    public function setHasBranch(?string $branch) : void
258
    {
259 6
        $this->hasBranch = true;
260 6
        if (null === $branch) {
261 1
            $this->hasBranch = false;
262
        }
263 6
    }
264
265
    /**
266
     * @throws NullArgumentException
267
     */
268 10
    private function setId(?int $id) : void
269
    {
270 10
        if (null === $id) {
271 1
            throw new NullArgumentException('Ticket ID property cannot be null');
272
        }
273 9
        $this->id = $id;
274 9
    }
275
276
    /**
277
     * @throws NullArgumentException
278
     */
279 9
    private function setKey(?string $key) : void
280
    {
281 9
        if (null === $key) {
282 1
            throw new NullArgumentException('Ticket key cannot be null');
283
        }
284 8
        $this->key = $key;
285 8
    }
286
287 8
    private function setAssigneeName(?string $assigneeName) : void
288
    {
289 8
        $this->assigneeName = $assigneeName;
290 8
    }
291
292 8
    private function setAssigneeDisplayName(?string $assigneeDisplayName) : void
293
    {
294 8
        $this->assigneeDisplayName = $assigneeDisplayName;
295 8
    }
296
297 8
    private function setAssigneeEmail(?string $assigneeEmail) : void
298
    {
299 8
        $this->assigneeEmail = $assigneeEmail;
300 8
    }
301
302 8
    private function setIsAssigneeActive(?bool $isAssigneeActive) : void
303
    {
304 8
        $this->isAssigneeActive = $isAssigneeActive;
305 8
    }
306
307
    /**
308
     * @throws NullArgumentException
309
     */
310 8
    private function setTicketStatus(?string $ticketStatus) : void
311
    {
312 8
        if (null === $ticketStatus) {
313 1
            throw new NullArgumentException('Ticket status cannot be null');
314
        }
315 7
        $this->ticketStatus = JiraTicketStatus::createFromString($ticketStatus)->status();
316 7
    }
317
318 7
    private function setTicketStatusCategory(?string $ticketStatusCategory) : void
319
    {
320 7
        $this->ticketStatusCategory = $ticketStatusCategory;
321 7
    }
322
323 7
    private function setComponents(?string $components) : void
324
    {
325 7
        $this->components = $components;
326 7
    }
327
328 7
    private function setType(?string $type) : void
329
    {
330 7
        $this->type = $type;
331 7
    }
332
333
    /**
334
     * @throws NullArgumentException
335
     */
336 7
    private function setProject(?string $project) : void
337
    {
338 7
        if (null === $project) {
339 1
            throw new NullArgumentException('Ticket project cannot be null');
340
        }
341 6
        $this->project = $project;
342 6
    }
343
344 6
    private function setFixVersion(?string $fixVersion) : void
345
    {
346 6
        $this->fixVersion = $fixVersion;
347 6
    }
348
349 6
    private function setSummary(?string $summary) : void
350
    {
351 6
        $this->summary = $summary;
352 6
    }
353
354 6
    private function setBranch(?string $branch) : void
355
    {
356 6
        $this->branch = $branch;
357 6
    }
358
359 6
    private function setLastUpdate(?string $lastUpdate) : void
360
    {
361 6
        $this->lastUpdate = $lastUpdate;
362 6
    }
363
364 6
    private function setUrl(?string $url) : void
365
    {
366 6
        $this->url = $url;
367 6
    }
368
369 6
    private function setPullRequestStatus(?string $pullRequestStatus) : void
370
    {
371 6
        $this->pullRequestStatus = $pullRequestStatus;
372 6
    }
373
374 6
    private function setHasDirectory(?bool $hasDirectory) : void
375
    {
376 6
        if (null === $hasDirectory) {
377 1
            throw new NullArgumentException('Ticket "hasDirectory" cannot be null');
378
        }
379 5
        $this->hasDirectory = $hasDirectory;
380 5
    }
381
382 5
    private function setDirectory(?string $directory) : void
383
    {
384 5
        $this->directory = $directory;
385 5
    }
386
387 6
    private function setPullRequestName(?string $pullRequestName) : void
388
    {
389 6
        $this->pullRequestName = $pullRequestName;
390 6
    }
391
}
392