Stop::getCommand()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

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