Passed
Push — master ( 2504bd...9919f9 )
by Anton
04:30
created

AbstractCommand::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/bluzman
5
 */
6
7
namespace Bluzman\Command;
8
9
use Bluzman\Application\Application;
10
use Symfony\Component\Console;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Filesystem\Filesystem;
14
15
/**
16
 * Class AbstractCommand
17
 * @package Bluzman\Command
18
 *
19
 * @method Application getApplication()
20
 *
21
 * @author Pavel Machekhin
22
 * @created 2013-11-28 15:47
23
 */
24
abstract class AbstractCommand extends Console\Command\Command
25
{
26
    /**
27
     * @var InputInterface
28
     */
29
    protected $input;
30
31
    /**
32
     * @var OutputInterface
33
     */
34
    protected $output;
35
36
    /**
37
     * @var Filesystem
38
     */
39
    protected $fs;
40
41
    /**
42
     * @param InputInterface $input
43
     */
44 10
    public function setInput(InputInterface $input)
45
    {
46 10
        $this->input = $input;
47 10
    }
48
49
    /**
50
     * @return InputInterface
51
     */
52
    public function getInput()
53
    {
54
        return $this->input;
55
    }
56
57
    /**
58
     * @param OutputInterface $output
59
     */
60 10
    public function setOutput(OutputInterface $output)
61
    {
62 10
        $this->output = $output;
63 10
    }
64
65
    /**
66
     * @return OutputInterface
67
     */
68 10
    public function getOutput()
69
    {
70 10
        return $this->output;
71
    }
72
73
    /**
74
     * @param \Symfony\Component\Filesystem\Filesystem $fs
75
     */
76
    public function setFs($fs)
77
    {
78
        $this->fs = $fs;
79
    }
80
81
    /**
82
     * @return \Symfony\Component\Filesystem\Filesystem
83
     */
84 6
    public function getFs()
85
    {
86 6
        if (!$this->fs) {
87 6
            $this->fs = new Filesystem();
88
        }
89 6
        return $this->fs;
90
    }
91
92
    /**
93
     * @param  InputInterface $input
94
     * @param  OutputInterface $output
95
     * @return void
96
     */
97 10
    final public function initialize(InputInterface $input, OutputInterface $output)
98
    {
99 10
        parent::initialize($input, $output);
100
101 10
        $this->setInput($input);
102 10
        $this->setOutput($output);
103
104 10
        putenv('BLUZ_ENV=' . $input->getOption('env'));
105 10
    }
106
107
    /**
108
     * @param $message
109
     * @return void
110
     */
111 10
    public function write($message)
112
    {
113 10
        $this->getOutput()->writeln($message);
114 10
    }
115
116
    /**
117
     * @param $message
118
     * @return void
119
     */
120
    public function info($message)
121
    {
122
        $this->write("<info>$message</info>");
123
    }
124
125
    /**
126
     * @param $message
127
     * @return void
128
     */
129
    public function comment($message)
130
    {
131
        $this->write("<comment>$message</comment>");
132
    }
133
134
    /**
135
     * @param $message
136
     * @return void
137
     */
138
    public function question($message)
139
    {
140
        $this->write("<question>$message</question>:");
141
    }
142
143
    /**
144
     * @param $message
145
     * @return void
146
     */
147 4
    public function error($message)
148
    {
149 4
        $this->write("<error>$message</error>");
150 4
    }
151
152
    /**
153
     * @internal param $output
154
     */
155
    public function callForContribute()
156
    {
157
        $this->info(
158
            ' This command is not implemented yet. Don\'t be indifferent - you can contribute!' .
159
            ' https://github.com/bluzphp/bluzman. '
160
        );
161
    }
162
}
163