Skip to content

Commit

Permalink
Merge pull request #337 from sensiolabs-de/improve-console-output-for…
Browse files Browse the repository at this point in the history
…matter

introduce table output formatter
  • Loading branch information
Simon Mönch authored Oct 19, 2020
2 parents 5ade86b + 7e03079 commit 77547e9
Show file tree
Hide file tree
Showing 24 changed files with 761 additions and 94 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ this rule has been violated.
1. [Custom Collectors](#custom-collectors)
1. [Formatters](#formatters)
1. [Console Formatter](#console-formatter)
1. [Table Formatter](#table-formatter)
1. [Graphviz Formatter](#graphviz-formatter)
1. [JUnit Formatter](#junit-formatter)
1. [GitHubActions Formatter](#githubactions-formatter)
Expand Down Expand Up @@ -631,6 +632,18 @@ Supported options:
--formatter-console-report-uncovered= report uncovered dependencies [default: false]
```
### Table Formatter
The table formatter groups results by layers to its own table. It can be activated with `--formatter-table=true`.
Supported options:
```
--formatter-table= to disable the table formatter, set this argument to "false" [default: true]
--formatter-table-report-uncovered= report uncovered dependencies [default: false]
```
### Graphviz Formatter
Expand Down
4 changes: 4 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use SensioLabs\Deptrac\OutputFormatter\GithubActionsOutputFormatter;
use SensioLabs\Deptrac\OutputFormatter\GraphVizOutputFormatter;
use SensioLabs\Deptrac\OutputFormatter\JUnitOutputFormatter;
use SensioLabs\Deptrac\OutputFormatter\TableOutputFormatter;
use SensioLabs\Deptrac\OutputFormatter\XMLOutputFormatter;
use SensioLabs\Deptrac\OutputFormatterFactory;
use SensioLabs\Deptrac\RulesetEngine;
Expand Down Expand Up @@ -122,6 +123,9 @@
$services
->set(JUnitOutputFormatter::class)
->tag('output_formatter');
$services
->set(TableOutputFormatter::class)
->tag('output_formatter');
$services
->set(XMLOutputFormatter::class)
->tag('output_formatter');
Expand Down
3 changes: 3 additions & 0 deletions examples/DirectoryLayer.depfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ ruleset:
- Layer1
Layer1:
- Layer2
skip_violations:
examples\Layer2\SomeOtherClass:
- examples\Layer1\SomeClass
5 changes: 5 additions & 0 deletions examples/Layer1/SomeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class SomeClass
*/
private $someOtherClass;

/**
* @var \Uncovered\Dependency
*/
private $uncovered;

/**
* @param SomeOtherClass $someOtherClass
*/
Expand Down
9 changes: 7 additions & 2 deletions src/Console/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use SensioLabs\Deptrac\Analyser;
use SensioLabs\Deptrac\Configuration\Loader as ConfigurationLoader;
use SensioLabs\Deptrac\Console\Command\Exception\SingleDepfileIsRequiredException;
use SensioLabs\Deptrac\Console\Symfony\Style;
use SensioLabs\Deptrac\Console\Symfony\SymfonyOutput;
use SensioLabs\Deptrac\OutputFormatterFactory;
use SensioLabs\Deptrac\Subscriber\ConsoleSubscriber;
use SensioLabs\Deptrac\Subscriber\ProgressSubscriber;
Expand All @@ -15,6 +17,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class AnalyzeCommand extends Command
Expand Down Expand Up @@ -67,12 +70,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw SingleDepfileIsRequiredException::fromArgument($file);
}

$symfonyOutput = new SymfonyOutput($output, new Style(new SymfonyStyle($input, $output)));

$configuration = $this->configurationLoader->load($file);

$this->dispatcher->addSubscriber(new ConsoleSubscriber($output));

if (!$input->getOption('no-progress')) {
$this->dispatcher->addSubscriber(new ProgressSubscriber($output));
$this->dispatcher->addSubscriber(new ProgressSubscriber($symfonyOutput));
}

$this->printCollectViolations($output);
Expand All @@ -84,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$formatter->finish(
$context,
$output,
$symfonyOutput,
$this->formatterFactory->getOutputFormatterInput($formatter, $input)
);
} catch (\Exception $ex) {
Expand Down
20 changes: 20 additions & 0 deletions src/Console/Output.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace SensioLabs\Deptrac\Console;

interface Output
{
public function writeFormatted(string $message): void;

public function writeLineFormatted(string $message): void;

public function writeRaw(string $message): void;

public function getStyle(): OutputStyle;

public function isVerbose(): bool;

public function isDebug(): bool;
}
43 changes: 43 additions & 0 deletions src/Console/OutputStyle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace SensioLabs\Deptrac\Console;

use Symfony\Component\Console\Helper\TableSeparator;

interface OutputStyle
{
public function title(string $message): void;

public function section(string $message): void;

public function success(string $message): void;

public function error(string $message): void;

public function warning(string $message): void;

public function note(string $message): void;

public function caution(string $message): void;

/**
* @param string|array|TableSeparator ...$list
*/
public function definitionList(...$list): void;

/**
* @param mixed[] $headers
* @param mixed[] $rows
*/
public function table(array $headers, array $rows): void;

public function newLine(int $count = 1): void;

public function progressStart(int $max = 0): void;

public function progressAdvance(int $step = 1): void;

public function progressFinish(): void;
}
89 changes: 89 additions & 0 deletions src/Console/Symfony/Style.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace SensioLabs\Deptrac\Console\Symfony;

use SensioLabs\Deptrac\Console\OutputStyle;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @internal
*/
class Style implements OutputStyle
{
private $symfonyStyle;

public function __construct(SymfonyStyle $symfonyStyle)
{
$this->symfonyStyle = $symfonyStyle;
}

public function title(string $message): void
{
$this->symfonyStyle->title($message);
}

public function section(string $message): void
{
$this->symfonyStyle->section($message);
}

public function success(string $message): void
{
$this->symfonyStyle->success($message);
}

public function error(string $message): void
{
$this->symfonyStyle->error($message);
}

public function warning(string $message): void
{
$this->symfonyStyle->warning($message);
}

public function note(string $message): void
{
$this->symfonyStyle->note($message);
}

public function caution(string $message): void
{
$this->symfonyStyle->caution($message);
}

/**
* {@inheritdoc}
*/
public function definitionList(...$list): void
{
$this->symfonyStyle->definitionList(...$list);
}

public function table(array $headers, array $rows): void
{
$this->symfonyStyle->table($headers, $rows);
}

public function newLine(int $count = 1): void
{
$this->symfonyStyle->newLine($count);
}

public function progressStart(int $max = 0): void
{
$this->symfonyStyle->progressStart($max);
}

public function progressAdvance(int $step = 1): void
{
$this->symfonyStyle->progressAdvance($step);
}

public function progressFinish(): void
{
$this->symfonyStyle->progressFinish();
}
}
56 changes: 56 additions & 0 deletions src/Console/Symfony/SymfonyOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace SensioLabs\Deptrac\Console\Symfony;

use SensioLabs\Deptrac\Console\Output;
use SensioLabs\Deptrac\Console\OutputStyle;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
class SymfonyOutput implements Output
{
private $symfonyOutput;
private $style;

public function __construct(
OutputInterface $symfonyOutput,
OutputStyle $style
) {
$this->symfonyOutput = $symfonyOutput;
$this->style = $style;
}

public function writeFormatted(string $message): void
{
$this->symfonyOutput->write($message, false, OutputInterface::OUTPUT_NORMAL);
}

public function writeLineFormatted(string $message): void
{
$this->symfonyOutput->writeln($message, OutputInterface::OUTPUT_NORMAL);
}

public function writeRaw(string $message): void
{
$this->symfonyOutput->write($message, false, OutputInterface::OUTPUT_RAW);
}

public function getStyle(): OutputStyle
{
return $this->style;
}

public function isVerbose(): bool
{
return $this->symfonyOutput->isVerbose();
}

public function isDebug(): bool
{
return $this->symfonyOutput->isDebug();
}
}
Loading

0 comments on commit 77547e9

Please sign in to comment.