diff --git a/src/Conso/CommandInvoker.php b/src/Conso/CommandInvoker.php index fea03d9..de63e7c 100644 --- a/src/Conso/CommandInvoker.php +++ b/src/Conso/CommandInvoker.php @@ -96,9 +96,11 @@ public function showConsoleInformation(array $commands) * * @return void */ - public function showConsoleCommands(array $commands) : void + public function showConsoleCommands(array $commands): void { - if (count($commands) < 1) return; + if (count($commands) < 1) { + return; + } // sort & get max length command sort($commands); @@ -107,15 +109,14 @@ public function showConsoleCommands(array $commands) : void // group commands $grouped = []; - foreach($commands as $command) + foreach ($commands as $command) { $grouped[$command['group']][] = $command; + } $this->output->writeLn("\nAvailable Commands:\n\n", 'yellow'); - if(isset($grouped['main'])) //no groups - { - foreach($grouped['main'] as $command) - { + if (isset($grouped['main'])) { //no groups + foreach ($grouped['main'] as $command) { $this->output->writeLn(' '.$command['name'].str_repeat(' ', ($max - strlen($command['name'])) + 4), 'green'); $this->output->writeLn($command['description']."\n"); } @@ -123,8 +124,7 @@ public function showConsoleCommands(array $commands) : void unset($grouped['main']); } - foreach($grouped as $group => $commands) // if groups - { + foreach ($grouped as $group => $commands) { // if groups $this->output->writeLn("\n$group\n\n", 'yellow'); foreach ($commands as $command) { @@ -190,6 +190,7 @@ public function invoke(?array $command) protected function invokeCallback(array $command) { $closure = \Closure::bind($command['action'], $this->app); + return call_user_func_array($closure, [$this->input, $this->output]); } @@ -205,8 +206,8 @@ protected function invokeClassMethod(array $command) $subCommand = $this->input->subCommand(); // append namespace - $namespace = (!is_null($command['namespace'])) ? rtrim($command['namespace'], '\\') . '\\' : ''; - $class = $namespace . ucfirst($command['action']); + $namespace = (!is_null($command['namespace'])) ? rtrim($command['namespace'], '\\').'\\' : ''; + $class = $namespace.ucfirst($command['action']); if (!class_exists($class)) { throw new InvokerException("command class ($class) is not defined."); diff --git a/src/Conso/CommandsTable.php b/src/Conso/CommandsTable.php index e03956e..63a9b50 100644 --- a/src/Conso/CommandsTable.php +++ b/src/Conso/CommandsTable.php @@ -30,18 +30,18 @@ class CommandsTable ]; /** - * command group + * command group. * * @var ?string */ private $group = 'main'; /** - * command namespace + * command namespace. * * @var ?string */ - private $namespace = NULL; + private $namespace = null; /** * add command method. @@ -62,7 +62,7 @@ public function add(string $name, $action): self 'description' => '', 'help' => [], 'group' => $this->group, - 'namespace' => $this->namespace + 'namespace' => $this->namespace, ]; return $this; @@ -147,45 +147,47 @@ public function help(array $help): self } /** - * set command group + * set command group. * * @param string $group + * * @return void */ - public function setGroup(string $group) : void + public function setGroup(string $group): void { $this->group = $group; } /** - * unset group + * unset group. * * @return void */ - public function unsetGroup() : void + public function unsetGroup(): void { $this->group = 'main'; } /** - * set namespace + * set namespace. * * @param string $namespace + * * @return void */ - public function setNamespace(string $namespace) : void + public function setNamespace(string $namespace): void { $this->namespace = $namespace; } /** - * unset namespace + * unset namespace. * * @return void */ - public function unsetNamespace() : void + public function unsetNamespace(): void { - $this->namespace = NULL; + $this->namespace = null; } /** diff --git a/src/Conso/Conso.php b/src/Conso/Conso.php index 222da6f..ec2ded2 100644 --- a/src/Conso/Conso.php +++ b/src/Conso/Conso.php @@ -85,11 +85,11 @@ public function command(string $name, $action): CommandsTable } /** - * command group method + * command group method. * * @return void */ - public function group(string $name, callable $callback) : void + public function group(string $name, callable $callback): void { $this->table->setGroup($name); call_user_func($callback, $this); @@ -97,11 +97,11 @@ public function group(string $name, callable $callback) : void } /** - * command group method + * command group method. * * @return void */ - public function namespace(string $namespace, callable $callback) : void + public function namespace(string $namespace, callable $callback): void { $this->table->setNamespace($namespace); call_user_func($callback, $this); diff --git a/src/Conso/hlprs.php b/src/Conso/hlprs.php index 1a49493..39fa88a 100644 --- a/src/Conso/hlprs.php +++ b/src/Conso/hlprs.php @@ -71,18 +71,16 @@ function readCommandPropertiesFromClass(array &$command): void if (is_string($command['action'])) { // if is controller - $namespace = (!is_null($command['namespace'])) ? rtrim($command['namespace'], '\\') . '\\' : ''; - $class = $namespace . ucfirst($command['action']); + $namespace = (!is_null($command['namespace'])) ? rtrim($command['namespace'], '\\').'\\' : ''; + $class = $namespace.ucfirst($command['action']); - if(class_exists($class)) - { + if (class_exists($class)) { foreach ($list as $lst) { if (empty($command[$lst])) { $command[$lst] = readProtectedProperty($class, $lst); } } } - } // fill from command class if not defined by method } diff --git a/tests/Unit/CommandInvokerTest.php b/tests/Unit/CommandInvokerTest.php index 9f8c8f7..a49c186 100644 --- a/tests/Unit/CommandInvokerTest.php +++ b/tests/Unit/CommandInvokerTest.php @@ -57,7 +57,7 @@ public function setUp(): void 'description' => 'This is make command', 'help' => [], 'group' => 'main', - 'namespace' => NULL + 'namespace' => null, ], ]; } diff --git a/tests/Unit/CommandLinkerTest.php b/tests/Unit/CommandLinkerTest.php index d87ac86..1fe9d97 100644 --- a/tests/Unit/CommandLinkerTest.php +++ b/tests/Unit/CommandLinkerTest.php @@ -57,7 +57,7 @@ public function setUp(): void 'description' => 'This is make command', 'help' => [], 'group' => 'main', - 'namespace' => NULL + 'namespace' => null, ], ]; }