Skip to content

Commit a03fdbc

Browse files
committed
update, code format for php7
1 parent f329357 commit a03fdbc

20 files changed

+122
-81
lines changed

src/Application.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Application extends AbstractApplication
2525
* @param string $name The controller name
2626
* @param string $class The controller class
2727
* @return static
28+
* @throws \InvalidArgumentException
2829
*/
2930
public function controller(string $name, string $class = null)
3031
{
@@ -78,6 +79,7 @@ public function controllers(array $controllers)
7879
* @param string|\Closure|Command $handler
7980
* @param null|string $description
8081
* @return $this
82+
* @throws \InvalidArgumentException
8183
*/
8284
public function command(string $name, $handler = null, $description = null)
8385
{
@@ -97,15 +99,15 @@ public function command(string $name, $handler = null, $description = null)
9799
throw new \InvalidArgumentException("Command '$name' have been registered!");
98100
}
99101

100-
if (is_string($handler)) {
102+
if (\is_string($handler)) {
101103
if (!class_exists($handler)) {
102104
throw new \InvalidArgumentException("The console command class [$handler] not exists!");
103105
}
104106

105107
if (!is_subclass_of($handler, Command::class)) {
106108
throw new \InvalidArgumentException('The console command class must is subclass of the: ' . Command::class);
107109
}
108-
} elseif (!is_object($handler) || !method_exists($handler, '__invoke')) {
110+
} elseif (!\is_object($handler) || !method_exists($handler, '__invoke')) {
109111
throw new \InvalidArgumentException(sprintf(
110112
'The console command handler must is an subclass of %s OR a Closure OR a object have method __invoke()',
111113
Command::class
@@ -135,6 +137,7 @@ public function commands(array $commands)
135137
* @param string $name
136138
* @param mixed $handler
137139
* @return $this
140+
* @throws \InvalidArgumentException
138141
*/
139142
public function addCommand(string $name, $handler = null)
140143
{
@@ -146,6 +149,7 @@ public function addCommand(string $name, $handler = null)
146149
* @param string $name
147150
* @param string|null $controller
148151
* @return static
152+
* @throws \InvalidArgumentException
149153
*/
150154
public function addGroup(string $name, string $controller = null)
151155
{
@@ -158,6 +162,7 @@ public function addGroup(string $name, string $controller = null)
158162

159163
/**
160164
* @inheritdoc
165+
* @throws \InvalidArgumentException
161166
*/
162167
protected function dispatch($name)
163168
{
@@ -176,7 +181,7 @@ protected function dispatch($name)
176181
// like 'home/index'
177182
if (strpos($name, $sep) > 0) {
178183
$input = array_filter(explode($sep, $name));
179-
list($name, $action) = count($input) > 2 ? array_splice($input, 2) : $input;
184+
list($name, $action) = \count($input) > 2 ? array_splice($input, 2) : $input;
180185
}
181186

182187
if ($this->isController($name)) {
@@ -200,7 +205,7 @@ protected function dispatch($name)
200205
}
201206

202207
if ($similar) {
203-
$this->write(sprintf('Maybe what you mean is: <info>%s</info>', implode(', ', $similar)));
208+
$this->write(sprintf("\nMaybe what you mean is:\n <info>%s</info>", implode(', ', $similar)));
204209
} else {
205210
$this->showCommandList(false);
206211
}
@@ -214,6 +219,7 @@ protected function dispatch($name)
214219
* @param string $name Command name
215220
* @param bool $believable The `$name` is believable
216221
* @return mixed
222+
* @throws \InvalidArgumentException
217223
*/
218224
public function runCommand($name, $believable = false)
219225
{
@@ -225,7 +231,7 @@ public function runCommand($name, $believable = false)
225231
/** @var \Closure|string $handler Command class */
226232
$handler = $this->commands[$name];
227233

228-
if (is_object($handler) && method_exists($handler, '__invoke')) {
234+
if (\is_object($handler) && method_exists($handler, '__invoke')) {
229235
$status = $handler($this->input, $this->output);
230236
} else {
231237
if (!class_exists($handler)) {
@@ -253,6 +259,7 @@ public function runCommand($name, $believable = false)
253259
* @param bool $believable The `$name` is believable
254260
* @param bool $standAlone
255261
* @return mixed
262+
* @throws \InvalidArgumentException
256263
*/
257264
public function runAction($name, $action, $believable = false, $standAlone = false)
258265
{

src/Base/AbstractApplication.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function stop($code = 0)
207207
protected function runtimeCheck()
208208
{
209209
// check env
210-
if (!in_array(PHP_SAPI, ['cli', 'cli-server'], true)) {
210+
if (!\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) {
211211
header('HTTP/1.1 403 Forbidden');
212212
exit(" 403 Forbidden \n\n"
213213
. " current environment is CLI. \n"
@@ -301,6 +301,7 @@ protected function filterSpecialCommand($command)
301301
/**
302302
* @param $name
303303
* @param bool $isGroup
304+
* @throws \InvalidArgumentException
304305
*/
305306
protected function validateName(string $name, $isGroup = false)
306307
{
@@ -403,10 +404,10 @@ public function showCommandList($quit = true)
403404
$desc = $command::getDescription() ?: $desPlaceholder;
404405
} else if ($msg = $this->getCommandMessage($name)) {
405406
$desc = $msg;
406-
} else if (is_string($command)) {
407+
} else if (\is_string($command)) {
407408
$desc = 'A handler : ' . $command;
408-
} else if (is_object($command)) {
409-
$desc = 'A handler by ' . get_class($command);
409+
} else if (\is_object($command)) {
410+
$desc = 'A handler by ' . \get_class($command);
410411
}
411412

412413
$commandArr[$name] = $desc;
@@ -423,7 +424,7 @@ public function showCommandList($quit = true)
423424

424425
$this->output->mList([
425426
//'There are all console controllers and independent commands.',
426-
'Usage:' => "$script {route|command} [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
427+
'Usage:' => "$script {command} [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
427428
'Options:' => self::$internalOptions,
428429
'Available Commands:' => array_merge($controllerArr, $commandArr, $internalCommands),
429430
//'Independent Commands:' => $commandArr ?: '... No register any independent command',
@@ -432,7 +433,7 @@ public function showCommandList($quit = true)
432433

433434
// $this->output->mList([
434435
// //'There are all console controllers and independent commands.',
435-
// 'Usage:' => "$script {route|command} [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
436+
// 'Usage:' => "$script {command} [arg0 arg1=value1 arg2=value2 ...] [--opt -v -h ...]",
436437
// 'Options:' => self::$internalOptions,
437438
// 'Group Commands:' => $controllerArr ?: '... No register any group command(controller)',
438439
// 'Independent Commands:' => $commandArr ?: '... No register any independent command',
@@ -491,7 +492,7 @@ public function getCommandNames()
491492
public function setControllers(array $controllers)
492493
{
493494
foreach ($controllers as $name => $controller) {
494-
if (is_int($name)) {
495+
if (\is_int($name)) {
495496
$this->controller($controller);
496497
} else {
497498
$this->controller($name, $controller);
@@ -522,7 +523,7 @@ public function isController($name)
522523
public function setCommands(array $commands)
523524
{
524525
foreach ($commands as $name => $handler) {
525-
if (is_int($name)) {
526+
if (\is_int($name)) {
526527
$this->command($handler);
527528
} else {
528529
$this->command($name, $handler);

src/Base/AbstractCommand.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected function showHelp()
184184
protected function prepare()
185185
{
186186
if ($this->processTitle) {
187-
if (function_exists('cli_set_process_title')) {
187+
if (\function_exists('cli_set_process_title')) {
188188
if (false === @cli_set_process_title($this->processTitle)) {
189189
if ('Darwin' === PHP_OS) {
190190
$this->output->writeln('<comment>Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.</comment>');
@@ -193,7 +193,7 @@ protected function prepare()
193193
trigger_error($error['message'], E_USER_WARNING);
194194
}
195195
}
196-
} elseif (function_exists('setproctitle')) {
196+
} elseif (\function_exists('setproctitle')) {
197197
setproctitle($this->processTitle);
198198
// } elseif (isDebug) {
199199
// $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
@@ -218,14 +218,14 @@ public function validateInput()
218218
$givenArgs = $errArgs = [];
219219

220220
foreach ($in->getArgs() as $key => $value) {
221-
if (is_int($key)) {
221+
if (\is_int($key)) {
222222
$givenArgs[$key] = $value;
223223
} else {
224224
$errArgs[] = $key;
225225
}
226226
}
227227

228-
if (count($errArgs) > 0) {
228+
if (\count($errArgs) > 0) {
229229
$this->output->liteError(sprintf('Unknown arguments (error: "%s").', implode(', ', $errArgs)));
230230

231231
return false;
@@ -236,7 +236,7 @@ public function validateInput()
236236
return !array_key_exists($key, $givenArgs) && $def->argumentIsRequired($name);
237237
}, ARRAY_FILTER_USE_BOTH);
238238

239-
if (count($missingArgs) > 0) {
239+
if (\count($missingArgs) > 0) {
240240
$this->output->liteError(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArgs)));
241241
return false;
242242
}
@@ -266,7 +266,7 @@ public function validateInput()
266266
}
267267
}
268268

269-
if (count($missingOpts) > 0) {
269+
if (\count($missingOpts) > 0) {
270270
$this->output->liteError(sprintf('Not enough options parameters (missing: "%s").', implode(', ', $missingOpts)));
271271

272272
return false;
@@ -319,6 +319,7 @@ protected function handleAnnotationVars($str)
319319
* @param string $method
320320
* @param null|string $action
321321
* @return int
322+
* @throws \ReflectionException
322323
*/
323324
protected function showHelpByMethodAnnotation($method, $action = null)
324325
{
@@ -341,7 +342,7 @@ protected function showHelpByMethodAnnotation($method, $action = null)
341342
$tags = Annotation::tagList($this->handleAnnotationVars($doc));
342343

343344
foreach ($tags as $tag => $msg) {
344-
if (!$msg || !is_string($msg)) {
345+
if (!$msg || !\is_string($msg)) {
345346
continue;
346347
}
347348

src/Controller.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ protected function configure()
7171
* @param Input $input
7272
* @param Output $output
7373
* @return mixed
74+
* @throws \ReflectionException
7475
*/
7576
protected function execute($input, $output)
7677
{
@@ -102,7 +103,7 @@ protected function execute($input, $output)
102103
}
103104

104105
if ($similar) {
105-
$output->liteWarning(sprintf("Maybe what you mean is:\n\t <info>%s</info>", implode(', ', $similar)));
106+
$output->write(sprintf("\nMaybe what you mean is:\n <info>%s</info>", implode(', ', $similar)));
106107
} else {
107108
$this->showCommandList();
108109
}
@@ -113,6 +114,7 @@ protected function execute($input, $output)
113114

114115
/**
115116
* @return int
117+
* @throws \ReflectionException
116118
*/
117119
protected function showHelp()
118120
{
@@ -134,6 +136,7 @@ protected function showHelp()
134136
* {script} {name} index
135137
*
136138
* @return int
139+
* @throws \ReflectionException
137140
*/
138141
final public function helpCommand()
139142
{
@@ -154,6 +157,7 @@ final public function helpCommand()
154157

155158
/**
156159
* show command list of the controller class
160+
* @throws \ReflectionException
157161
*/
158162
final public function showCommandList()
159163
{

src/IO/Input.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public function get($name, $default = null)
199199
* get a required argument
200200
* @param int|string $name
201201
* @return mixed
202+
* @throws \InvalidArgumentException
202203
*/
203204
public function getRequiredArg($name)
204205
{
@@ -305,6 +306,7 @@ public function getOption(string $name, $default = null)
305306
* get a required argument
306307
* @param int|string $name
307308
* @return mixed
309+
* @throws \InvalidArgumentException
308310
*/
309311
public function getRequiredOpt($name)
310312
{
@@ -408,7 +410,7 @@ public function sBoolOpt(string $name, $default = false): bool
408410
{
409411
$val = $this->sOpt($name);
410412

411-
return is_bool($val) ? $val : (bool)$default;
413+
return \is_bool($val) ? $val : (bool)$default;
412414
}
413415

414416
/**
@@ -474,7 +476,7 @@ public function lBoolOpt(string $name, $default = false): bool
474476
{
475477
$val = $this->lOpt($name);
476478

477-
return is_bool($val) ? $val : (bool)$default;
479+
return \is_bool($val) ? $val : (bool)$default;
478480
}
479481

480482
/**

0 commit comments

Comments
 (0)