Completed
Push — master ( d89aaa...82225d )
by Andrés
48s
created

AbstractCommand::requireConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
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 44
    public function setRuntime(Runtime $runtime)
43
    {
44 44
        $this->runtime = $runtime;
45
46 44
        return $this;
47
    }
48
49
    /**
50
     * Logs a message
51
     *
52
     * @param string $message
53
     * @param string $level
54
     */
55 31
    public function log($message, $level = LogLevel::DEBUG)
56
    {
57 31
        $this->runtime->log($message, $level);
58 31
    }
59
60
    /**
61
     * Get the Human friendly Stage name
62
     *
63
     * @return string
64
     */
65 26
    protected function getStageName()
66
    {
67 26
        $utils = new Utils();
68 26
        return $utils->getStageName($this->runtime->getStage());
69
    }
70
71
    /**
72
     * Requires the configuration to be loaded
73
     */
74 38
    protected function requireConfig()
75
    {
76 38
        $app = $this->getApplication();
77 38
        if ($app instanceof MageApplication) {
78 38
            $app->configure();
79 38
        }
80 38
    }
81
}
82