AbstractCommand::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Assimtech\Tempo\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Assimtech\Tempo\Environment;
7
8
abstract class AbstractCommand extends Command
9
{
10
    /**
11
     * @var \Assimtech\Tempo\Environment $env
12
     */
13
    protected $env;
14
15
    /**
16
     * {@inheritdoc}
17
     *
18
     * @param \Assimtech\Tempo\Environment $env
19
     *
20
     * The environment name will be prefixed to the command name, e.g.
21
     *
22
     *      new MyCommand(
23
     *          new \Assimtech\Tempo\Environment('staging'),
24
     *          'deploy'
25
     *      );
26
     *
27
     * would result in a command:
28
     *
29
     *      tempo staging:deploy
30
     *
31
     * if $name is ommited, it will default to the class name of the command, e.g.
32
     *
33
     *      new MyCommand(
34
     *          new \Assimtech\Tempo\Environment('staging')
35
     *      );
36
     *
37
     * would result in a command:
38
     *
39
     *      tempo staging:mycommand
40
     *
41
     */
42 3
    public function __construct(Environment $env, $name = null)
43
    {
44 3
        $this->env = $env;
45
46 3
        if ($name === null) {
47 2
            $components = explode('\\', get_called_class());
48 2
            $class = array_pop($components);
49 2
            $name = strtolower($class);
50 2
        }
51
52 3
        parent::__construct(sprintf('%s:%s', $env, $name));
53 3
    }
54
}
55