Total Complexity | 58 |
Total Lines | 502 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like GitTagTask 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 GitTagTask, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
35 | class GitTagTask extends GitBaseTask |
||
36 | { |
||
37 | /** |
||
38 | * Make unsigned, annotated tag object. See -a of git-tag |
||
39 | * |
||
40 | * @var boolean |
||
41 | */ |
||
42 | private $annotate = false; |
||
43 | |||
44 | /** |
||
45 | * Make GPG-signed tag. See -s of git-tag |
||
46 | * |
||
47 | * @var boolean |
||
48 | */ |
||
49 | private $sign = false; |
||
50 | |||
51 | /** |
||
52 | * Make GPG-signed tag, using given key. See -u of git-tag |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private $keySign; |
||
57 | |||
58 | /** |
||
59 | * Replace existing tag with given name. See -f of git-tag |
||
60 | * |
||
61 | * @var boolean |
||
62 | */ |
||
63 | private $replace = false; |
||
64 | |||
65 | /** |
||
66 | * Delete existing tags with given names. See -d of git-tag |
||
67 | * |
||
68 | * @var boolean |
||
69 | */ |
||
70 | private $delete = false; |
||
71 | |||
72 | /** |
||
73 | * Verify gpg signature of given tag names. See -v of git-tag |
||
74 | * |
||
75 | * @var boolean |
||
76 | */ |
||
77 | private $verify = false; |
||
78 | |||
79 | /** |
||
80 | * List tags with names matching given pattern. See -l of git-tag |
||
81 | * |
||
82 | * @var boolean |
||
83 | */ |
||
84 | private $list = false; |
||
85 | |||
86 | /** |
||
87 | * <num> specifies how many lines from the annotation, if any, are printed |
||
88 | * when using -l. See -n of git-tag |
||
89 | * |
||
90 | * @var int |
||
91 | */ |
||
92 | private $num; |
||
93 | |||
94 | /** |
||
95 | * Only list tags containing specified commit. See --contains of git-tag |
||
96 | * |
||
97 | * @var string |
||
98 | */ |
||
99 | private $contains; |
||
100 | |||
101 | /** |
||
102 | * Use given tag message. See -m of git-tag |
||
103 | * |
||
104 | * @var string |
||
105 | */ |
||
106 | private $message; |
||
107 | |||
108 | /** |
||
109 | * Take tag message from given file. See -F of git-tag |
||
110 | * |
||
111 | * @var string |
||
112 | */ |
||
113 | private $file; |
||
114 | |||
115 | /** |
||
116 | * <tagname> argument to git-tag |
||
117 | * |
||
118 | * @var string |
||
119 | */ |
||
120 | private $name; |
||
121 | |||
122 | /** |
||
123 | * <commit> argument to git-tag |
||
124 | * |
||
125 | * @var string |
||
126 | */ |
||
127 | private $commit; |
||
128 | |||
129 | /** |
||
130 | * <object> argument to git-tag |
||
131 | * |
||
132 | * @var string |
||
133 | */ |
||
134 | private $object; |
||
135 | |||
136 | /** |
||
137 | * <pattern> argument to git-tag |
||
138 | * |
||
139 | * @var string |
||
140 | */ |
||
141 | private $pattern; |
||
142 | |||
143 | /** |
||
144 | * Property name to set with output value from git-tag |
||
145 | * |
||
146 | * @var string |
||
147 | */ |
||
148 | private $outputProperty; |
||
149 | |||
150 | /** |
||
151 | * The main entry point for the task |
||
152 | */ |
||
153 | public function main() |
||
154 | { |
||
155 | if (null === $this->getRepository()) { |
||
|
|||
156 | throw new BuildException('"repository" is required parameter'); |
||
157 | } |
||
158 | |||
159 | $client = $this->getGitClient(false, $this->getRepository()); |
||
160 | $command = $client->getCommand('tag'); |
||
161 | $command |
||
162 | ->setOption('a', $this->isAnnotate()) |
||
163 | ->setOption('s', $this->isSign()) |
||
164 | ->setOption('f', $this->isReplace()) |
||
165 | ->setOption('d', $this->isDelete()) |
||
166 | ->setOption('v', $this->isVerify()) |
||
167 | ->setOption('l', $this->isList()); |
||
168 | |||
169 | if (null !== $this->getKeySign()) { |
||
170 | $command->setOption('u', $this->getKeySign()); |
||
171 | } |
||
172 | |||
173 | if (null !== $this->getMessage()) { |
||
174 | $command->setOption('m', $this->getMessage()); |
||
175 | } |
||
176 | |||
177 | if (null !== $this->getFile()) { |
||
178 | $command->setOption('F', $this->getFile()); |
||
179 | } |
||
180 | |||
181 | // Use 'name' arg, if relevant |
||
182 | if (null != $this->getName() && false == $this->isList()) { |
||
183 | $command->addArgument($this->getName()); |
||
184 | } |
||
185 | |||
186 | if (null !== $this->getKeySign() || $this->isAnnotate() || $this->isSign()) { |
||
187 | // Require a tag message or file |
||
188 | if (null === $this->getMessage() && null === $this->getFile()) { |
||
189 | throw new BuildException('"message" or "file" required to make a tag'); |
||
190 | } |
||
191 | } |
||
192 | |||
193 | // Use 'commit' or 'object' args, if relevant |
||
194 | if (null !== $this->getCommit()) { |
||
195 | $command->addArgument($this->getCommit()); |
||
196 | } else { |
||
197 | if (null !== $this->getObject()) { |
||
198 | $command->addArgument($this->getObject()); |
||
199 | } |
||
200 | } |
||
201 | |||
202 | // Customize list (-l) options |
||
203 | if ($this->isList()) { |
||
204 | if (null !== $this->getContains()) { |
||
205 | $command->setOption('contains', $this->getContains()); |
||
206 | } |
||
207 | if (null !== $this->getPattern()) { |
||
208 | $command->addArgument($this->getPattern()); |
||
209 | } |
||
210 | if (null != $this->getNum()) { |
||
211 | $command->setOption('n', $this->getNum()); |
||
212 | } |
||
213 | } |
||
214 | |||
215 | $this->log('git-tag command: ' . $command->createCommandString(), Project::MSG_INFO); |
||
216 | |||
217 | try { |
||
218 | $output = $command->execute(); |
||
219 | } catch (\Exception $e) { |
||
220 | $this->log($e->getMessage(), Project::MSG_ERR); |
||
221 | throw new BuildException('Task execution failed. ' . $e->getMessage()); |
||
222 | } |
||
223 | |||
224 | if (null !== $this->outputProperty) { |
||
225 | $this->project->setProperty($this->outputProperty, trim($output)); |
||
226 | } |
||
227 | |||
228 | $this->log( |
||
229 | sprintf('git-tag: tags for "%s" repository', $this->getRepository()), |
||
230 | Project::MSG_INFO |
||
231 | ); |
||
232 | $this->log('git-tag output: ' . trim($output), Project::MSG_INFO); |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @param $flag |
||
237 | */ |
||
238 | public function setAnnotate(bool $flag) |
||
239 | { |
||
240 | $this->annotate = $flag; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * @return bool |
||
245 | */ |
||
246 | public function getAnnotate() |
||
247 | { |
||
248 | return $this->annotate; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @return bool |
||
253 | */ |
||
254 | public function isAnnotate() |
||
255 | { |
||
256 | return $this->getAnnotate(); |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @param $flag |
||
261 | */ |
||
262 | public function setSign(bool $flag) |
||
263 | { |
||
264 | $this->sign = $flag; |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * @return bool |
||
269 | */ |
||
270 | public function getSign() |
||
271 | { |
||
272 | return $this->sign; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * @return bool |
||
277 | */ |
||
278 | public function isSign() |
||
279 | { |
||
280 | return $this->getSign(); |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @param $keyId |
||
285 | */ |
||
286 | public function setKeySign($keyId) |
||
287 | { |
||
288 | $this->keySign = $keyId; |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * @return string |
||
293 | */ |
||
294 | public function getKeySign() |
||
295 | { |
||
296 | return $this->keySign; |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * @param $flag |
||
301 | */ |
||
302 | public function setReplace(bool $flag) |
||
303 | { |
||
304 | $this->replace = $flag; |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * @return bool |
||
309 | */ |
||
310 | public function getReplace() |
||
311 | { |
||
312 | return $this->replace; |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * @return bool |
||
317 | */ |
||
318 | public function isReplace() |
||
319 | { |
||
320 | return $this->getReplace(); |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * @param $flag |
||
325 | */ |
||
326 | public function setForce(bool $flag) |
||
327 | { |
||
328 | return $this->setReplace($flag); |
||
329 | } |
||
330 | |||
331 | /** |
||
332 | * @param $flag |
||
333 | */ |
||
334 | public function setDelete(bool $flag) |
||
335 | { |
||
336 | $this->delete = $flag; |
||
337 | } |
||
338 | |||
339 | /** |
||
340 | * @return bool |
||
341 | */ |
||
342 | public function getDelete() |
||
343 | { |
||
344 | return $this->delete; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * @return bool |
||
349 | */ |
||
350 | public function isDelete() |
||
351 | { |
||
352 | return $this->getDelete(); |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * @param $flag |
||
357 | */ |
||
358 | public function setVerify(bool $flag) |
||
359 | { |
||
360 | $this->verify = $flag; |
||
361 | } |
||
362 | |||
363 | /** |
||
364 | * @return bool |
||
365 | */ |
||
366 | public function getVerify() |
||
367 | { |
||
368 | return $this->verify; |
||
369 | } |
||
370 | |||
371 | /** |
||
372 | * @return bool |
||
373 | */ |
||
374 | public function isVerify() |
||
375 | { |
||
376 | return $this->getVerify(); |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * @param $flag |
||
381 | */ |
||
382 | public function setList(bool $flag) |
||
383 | { |
||
384 | $this->list = $flag; |
||
385 | } |
||
386 | |||
387 | /** |
||
388 | * @return bool |
||
389 | */ |
||
390 | public function getList() |
||
391 | { |
||
392 | return $this->list; |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * @return bool |
||
397 | */ |
||
398 | public function isList() |
||
399 | { |
||
400 | return $this->getList(); |
||
401 | } |
||
402 | |||
403 | /** |
||
404 | * @param $num |
||
405 | */ |
||
406 | public function setNum($num) |
||
407 | { |
||
408 | $this->num = (int) $num; |
||
409 | } |
||
410 | |||
411 | /** |
||
412 | * @return int |
||
413 | */ |
||
414 | public function getNum() |
||
415 | { |
||
416 | return $this->num; |
||
417 | } |
||
418 | |||
419 | /** |
||
420 | * @param $commit |
||
421 | */ |
||
422 | public function setContains($commit) |
||
423 | { |
||
424 | $this->contains = $commit; |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * @return string |
||
429 | */ |
||
430 | public function getContains() |
||
431 | { |
||
432 | return $this->contains; |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * @param $msg |
||
437 | */ |
||
438 | public function setMessage($msg) |
||
439 | { |
||
440 | $this->message = $msg; |
||
441 | } |
||
442 | |||
443 | /** |
||
444 | * @return string |
||
445 | */ |
||
446 | public function getMessage() |
||
447 | { |
||
448 | return $this->message; |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * @param $file |
||
453 | */ |
||
454 | public function setFile($file) |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * @return string |
||
461 | */ |
||
462 | public function getFile() |
||
463 | { |
||
464 | return $this->file; |
||
465 | } |
||
466 | |||
467 | /** |
||
468 | * @param $name |
||
469 | */ |
||
470 | public function setName($name) |
||
473 | } |
||
474 | |||
475 | /** |
||
476 | * @return string |
||
477 | */ |
||
478 | public function getName() |
||
479 | { |
||
480 | return $this->name; |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * @param $commit |
||
485 | */ |
||
486 | public function setCommit($commit) |
||
489 | } |
||
490 | |||
491 | /** |
||
492 | * @return string |
||
493 | */ |
||
494 | public function getCommit() |
||
495 | { |
||
496 | return $this->commit; |
||
497 | } |
||
498 | |||
499 | /** |
||
500 | * @param $object |
||
501 | */ |
||
502 | public function setObject($object) |
||
503 | { |
||
504 | $this->object = $object; |
||
505 | } |
||
506 | |||
507 | /** |
||
508 | * @return string |
||
509 | */ |
||
510 | public function getObject() |
||
511 | { |
||
512 | return $this->object; |
||
513 | } |
||
514 | |||
515 | /** |
||
516 | * @param $pattern |
||
517 | */ |
||
518 | public function setPattern($pattern) |
||
519 | { |
||
520 | $this->pattern = $pattern; |
||
521 | } |
||
522 | |||
523 | /** |
||
524 | * @return string |
||
525 | */ |
||
526 | public function getPattern() |
||
529 | } |
||
530 | |||
531 | /** |
||
532 | * @param $prop |
||
533 | */ |
||
534 | public function setOutputProperty($prop) |
||
537 | } |
||
538 | } |
||
539 |