Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
lotfio committed Jul 28, 2020
1 parent 93b7ac3 commit 9d54217
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
*
* @copyright 2019 Lotfio Lakehal
*/
$conso->command('command', Conso\Commands\Command::class);
$conso->command('command', Conso\Commands\Command::class);
2 changes: 1 addition & 1 deletion src/Conso/CommandInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
18 changes: 10 additions & 8 deletions src/Conso/CommandLinker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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);
Expand Down Expand Up @@ -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]+)');
}
}
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Conso/Conso.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 15 additions & 14 deletions src/Conso/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,29 @@ 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;
}

// reset argv array
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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 9d54217

Please sign in to comment.