Update   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 2
dl 31
loc 31
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 7 7 1
A getCommand() 14 14 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of RoboSystemPackage.
4
 *
5
 * @author      Aitor García Martínez (Falc) <[email protected]>
6
 * @copyright   2015 Aitor García Martínez (Falc) <[email protected]>
7
 * @license     MIT
8
 */
9
10
namespace Falc\Robo\Package;
11
12
use Robo\Contract\CommandInterface;
13
14
/**
15
 * Package Update
16
 *
17
 * ``` php
18
 * // Updating a single package:
19
 * $this->taskPackageUpdate()
20
 *     ->packageManager('yum')
21
 *     ->package('package1')
22
 *     ->run();
23
 *
24
 * // Updating many packages:
25
 * $this->taskPackageUpdate()
26
 *     ->packageManager('yum')
27
 *     ->packages(['package1', 'package2'])
28
 *     ->run();
29
 *
30
 * // Compact form:
31
 * $this->taskPackageUpdate('yum', ['package1', 'package2'])->run();
32
 *
33
 * // It allows to specify packages conditionally:
34
 * $update = $this->taskPackageUpdate('yum', ['package1']);
35
 *
36
 * if ($requiresPackage2) {
37
 *     $update->package('package2');
38
 * }
39
 *
40
 * $update->run();
41
 *
42
 * // It is possible to specify a pattern:
43
 * $this->taskPackageUpdate()
44
 *     ->packageManager('yum')
45
 *     ->package('package1-*') // Updates all packages starting with "package1-"
46
 *     ->run();
47
 * ```
48
 */
49 View Code Duplication
class Update extends BaseTask implements CommandInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
{
51
    /**
52
     * {@inheritdoc}
53
     */
54 8
    public function getCommand()
55
    {
56 8
        if ($this->builder === null) {
57 1
            throw new \Exception('Package manager not defined');
58
        }
59
60 7
        $this->builder->update($this->packages)->assumeYes();
61
62 7
        if (!$this->verbose) {
63 6
            $this->builder->quiet();
64
        }
65
66 7
        return $this->builder->getCommand();
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1
    public function run()
73
    {
74 1
        $command = $this->getCommand();
75
76 1
        $this->printTaskInfo('Updating packages...');
77 1
        return $this->executeCommand($command);
78
    }
79
}
80