Command::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SyncFS\Command;
4
5
use Symfony\Component\Console\Command\Command as BaseCommand;
6
use Symfony\Component\Console\Input\ArrayInput;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class Command
12
 *
13
 * @package SyncFS\Command
14
 * @author  Matej Velikonja <[email protected]>
15
 */
16
class Command extends BaseCommand
17
{
18
    const ARG_CONFIG_PATH = 'config-path';
19
20
    /**
21
     * @var string
22
     */
23
    private $defaultConfigPath;
24
25
    /**
26
     * @var InputInterface
27
     */
28
    protected $input;
29
30
    /**
31
     * @var OutputInterface
32
     */
33
    protected $output;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param string|null $name The name of the command; passing null means it must be set in configure()
39
     *
40
     * @throws \LogicException When the command name is empty
41
     */
42 6
    public function __construct($name = null)
43
    {
44 6
        $this->defaultConfigPath = getenv("HOME") . '/.syncfs.yml';
45
46 6
        parent::__construct($name);
47 6
    }
48
49
    /**
50
     * @return string
51
     */
52 6
    protected function getDefaultConfiguration()
53
    {
54 6
        return $this->defaultConfigPath;
55
    }
56
57
    /**
58
     * @param string $name
59
     * @param array  $args
60
     *
61
     * @return int
62
     * @throws \LogicException
63
     */
64 1
    protected function runCommand($name, array $args)
65
    {
66 1
        if (! $this->output) {
67
            throw new \LogicException('Output is needed for running other command. Sent it via class property.');
68
        }
69
70
        $defaults = array(
71 1
            'command' => $name,
72 1
        );
73
74 1
        $mergedArgs = array_merge($defaults, $args);
75
76 1
        $command = $this->getApplication()->find($name);
77 1
        $input   = new ArrayInput($mergedArgs);
78
79 1
        return $command->run($input, $this->output);
80
    }
81
}
82