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 24, 2020
1 parent 873241b commit b1359ad
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
39 changes: 21 additions & 18 deletions src/Conso/CommandLinker.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CommandLinker
*/
public function __construct(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->input = $input;
$this->output = $output;
}

Expand All @@ -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']);
Expand All @@ -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.");
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Conso/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Command extends BaseCommand implements CommandInterface
],
'options' => [
'name' => 'command name to be created or deleted.',
]
],
];

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Conso/Conso.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Conso/ConsoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Conso/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Input implements InputInterface
];

/**
* executable file
* executable file.
*
* @var string
*/
Expand All @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
12 changes: 4 additions & 8 deletions src/Conso/hlprs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down

0 comments on commit b1359ad

Please sign in to comment.