Issues (108)

src/Command/AbstractCommand.php (11 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * @copyright Bluz PHP Team
5
 * @link https://github.com/bluzphp/bluzman
6
 */
7
8
namespace Bluzman\Command;
9
10
use Bluz\Config\ConfigException;
0 ignored issues
show
The type Bluz\Config\ConfigException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Bluz\Proxy\Config;
0 ignored issues
show
The type Bluz\Proxy\Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Bluz\Validator\Validator;
0 ignored issues
show
The type Bluz\Validator\Validator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Bluzman\Application\Application;
14
use Bluzman\Input\InputArgument;
15
use Bluzman\Input\InputException;
16
use Symfony\Component\Console;
0 ignored issues
show
The type Symfony\Component\Console was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Symfony\Component\Filesystem\Filesystem;
0 ignored issues
show
The type Symfony\Component\Filesystem\Filesystem was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
21
/**
22
 * Class AbstractCommand
23
 * @package Bluzman\Command
24
 *
25
 * @method Application getApplication()
26
 *
27
 * @author Pavel Machekhin
28
 * @created 2013-11-28 15:47
29
 */
30
abstract class AbstractCommand extends Console\Command\Command
0 ignored issues
show
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
{
32
    /**
33
     * @var InputInterface
34
     */
35
    protected $input;
36
37
    /**
38
     * @var OutputInterface
39
     */
40
    protected $output;
41
42
    /**
43
     * @var Filesystem
44
     */
45
    protected $fs;
46
47
    /**
48 11
     * @param InputInterface $input
49
     */
50 11
    public function setInput(InputInterface $input): void
51 11
    {
52
        $this->input = $input;
53
    }
54
55
    /**
56 11
     * @return InputInterface
57
     */
58 11
    public function getInput(): InputInterface
59
    {
60
        return $this->input;
61
    }
62
63
    /**
64 11
     * @param OutputInterface $output
65
     */
66 11
    public function setOutput(OutputInterface $output): void
67 11
    {
68
        $this->output = $output;
69
    }
70
71
    /**
72 11
     * @return OutputInterface
73
     */
74 11
    public function getOutput()
75
    {
76
        return $this->output;
77
    }
78
79
    /**
80
     * @param Filesystem $fs
81
     */
82
    public function setFs(Filesystem $fs): void
83
    {
84
        $this->fs = $fs;
85
    }
86
87
    /**
88 7
     * @return Filesystem
89
     */
90 7
    public function getFs(): Filesystem
91 7
    {
92
        if (!$this->fs) {
93 7
            $this->fs = new Filesystem();
94
        }
95
        return $this->fs;
96
    }
97
98
    /**
99
     * @param  InputInterface  $input
100
     * @param  OutputInterface $output
101
     *
102
     * @return void
103 11
     * @throws ConfigException
104
     */
105 11
    final public function initialize(InputInterface $input, OutputInterface $output)
106
    {
107 11
        parent::initialize($input, $output);
108 11
109
        $this->setInput($input);
110 11
        $this->setOutput($output);
111
112 11
        putenv('BLUZ_ENV=' . ($input->getOption('env') ?: getenv('BLUZ_ENV')));
113 11
114 11
        $loader = new \Bluz\Config\ConfigLoader();
0 ignored issues
show
The type Bluz\Config\ConfigLoader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
115 11
        $loader->setPath(PATH_APPLICATION);
0 ignored issues
show
The constant Bluzman\Command\PATH_APPLICATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
116
        $loader->setEnvironment($input->getOption('env'));
117 11
        $loader->load();
118 11
119
        $config = new \Bluz\Config\Config();
0 ignored issues
show
The type Bluz\Config\Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
120 11
        $config->setFromArray($loader->getConfig());
121 11
122
        Config::setInstance($config);
123
    }
124
125
    /**
126
     * @param $message
127 11
     * @return void
128
     */
129 11
    public function write($message): void
130 11
    {
131
        $this->getOutput()->writeln($message);
132
    }
133
134
    /**
135
     * @param $message
136
     * @return void
137
     */
138
    public function info($message): void
139
    {
140
        $this->write("<info>$message</info>");
141
    }
142
143
    /**
144
     * @param $message
145
     * @return void
146
     */
147
    public function comment($message): void
148
    {
149
        $this->write("<comment>$message</comment>");
150
    }
151
152
    /**
153
     * @param $message
154
     * @return void
155
     */
156
    public function question($message): void
157
    {
158
        $this->write("<question>$message</question>:");
159
    }
160
161
    /**
162
     * @param $message
163 5
     * @return void
164
     */
165 5
    public function error($message): void
166 5
    {
167
        $this->write("<error>$message</error>");
168
    }
169
170
    /**
171
     * @internal param $output
172
     */
173
    public function callForContribute()
174
    {
175
        $this->info(
176
            ' This command is not implemented yet. Don\'t be indifferent - you can contribute!' .
177
            ' https://github.com/bluzphp/bluzman. '
178
        );
179
    }
180
181
    /**
182
     * Add Module Argument
183
     *
184
     * @param int $required
185 15
     * @return void
186
     */
187 15
    protected function addModuleArgument($required = InputArgument::REQUIRED): void
188 15
    {
189 15
        $module = new InputArgument('module', $required, 'Module name is required');
190
        $this->getDefinition()->addArgument($module);
191
    }
192
193
    /**
194
     * Validate Module Argument
195
     *
196
     * @return void
197 6
     * @throws InputException
198
     */
199 6
    protected function validateModuleArgument(): void
200
    {
201 6
        $module = $this->getInput()->getArgument('module');
202 6
203 6
        $validator = Validator::create()
204 6
            ->string()
205
            ->alphaNumeric('-_')
206 6
            ->noWhitespace();
207 6
208 1
        if (
209
            $this->getDefinition()->getArgument('module')->isRequired()
210 5
            && !$validator->validate($module)
211
        ) {
212
            throw new InputException($validator->getError());
213
        }
214
    }
215
216
    /**
217
     * Add Controller Argument
218 15
     *
219
     * @param int $required
220 15
     * @return void
221 15
     */
222 15
    protected function addControllerArgument($required = InputArgument::REQUIRED): void
223
    {
224
        $controller = new InputArgument('controller', $required, 'Controller name is required');
225
        $this->getDefinition()->addArgument($controller);
226
    }
227
228
    /**
229
     * Validate Module Argument
230 1
     *
231
     * @return void
232 1
     * @throws InputException
233
     */
234 1
    protected function validateControllerArgument(): void
235 1
    {
236 1
        $controller = $this->getInput()->getArgument('controller');
237 1
238
        $validator = Validator::create()
239 1
            ->string()
240 1
            ->alphaNumeric('-_')
241
            ->noWhitespace();
242
243 1
        if (
244
            $this->getDefinition()->getArgument('controller')->isRequired()
245
            && !$validator->validate($controller)
246
        ) {
247
            throw new InputException($validator->getError());
248
        }
249
    }
250
}
251