diff --git a/commands.php b/commands.php index 7effa5d..908d1f3 100644 --- a/commands.php +++ b/commands.php @@ -11,4 +11,4 @@ * * @copyright 2019 Lotfio Lakehal */ -$conso->command('command', Conso\Commands\Command::class); \ No newline at end of file +$conso->command('command', Conso\Commands\Command::class); diff --git a/src/Conso/CommandInvoker.php b/src/Conso/CommandInvoker.php index 048beb4..59fbf97 100644 --- a/src/Conso/CommandInvoker.php +++ b/src/Conso/CommandInvoker.php @@ -123,7 +123,7 @@ public function invoke(?array $command) $commands = $this->app->getCommands(); // defined commands // disable ansi - if ($this->input->flag('--no-ansi') !== false ) { + if ($this->input->flag('--no-ansi') !== false) { $this->output->disableAnsi(); } diff --git a/src/Conso/CommandLinker.php b/src/Conso/CommandLinker.php index 1b50bab..c3c8ef3 100644 --- a/src/Conso/CommandLinker.php +++ b/src/Conso/CommandLinker.php @@ -59,10 +59,10 @@ public function __construct(InputInterface $input, OutputInterface $output) */ public function link(array &$commands): ?array { - $command = $this->input->command(); + $command = $this->input->command(); $subCommand = $this->input->subCommand(); - $options = $this->input->options(); - $flags = $this->input->flags(); + $options = $this->input->options(); + $flags = $this->input->flags(); // if command is a class for ($i = 0; $i < count($commands); $i++) { @@ -77,7 +77,6 @@ public function link(array &$commands): ?array for ($i = 0; $i < count($commands); $i++) { if ($command == $commands[$i]['name'] || in_array($command, $commands[$i]['aliases'])) { - $this->linkSubCommand($subCommand, $commands[$i]['sub']); $this->linkOptions($options); @@ -108,16 +107,19 @@ private function linkSubCommand(?string $subCommand, array $sub): void } /** - * link options + * link options. * * @param array $options + * * @return void */ public function linkOptions(array $options) { - foreach($options as $option) - if(!preg_match('/^[A-z0-9]+$/', $option)) - throw new InputException("oly alpha-numeric characters are allowed for options ([A-z0-9]+)"); + foreach ($options as $option) { + if (!preg_match('/^[A-z0-9]+$/', $option)) { + throw new InputException('oly alpha-numeric characters are allowed for options ([A-z0-9]+)'); + } + } } /** diff --git a/src/Conso/Conso.php b/src/Conso/Conso.php index 173afc9..8309633 100644 --- a/src/Conso/Conso.php +++ b/src/Conso/Conso.php @@ -94,17 +94,16 @@ public function command(string $name, $action): CommandsTable public function run(int $env = 0) { // build in commands - if (!$this->output->isTestMode()) - $this->loadBuildInCommands(); + if (!$this->output->isTestMode()) { + $this->loadBuildInCommands(); + } try { // pass table defined commands & match $this->invokedCommand = $this->linker->link($this->getCommands()); return $this->invoker->invoke($this->invokedCommand); - } catch (\Exception $e) { - if ($this->output->isTestMode()) { // is test mode throw new \Exception($e); diff --git a/src/Conso/Input.php b/src/Conso/Input.php index 0f79d1d..5c86021 100644 --- a/src/Conso/Input.php +++ b/src/Conso/Input.php @@ -110,7 +110,7 @@ private function extract(array $argv): void // if command & sub command if (preg_match('/^([A-z]+)(\:)([A-z]+)$/', $argv[0])) { $command = explode(':', $argv[0]); - $this->command = $command[0] ?? null; + $this->command = $command[0] ?? null; $this->subCommand = $command[1] ?? null; } @@ -118,20 +118,21 @@ private function extract(array $argv): void unset($argv[0]); } - $flags = $this->captureFlags($argv); + $flags = $this->captureFlags($argv); - $this->flags = $this->extractFlags($flags); + $this->flags = $this->extractFlags($flags); $this->options = array_values(array_diff($argv, $flags)); } /** - * extract flags method + * extract flags method. * * @param array $argv + * * @return array */ - private function captureFlags(array $argv) : array + private function captureFlags(array $argv): array { $flags = array_filter($argv, function ($elem) { return preg_match('/^[\-]{1,2}[A-z]+((\-\w+)|(\=.*))?$/', $elem); @@ -141,19 +142,18 @@ private function captureFlags(array $argv) : array } /** - * extract flags + * extract flags. + * + * @param array $flags * - * @param array $flags * @return array */ - private function extractFlags(array $flags) : array + private function extractFlags(array $flags): array { $flagsWithValues = []; - foreach($flags as $flag) - { - if(strpos($flag, '=') !== FALSE) - { + foreach ($flags as $flag) { + if (strpos($flag, '=') !== false) { $exp = explode('=', $flag); $flagsWithValues[$exp[0]] = $exp[1]; continue; @@ -250,13 +250,14 @@ public function reservedFlags() } /** - * read line method + * read line method. * * @param string $line + * * @return void */ public function readLine(string $line) { - return readLine($line); + return readline($line); } }