Install::getCommand()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 14
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
crap 3
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 Install
16
 *
17
 * ``` php
18
 * // Installing a single package:
19
 * $this->taskPackageInstall()
20
 *     ->packageManager('yum')
21
 *     ->package('package1')
22
 *     ->run();
23
 *
24
 * // Installing many packages:
25
 * $this->taskPackageInstall()
26
 *     ->packageManager('yum')
27
 *     ->packages(['package1', 'package2'])
28
 *     ->run();
29
 *
30
 * // Compact form:
31
 * $this->taskPackageInstall('yum', ['package1', 'package2'])->run();
32
 *
33
 * // It allows to specify packages conditionally:
34
 * $install = $this->taskPackageInstall('yum', ['package1']);
35
 *
36
 * if ($requiresPackage2) {
37
 *     $install->package('package2');
38
 * }
39
 *
40
 * $install->run();
41
 *
42
 * // It is possible to specify a pattern:
43
 * $this->taskPackageInstall()
44
 *     ->packageManager('yum')
45
 *     ->package('package1-*') // Installs all packages starting with "package1-"
46
 *     ->run();
47
 * ```
48
 */
49 View Code Duplication
class Install 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->install($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('Installing packages...');
77 1
        return $this->executeCommand($command);
78
    }
79
}
80