Disable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 94.29 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 33
loc 35
ccs 12
cts 12
cp 1
rs 10

2 Methods

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

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 RoboSystemService.
4
 *
5
 * @author      Aitor García Martínez (Falc) <[email protected]>
6
 * @copyright   2015 Aitor García Martínez (Falc) <[email protected]>
7
 *
8
 * @author      Polyvaniy Oleksii (alexndlm) <[email protected]>
9
 * @copyright   2016 Polyvaniy Oleksii (alexndlm) <[email protected]>
10
 *
11
 * @license     MIT
12
 */
13
14
namespace Falc\Robo\Service;
15
16
use Robo\Contract\CommandInterface;
17
18
/**
19
 * Service disable
20
 *
21
 * ``` php
22
 * // Enabling a service:
23
 * $this->taskServiceDisable()
24
 *     ->serviceManager('systemd')
25
 *     ->service('httpd')
26
 *     ->run();
27
 *
28
 * // Compact form:
29
 * $this->taskServiceDisable('systemd', 'httpd')->run();
30
 * ```
31
 */
32 View Code Duplication
class Disable extends BaseTask implements CommandInterface
33
{
34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @throws \InvalidArgumentException
38
     */
39 7
    public function getCommand()
40
    {
41 7
        if ($this->builder === null) {
42 1
            throw new \InvalidArgumentException('Service manager not defined');
43
        }
44
45 6
        $this->builder->disable($this->service);
46
47 6
        if (!$this->verbose) {
48 5
            $this->builder->quiet();
49 5
        }
50
51 6
        return $this->builder->getCommand();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     *
57
     * @throws \InvalidArgumentException
58
     */
59 1
    public function run()
60
    {
61 1
        $command = $this->getCommand();
62
63 1
        $this->printTaskInfo('Disabling service...');
64 1
        return $this->executeCommand($command);
65
    }
66
}
67