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 30, 2020
1 parent 591e1c1 commit 5b71cfe
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
23 changes: 12 additions & 11 deletions src/Conso/CommandInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -107,24 +109,22 @@ 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");
}

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) {
Expand Down Expand Up @@ -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]);
}

Expand All @@ -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.");
Expand Down
28 changes: 15 additions & 13 deletions src/Conso/CommandsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -62,7 +62,7 @@ public function add(string $name, $action): self
'description' => '',
'help' => [],
'group' => $this->group,
'namespace' => $this->namespace
'namespace' => $this->namespace,
];

return $this;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Conso/Conso.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ 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);
$this->table->unsetGroup();
}

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/CommandInvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function setUp(): void
'description' => 'This is make command',
'help' => [],
'group' => 'main',
'namespace' => NULL
'namespace' => null,
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/CommandLinkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function setUp(): void
'description' => 'This is make command',
'help' => [],
'group' => 'main',
'namespace' => NULL
'namespace' => null,
],
];
}
Expand Down

0 comments on commit 5b71cfe

Please sign in to comment.