Total Complexity | 54 |
Total Lines | 480 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like IssueField 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.
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 IssueField, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class IssueField implements \JsonSerializable |
||
8 | { |
||
9 | use ClassSerialize; |
||
10 | |||
11 | /** @var string */ |
||
12 | public $summary; |
||
13 | |||
14 | /** @var array */ |
||
15 | public $progress; |
||
16 | |||
17 | /** @var \JiraRestApi\Issue\TimeTracking */ |
||
18 | public $timeTracking; |
||
19 | |||
20 | /** @var \JiraRestApi\Issue\IssueType */ |
||
21 | public $issuetype; |
||
22 | |||
23 | /** @var Reporter|null */ |
||
24 | public $reporter; |
||
25 | |||
26 | /** @var \DateTimeInterface */ |
||
27 | public $created; |
||
28 | |||
29 | /** @var \DateTimeInterface */ |
||
30 | public $updated; |
||
31 | |||
32 | /** @var string|null */ |
||
33 | public $description; |
||
34 | |||
35 | /** @var \JiraRestApi\Issue\Priority|null */ |
||
36 | public $priority; |
||
37 | |||
38 | /** @var \JiraRestApi\Issue\IssueStatus */ |
||
39 | public $status; |
||
40 | |||
41 | /** @var array */ |
||
42 | public $labels; |
||
43 | |||
44 | /** @var \JiraRestApi\Project\Project */ |
||
45 | public $project; |
||
46 | |||
47 | /** @var string|null */ |
||
48 | public $environment; |
||
49 | |||
50 | /** @var \JiraRestApi\Issue\Component[] */ |
||
51 | public $components; |
||
52 | |||
53 | /** @var \JiraRestApi\Issue\Comments */ |
||
54 | public $comment; |
||
55 | |||
56 | /** @var object */ |
||
57 | public $votes; |
||
58 | |||
59 | /** @var object|null */ |
||
60 | public $resolution; |
||
61 | |||
62 | /** @var array */ |
||
63 | public $fixVersions; |
||
64 | |||
65 | /** @var \JiraRestApi\Issue\Reporter|null */ |
||
66 | public $creator; |
||
67 | |||
68 | /** @var object|null */ |
||
69 | public $watches; |
||
70 | |||
71 | /** @var object|null */ |
||
72 | public $worklog; |
||
73 | |||
74 | /** @var \JiraRestApi\Issue\Reporter|null */ |
||
75 | public $assignee; |
||
76 | |||
77 | /** @var \JiraRestApi\Issue\Version[] */ |
||
78 | public $versions; |
||
79 | |||
80 | /** @var \JiraRestApi\Issue\Attachment[] */ |
||
81 | public $attachment; |
||
82 | |||
83 | /** @var string|null */ |
||
84 | public $aggregatetimespent; |
||
85 | |||
86 | /** @var string|null */ |
||
87 | public $timeestimate; |
||
88 | |||
89 | /** @var string|null */ |
||
90 | public $aggregatetimeoriginalestimate; |
||
91 | |||
92 | /** @var string|null */ |
||
93 | public $resolutiondate; |
||
94 | |||
95 | /** @var \DateTimeInterface|null */ |
||
96 | public $duedate; |
||
97 | |||
98 | /** @var array */ |
||
99 | public $issuelinks; |
||
100 | |||
101 | /** @var \JiraRestApi\Issue\Issue[] */ |
||
102 | public $subtasks; |
||
103 | |||
104 | /** @var int */ |
||
105 | public $workratio; |
||
106 | |||
107 | /** @var object|null */ |
||
108 | public $aggregatetimeestimate; |
||
109 | |||
110 | /** @var object|null */ |
||
111 | public $aggregateprogress; |
||
112 | |||
113 | /** @var object|null */ |
||
114 | public $lastViewed; |
||
115 | |||
116 | /** @var object|null */ |
||
117 | public $timeoriginalestimate; |
||
118 | |||
119 | /** @var object|null */ |
||
120 | public $parent; |
||
121 | |||
122 | /** @var array|null */ |
||
123 | public $customFields; |
||
124 | |||
125 | /** @var \JiraRestApi\Issue\SecurityScheme|null */ |
||
126 | public $security; |
||
127 | |||
128 | public function __construct($updateIssue = false) |
||
138 | } |
||
139 | } |
||
140 | |||
141 | public function jsonSerialize() |
||
169 | } |
||
170 | |||
171 | public function getCustomFields() |
||
174 | } |
||
175 | |||
176 | public function addCustomField($key, $value) |
||
177 | { |
||
178 | $this->customFields[$key] = $value; |
||
179 | |||
180 | return $this; |
||
181 | } |
||
182 | |||
183 | public function getProjectKey() |
||
184 | { |
||
185 | return $this->project->key; |
||
186 | } |
||
187 | |||
188 | public function getProjectId() |
||
189 | { |
||
190 | return $this->project->id; |
||
191 | } |
||
192 | |||
193 | public function setProjectKey($key) |
||
194 | { |
||
195 | $this->project->key = $key; |
||
196 | |||
197 | return $this; |
||
198 | } |
||
199 | |||
200 | public function setProjectId($id) |
||
201 | { |
||
202 | $this->project->id = $id; |
||
203 | |||
204 | return $this; |
||
205 | } |
||
206 | |||
207 | public function setSummary($summary) |
||
208 | { |
||
209 | $this->summary = $summary; |
||
210 | |||
211 | return $this; |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * set issue reporter name. |
||
216 | * |
||
217 | * @param string $name |
||
218 | * |
||
219 | * @return $this |
||
220 | */ |
||
221 | public function setReporterName($name) |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * set issue assignee name. |
||
234 | * |
||
235 | * @param string $name |
||
236 | * |
||
237 | * @return $this |
||
238 | */ |
||
239 | public function setAssigneeName($name) |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * set issue assignee accountId. |
||
252 | * |
||
253 | * @param string $accountId |
||
254 | * |
||
255 | * @return $this |
||
256 | */ |
||
257 | public function setAssigneeAccountId($accountId) |
||
258 | { |
||
259 | if (is_null($this->assignee)) { |
||
260 | $this->assignee = new Reporter(); |
||
261 | } |
||
262 | |||
263 | $this->assignee->accountId = $accountId; |
||
264 | |||
265 | // REST API V3 must name field set to null. |
||
266 | $this->assignee->name = null; |
||
267 | $this->assignee->setWantUnassigned(true); |
||
268 | |||
269 | return $this; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * set issue priority name. |
||
274 | * |
||
275 | * @param string $name |
||
276 | * |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function setPriorityName($name) |
||
280 | { |
||
281 | if (is_null($this->priority)) { |
||
282 | $this->priority = new Priority(); |
||
283 | } |
||
284 | |||
285 | $this->priority->name = $name; |
||
286 | |||
287 | return $this; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * set issue description. |
||
292 | * |
||
293 | * REST API V3 must use addDescriptionXXXX |
||
294 | * |
||
295 | * @see \JiraRestApi\Issue\IssueFieldV3::addDescriptionHeading |
||
296 | * @see \JiraRestApi\Issue\IssueFieldV3::addDescriptionParagraph |
||
297 | * |
||
298 | * @param string|null $description |
||
299 | * |
||
300 | * @return $this |
||
301 | */ |
||
302 | public function setDescription($description) |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * add a Affects version. |
||
313 | * |
||
314 | * @param mixed string or array $name |
||
315 | * |
||
316 | * @return $this |
||
317 | */ |
||
318 | public function addVersion($name) |
||
319 | { |
||
320 | if (is_null($this->versions)) { |
||
|
|||
321 | $this->versions = []; |
||
322 | } |
||
323 | |||
324 | if (is_string($name)) { |
||
325 | array_push($this->versions, new Version($name)); |
||
326 | } elseif (is_array($name)) { |
||
327 | foreach ($name as $v) { |
||
328 | array_push($this->versions, new Version($v)); |
||
329 | } |
||
330 | } |
||
331 | |||
332 | return $this; |
||
333 | } |
||
334 | |||
335 | /** |
||
336 | * add issue label. |
||
337 | * |
||
338 | * @param string $label |
||
339 | * |
||
340 | * @return $this |
||
341 | */ |
||
342 | public function addLabel($label) |
||
343 | { |
||
344 | if (is_null($this->labels)) { |
||
345 | $this->labels = []; |
||
346 | } |
||
347 | |||
348 | array_push($this->labels, $label); |
||
349 | |||
350 | return $this; |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * set issue type. |
||
355 | * |
||
356 | * @param mixed IssueType or string $name |
||
357 | * |
||
358 | * @return $this |
||
359 | */ |
||
360 | public function setIssueType($name) |
||
361 | { |
||
362 | if (is_string($name)) { |
||
363 | if (is_null($this->issuetype)) { |
||
364 | $this->issuetype = new IssueType(); |
||
365 | } |
||
366 | |||
367 | $this->issuetype->name = $name; |
||
368 | } else { |
||
369 | $this->issuetype = $name; |
||
370 | } |
||
371 | |||
372 | return $this; |
||
373 | } |
||
374 | |||
375 | public function getIssueType() |
||
376 | { |
||
377 | return $this->issuetype; |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * set parent issue. |
||
382 | * |
||
383 | * @param string $keyOrId |
||
384 | */ |
||
385 | public function setParentKeyOrId($keyOrId) |
||
386 | { |
||
387 | if (is_numeric($keyOrId)) { |
||
388 | $this->parent['id'] = $keyOrId; |
||
389 | } elseif (is_string($keyOrId)) { |
||
390 | $this->parent['key'] = $keyOrId; |
||
391 | } |
||
392 | } |
||
393 | |||
394 | public function setParent(Issue $parent) |
||
395 | { |
||
396 | $this->parent = $parent; |
||
397 | } |
||
398 | |||
399 | /** |
||
400 | * add issue component. |
||
401 | * |
||
402 | * @param mixed string or array $component |
||
403 | * |
||
404 | * @return $this |
||
405 | */ |
||
406 | public function addComponents($component) |
||
407 | { |
||
408 | if (is_null($this->components)) { |
||
409 | $this->components = []; |
||
410 | } |
||
411 | |||
412 | if (is_string($component)) { |
||
413 | array_push($this->components, new Component($component)); |
||
414 | } elseif (is_array($component)) { |
||
415 | foreach ($component as $c) { |
||
416 | array_push($this->components, new Component($c)); |
||
417 | } |
||
418 | } |
||
419 | |||
420 | return $this; |
||
421 | } |
||
422 | |||
423 | /** |
||
424 | * set security level. |
||
425 | * |
||
426 | * @param int $id issue's security id |
||
427 | * |
||
428 | * @return $this |
||
429 | */ |
||
430 | public function setSecurityId($id) |
||
431 | { |
||
432 | if (empty($this->security)) { |
||
433 | $this->security = new SecurityScheme(); |
||
434 | } |
||
435 | |||
436 | $this->security->id = $id; |
||
437 | |||
438 | return $this; |
||
439 | } |
||
440 | |||
441 | /** |
||
442 | * set issue's due date. |
||
443 | * |
||
444 | * @param \DateTimeInterface|null $duedate due date string or DateTimeInterface object |
||
445 | * @param string $format datetime string format. |
||
446 | * |
||
447 | * @return $this |
||
448 | */ |
||
449 | public function setDueDate($duedate, $format = 'Y-m-d') |
||
450 | { |
||
451 | if (is_string($duedate)) { |
||
452 | $this->duedate = $duedate; |
||
453 | } elseif ($duedate instanceof \DateTimeInterface) { |
||
454 | $this->duedate = $duedate->format($format); |
||
455 | } else { |
||
456 | $this->duedate = null; |
||
457 | } |
||
458 | |||
459 | return $this; |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * set Assignee to Unassigned. |
||
464 | * |
||
465 | * @see https://confluence.atlassian.com/jirakb/how-to-set-assignee-to-unassigned-via-rest-api-in-jira-744721880.html |
||
466 | */ |
||
467 | public function setAssigneeToUnassigned() |
||
468 | { |
||
469 | if (is_null($this->assignee)) { |
||
470 | $this->assignee = new Reporter(); |
||
471 | } |
||
472 | |||
473 | $this->assignee->setWantUnassigned(true); |
||
474 | |||
475 | return $this; |
||
476 | } |
||
477 | |||
478 | public function setAssigneeToDefault() |
||
487 | } |
||
488 | } |
||
489 |