GitTagTask   D
last analyzed

Complexity

Total Complexity 58

Size/Duplication

Total Lines 502
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 58
eloc 101
dl 0
loc 502
rs 4.5599
c 0
b 0
f 0

39 Methods

Rating   Name   Duplication   Size   Complexity  
A setFile() 0 3 1
A setName() 0 3 1
A setForce() 0 3 1
A getNum() 0 3 1
A isReplace() 0 3 1
A isList() 0 3 1
A isVerify() 0 3 1
A getAnnotate() 0 3 1
A setList() 0 3 1
A setCommit() 0 3 1
A getList() 0 3 1
A getPattern() 0 3 1
A getFile() 0 3 1
A isSign() 0 3 1
A setOutputProperty() 0 3 1
A getMessage() 0 3 1
A setReplace() 0 3 1
A setAnnotate() 0 3 1
A setContains() 0 3 1
F main() 0 80 20
A getVerify() 0 3 1
A getReplace() 0 3 1
A getName() 0 3 1
A getSign() 0 3 1
A setSign() 0 3 1
A setObject() 0 3 1
A setKeySign() 0 3 1
A setNum() 0 3 1
A getCommit() 0 3 1
A setMessage() 0 3 1
A setVerify() 0 3 1
A isDelete() 0 3 1
A setPattern() 0 3 1
A getKeySign() 0 3 1
A setDelete() 0 3 1
A getObject() 0 3 1
A getDelete() 0 3 1
A getContains() 0 3 1
A isAnnotate() 0 3 1

How to fix   Complexity   

Complex Class

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
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Task\Ext\Git;
22
23
use Phing\Exception\BuildException;
24
use Phing\Project;
25
26
/**
27
 * Wrapper around git-tag
28
 *
29
 * @author  Evan Kaufman <[email protected]>
30
 * @author  Victor Farazdagi <[email protected]>
31
 * @package phing.tasks.ext.git
32
 * @see     VersionControl_Git
33
 * @since   2.4.5
34
 */
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()) {
0 ignored issues
show
introduced by
The condition null === $this->getRepository() is always false.
Loading history...
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()) {
0 ignored issues
show
introduced by
The condition null !== $this->getKeySign() is always true.
Loading history...
170
            $command->setOption('u', $this->getKeySign());
171
        }
172
173
        if (null !== $this->getMessage()) {
0 ignored issues
show
introduced by
The condition null !== $this->getMessage() is always true.
Loading history...
174
            $command->setOption('m', $this->getMessage());
175
        }
176
177
        if (null !== $this->getFile()) {
0 ignored issues
show
introduced by
The condition null !== $this->getFile() is always true.
Loading history...
178
            $command->setOption('F', $this->getFile());
179
        }
180
181
        // Use 'name' arg, if relevant
182
        if (null != $this->getName() && false == $this->isList()) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
183
            $command->addArgument($this->getName());
184
        }
185
186
        if (null !== $this->getKeySign() || $this->isAnnotate() || $this->isSign()) {
0 ignored issues
show
introduced by
The condition null !== $this->getKeySign() is always true.
Loading history...
187
            // Require a tag message or file
188
            if (null === $this->getMessage() && null === $this->getFile()) {
0 ignored issues
show
introduced by
The condition null === $this->getMessage() is always false.
Loading history...
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()) {
0 ignored issues
show
introduced by
The condition null !== $this->getCommit() is always true.
Loading history...
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()) {
0 ignored issues
show
introduced by
The condition null !== $this->getContains() is always true.
Loading history...
205
                $command->setOption('contains', $this->getContains());
206
            }
207
            if (null !== $this->getPattern()) {
0 ignored issues
show
introduced by
The condition null !== $this->getPattern() is always true.
Loading history...
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);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->setReplace($flag) targeting Phing\Task\Ext\Git\GitTagTask::setReplace() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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)
455
    {
456
        $this->file = $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)
471
    {
472
        $this->name = $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)
487
    {
488
        $this->commit = $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()
527
    {
528
        return $this->pattern;
529
    }
530
531
    /**
532
     * @param $prop
533
     */
534
    public function setOutputProperty($prop)
535
    {
536
        $this->outputProperty = $prop;
537
    }
538
}
539