Test Failed
Pull Request — master (#448)
by
unknown
05:18
created

AbstractCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 58
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A requireConfig() 0 7 2
A setRuntime() 0 6 1
A log() 0 4 1
A getStageName() 0 5 1
1
<?php
2
/*
3
 * This file is part of the Magallanes package.
4
 *
5
 * (c) Andrés Montañez <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Mage\Command;
12
13
use Mage\MageApplication;
14
use Mage\Utils;
15
use Mage\Runtime\Runtime;
16
use Psr\Log\LogLevel;
17
use Symfony\Component\Console\Command\Command;
18
19
/**
20
 * Abstract base class for Magallanes Commands
21
 *
22
 * @author Andrés Montañez <[email protected]>
23
 */
24
abstract class AbstractCommand extends Command
25
{
26
    /**
27
     * @var int
28
     */
29
    protected $statusCode = 0;
30
31
    /**
32
     * @var Runtime Current Runtime instance
33
     */
34
    protected $runtime;
35
36
    /**
37
     * Set the Runtime configuration
38
     *
39
     * @param Runtime $runtime Runtime container
40
     * @return AbstractCommand
41
     */
42
    public function setRuntime(Runtime $runtime)
43
    {
44
        $this->runtime = $runtime;
45
46
        return $this;
47
    }
48
49
    /**
50
     * Logs a message
51
     *
52
     * @param string $message
53
     * @param string $level
54
     */
55
    public function log($message, $level = LogLevel::DEBUG)
56
    {
57
        $this->runtime->log($message, $level);
58
    }
59
60
    /**
61
     * Get the Human friendly Stage name
62
     *
63
     * @return string
64
     */
65
    protected function getStageName()
66
    {
67
        $utils = new Utils();
68
        return $utils->getStageName($this->runtime->getStage());
69
    }
70
71
    /**
72
     * Requires the configuration to be loaded
73
     */
74
    protected function requireConfig()
75
    {
76
        $app = $this->getApplication();
77
        if ($app instanceof MageApplication) {
78
            $app->configure();
79
        }
80
    }
81
}
82