Enable::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 6
Ratio 85.71 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
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 enable
20
 *
21
 * ``` php
22
 * // Enabling a service:
23
 * $this->taskServiceEnable()
24
 *     ->serviceManager('systemd')
25
 *     ->service('httpd')
26
 *     ->run();
27
 *
28
 * // Compact form:
29
 * $this->taskServiceEnable('systemd', 'httpd')->run();
30
 * ```
31
 */
32 View Code Duplication
class Enable 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->enable($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('Enabling service...');
64 1
        return $this->executeCommand($command);
65
    }
66
}
67