Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed May 27, 2021
1 parent deae6b1 commit 2934960
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/Commands/CheckPsr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public function handle(ErrorPrinter $errorPrinter)
$this->fixReferences($autoload, $olds, $news);
}
if (Str::startsWith(request()->server('argv')[1] ?? '', 'check:psr4')) {
$this->getOutput()->writeln('');
$this->getOutput()->writeln('<fg=green>Finished!</fg=green>');
$this->getOutput()->writeln('==============================');
$this->getOutput()->writeln('<options=bold;fg=yellow>'.CheckNamespaces::$checkedNamespaces.' classes were checked under:</>');
$this->getOutput()->writeln(' - '.implode("\n - ", array_keys($autoload)).'');
$this->reportResult($autoload);
$this->printErrorsCount($errorPrinter, $time);
} else {
$this->getOutput()->writeln(' - '.CheckNamespaces::$checkedNamespaces.' namespaces were checked.');
Expand Down Expand Up @@ -175,20 +171,34 @@ private function checkNamespaces(array $autoload)
}
}

private function report(string $_path, $line)
private function report($_path, $line)
{
app(ErrorPrinter::class)->simplePendError($_path, $line, '', 'ns_replacement', 'Namespace replacement:');
}

private function printErrorsCount($errorPrinter, $time)
{
if ($errorCount = $errorPrinter->errorsList['total']) {
$errorCount && $this->warn(PHP_EOL.$errorCount.' error(s) found in namespaces');
$this->warn(PHP_EOL.$errorCount.' error(s) found in namespaces');
} else {
$time = microtime(true) - $time;
$this->line(PHP_EOL.'<fg=green>All namespaces are correct!</><fg=blue> You rock \(^_^)/ </>');
$this->line('<fg=red;options=bold>'.round($time, 5).'(s)</>');
$this->line('');
$this->noErrorFound($time);
}
}

private function reportResult($autoload)
{
$this->getOutput()->writeln('');
$this->getOutput()->writeln('<fg=green>Finished!</fg=green>');
$this->getOutput()->writeln('==============================');
$this->getOutput()->writeln('<options=bold;fg=yellow>'.CheckNamespaces::$checkedNamespaces.' classes were checked under:</>');
$this->getOutput()->writeln(' - '.implode("\n - ", array_keys($autoload)).'');
}

private function noErrorFound($time)
{
$time = microtime(true) - $time;
$this->line(PHP_EOL.'<fg=green>All namespaces are correct!</><fg=blue> You rock \(^_^)/ </>');
$this->line('<fg=red;options=bold>'.round($time, 5).'(s)</>');
$this->line('');
}
}

0 comments on commit 2934960

Please sign in to comment.