Completed
Pull Request — master (#1)
by
unknown
05:54
created

DaemonReload::getCommand()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
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      Polyvaniy Oleksii (alexndlm) <[email protected]>
6
 * @copyright   2015 Polyvaniy Oleksii (alexndlm) <[email protected]>
7
 * @license     MIT
8
 */
9
10
namespace Falc\Robo\Service;
11
12
use Falc\Robo\Service\Factory\CommandBuilderFactoryInterface;
13
use Robo\Contract\CommandInterface;
14
15
/**
16
 * Reload systemd manager configuration
17
 *
18
 * ``` php
19
 * // Enabling a service:
20
 * $this->taskServiceDaemonReload()
21
 *     ->serviceManager('systemd')
22
 *     ->run();
23
 *
24
 * // Compact form:
25
 * $this->taskServiceDaemonReload('systemd')->run();
26
 * ```
27
 */
28
class DaemonReload extends BaseTask implements CommandInterface
29
{
30
    /**
31
     * Constructor.
32
     *
33
     * @param   string                          $serviceManager Service manager to use. Optional.
34
     * @param   CommandBuilderFactoryInterface  $factory        CommandBuilder factory. Optional.
35
     */
36 6
    public function __construct($serviceManager = null, CommandBuilderFactoryInterface $factory = null)
37
    {
38 6
        parent::__construct($serviceManager, null, $factory);
39 6
    }
40
41
    /**
42
     * {@inheritdoc}
43
     * @throws \InvalidArgumentException
44
     */
45 6
    public function getCommand()
46
    {
47 6
        if ($this->builder === null) {
48 1
            throw new \InvalidArgumentException('Service manager not defined');
49
        }
50
51 5
        $this->builder->daemonReload();
52
53 5
        if (!$this->verbose) {
54 4
            $this->builder->quiet();
55 4
        }
56
57 5
        return $this->builder->getCommand();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     * @throws \InvalidArgumentException
63
     */
64 1
    public function run()
65
    {
66 1
        $command = $this->getCommand();
67
68 1
        $this->printTaskInfo('Reload systemd, scanning for new or changed units...');
69 1
        return $this->executeCommand($command);
70
    }
71
}
72