Skip to content

Commit

Permalink
Uses table output
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelstolt committed May 2, 2024
1 parent 9efd783 commit 8c15353
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 132 deletions.
51 changes: 36 additions & 15 deletions app/Commands/Analyse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use App\Domain\ReportWriter;
use App\Exceptions\NonExistentPackageDirectory;
use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Helper\TableSeparator;

class Analyse extends Command
{
Expand Down Expand Up @@ -37,31 +40,49 @@ public function handle(): int
{
$workingDirectory = getcwd();
$packageDirectory = $this->argument('package-directory');
$violationText = '';

try {
$this->packageAnalyser = new PackageAnalyser($packageDirectory, $this->getOutput());
$this->packageAnalyser = new PackageAnalyser($packageDirectory);
$this->getOutput()->writeln('Analysing 📦 in directory <info>'.realpath($packageDirectory).'</info>');
$amountOfAnalysisSteps = $this->packageAnalyser->analyse();

if (count($this->packageAnalyser->getViolations()) > 0) {
$violationText = 'Found <info>'.count($this->packageAnalyser->getViolations()).'</info> optimiseable aspect';
if (count($this->packageAnalyser->getViolations()) > 1) {
$violationText = 'Found <info>'.count($this->packageAnalyser->getViolations()).'</info> optimiseable aspects';
}
}

$table = new Table($this->getOutput());
$table->setHeaders(['#', 'Analyse step', 'Status']);
$table->setRows([
$this->packageAnalyser->getStepsForTable()[0],
$this->packageAnalyser->getStepsForTable()[1],
$this->packageAnalyser->getStepsForTable()[2],
$this->packageAnalyser->getStepsForTable()[3],
$this->packageAnalyser->getStepsForTable()[4],
$this->packageAnalyser->getStepsForTable()[5],
$this->packageAnalyser->getStepsForTable()[6],
$this->packageAnalyser->getStepsForTable()[7],
$this->packageAnalyser->getStepsForTable()[8],
$this->packageAnalyser->getStepsForTable()[9],
$this->packageAnalyser->getStepsForTable()[10],
$this->packageAnalyser->getStepsForTable()[11],
$this->packageAnalyser->getStepsForTable()[12],
$this->packageAnalyser->getStepsForTable()[13],
$this->packageAnalyser->getStepsForTable()[14],
new TableSeparator(),
[new TableCell('Ran <info>'.$amountOfAnalysisSteps.'</info> analysis steps. '.$violationText, ['colspan' => 3])],
]);

$table->render();
} catch (NonExistentPackageDirectory $e) {
$this->getOutput()->writeln($e->getMessage());

return self::FAILURE;
}

$this->getOutput()->writeln('Ran <info>'.$amountOfAnalysisSteps.'</info> analysis steps');

if (count($this->packageAnalyser->getViolations()) > 0) {
if (count($this->packageAnalyser->getViolations()) === 1) {
$this->getOutput()->writeln(
'Found <info>'.count($this->packageAnalyser->getViolations()).'</info> optimiseable aspect'
);
} else {
$this->getOutput()->writeln(
'Found <info>'.count($this->packageAnalyser->getViolations()).'</info> optimiseable aspects'
);
}
}

$writeReportOption = $this->option('write-report');

if ($writeReportOption) {
Expand Down
Loading

0 comments on commit 8c15353

Please sign in to comment.