From b1359ad578f29495f5b9690d4050931732fd7382 Mon Sep 17 00:00:00 2001 From: lotfio lakehal Date: Fri, 24 Jul 2020 12:54:22 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Conso/CommandLinker.php | 39 ++++++++++++++++++---------------- src/Conso/Commands/Command.php | 2 +- src/Conso/Conso.php | 10 ++++----- src/Conso/ConsoTrait.php | 6 +++--- src/Conso/Input.php | 9 ++++---- src/Conso/hlprs.php | 12 ++++------- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Conso/CommandLinker.php b/src/Conso/CommandLinker.php index 7463446..f42417f 100644 --- a/src/Conso/CommandLinker.php +++ b/src/Conso/CommandLinker.php @@ -46,7 +46,7 @@ class CommandLinker */ public function __construct(InputInterface $input, OutputInterface $output) { - $this->input = $input; + $this->input = $input; $this->output = $output; } @@ -59,26 +59,23 @@ 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(); - $flags = $this->input->flags(); + $flags = $this->input->flags(); // if command is a class for ($i = 0; $i < count($commands); $i++) { readCommandPropertiesFromClass($commands[$i]); } // fill array info - - if (!$command) // if no command only flags - { + if (!$command) { // if no command only flags $this->linkFlags($flags); + return null; } 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->linkFlags($flags, $commands[$i]['flags']); @@ -90,32 +87,38 @@ public function link(array &$commands): ?array throw new InputException("command ({$command}) is not defined."); } - /** - * link sub command method + * link sub command method. * * @param string|null $subCommand - * @param array $sub + * @param array $sub + * * @return void */ - private function linkSubCommand(?string $subCommand, array $sub) : void + private function linkSubCommand(?string $subCommand, array $sub): void { - if ($subCommand && !in_array($subCommand, $sub))// match sub commands + if ($subCommand && !in_array($subCommand, $sub)) {// match sub commands + throw new InputException("sub command ({$subCommand}) is not defined."); + } } /** - * link flags method + * link flags method. * * @param array $flags * @param array $reserved + * * @return void */ - private function linkFlags(array $flags, array $reserved = []) : void + private function linkFlags(array $flags, array $reserved = []): void { - if (count($flags)) - foreach ($flags as $flag) - if (!in_array($flag, array_merge($reserved, $this->input->reservedFlags()) )) + if (count($flags)) { + foreach ($flags as $flag) { + if (!in_array($flag, array_merge($reserved, $this->input->reservedFlags()))) { throw new InputException("flag ({$flag}) is not defined."); + } + } + } } } diff --git a/src/Conso/Commands/Command.php b/src/Conso/Commands/Command.php index 62f855a..35da6aa 100644 --- a/src/Conso/Commands/Command.php +++ b/src/Conso/Commands/Command.php @@ -51,7 +51,7 @@ class Command extends BaseCommand implements CommandInterface ], 'options' => [ 'name' => 'command name to be created or deleted.', - ] + ], ]; /** diff --git a/src/Conso/Conso.php b/src/Conso/Conso.php index b10e398..e81cace 100644 --- a/src/Conso/Conso.php +++ b/src/Conso/Conso.php @@ -64,11 +64,11 @@ class Conso */ public function __construct(InputInterface $input, OutputInterface $output) { - $this->input = $input; - $this->output = $output; - $this->table = new CommandsTable(); - $this->linker = new CommandLinker($input, $output); - $this->invoker = new CommandInvoker($input, $output, $this); + $this->input = $input; + $this->output = $output; + $this->table = new CommandsTable(); + $this->linker = new CommandLinker($input, $output); + $this->invoker = new CommandInvoker($input, $output, $this); } /** diff --git a/src/Conso/ConsoTrait.php b/src/Conso/ConsoTrait.php index 7839329..98500f9 100644 --- a/src/Conso/ConsoTrait.php +++ b/src/Conso/ConsoTrait.php @@ -194,10 +194,10 @@ public function call(string $command): void { $inp = new Input($command); - if($inp->command() == $this->invokedCommand['name']) + if ($inp->command() == $this->invokedCommand['name']) { throw new InputException("cannot call same command [$command] recursively"); - - $cmd = 'php '. $this->input->getExecutable() . ' ' . $command; + } + $cmd = 'php '.$this->input->getExecutable().' '.$command; passthru($cmd); } diff --git a/src/Conso/Input.php b/src/Conso/Input.php index 3ced233..f4ba384 100644 --- a/src/Conso/Input.php +++ b/src/Conso/Input.php @@ -69,7 +69,7 @@ class Input implements InputInterface ]; /** - * executable file + * executable file. * * @var string */ @@ -85,7 +85,7 @@ public function __construct(?string $userArgv = null) { // get argv and remove file name global $argv; - $this->executable = $argv[0] ?? NULL; + $this->executable = $argv[0] ?? null; unset($argv[0]); // get argv or user argv @@ -191,14 +191,15 @@ public function flags(): array } /** - * get executable file + * get executable file. * * @return void */ - public function getExecutable() : string + public function getExecutable(): string { return $this->executable; } + /** * reserved flags. * diff --git a/src/Conso/hlprs.php b/src/Conso/hlprs.php index a4e678a..7dd9fcc 100644 --- a/src/Conso/hlprs.php +++ b/src/Conso/hlprs.php @@ -94,23 +94,19 @@ function commandHelp(array $command, $output) $output->writeLn(" php conso $name:[sub command] [options] [flags]\n"); if (is_array($help) && count($help) > 0) { - foreach ($help as $key => $value) { - $output->writeLn("\n ".$key.":\n\n", 'yellow'); // get longest $max = 0; - if(count($value) > 0) - { - $max = array_map(function($elem){ return strlen($elem);}, array_keys($value)); + if (count($value) > 0) { + $max = array_map(function ($elem) { return strlen($elem); }, array_keys($value)); $max = max($max); } foreach ($value as $a => $b) { - - $key = !is_numeric($a) ? $a . str_repeat(' ', ($max - (strlen($a)))) .' : ' : null; - $output->writeLn(' '. $key . $b . "\n"); + $key = !is_numeric($a) ? $a.str_repeat(' ', ($max - (strlen($a)))).' : ' : null; + $output->writeLn(' '.$key.$b."\n"); } } }