Skip to content

Commit

Permalink
Merge pull request #25 from jjanvier/simple-format
Browse files Browse the repository at this point in the history
Simple formatter
  • Loading branch information
jjanvier committed Mar 29, 2016
2 parents c5df176 + 8ae1f81 commit 4f23b4e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ The detect command detects coupling problems for a given file or directory depen
With the ``--config-file`` option you can specify the path to the ``.php_cd`` file:

php bin/php-coupling-detector detect /path/to/dir --config-file=/path/to/my/configuration.php_cd

With the --format option you can specify the output format:

php %command.full_name% /path/to/dir --format=dot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Akeneo\CouplingDetector\Domain\ViolationInterface;
use Akeneo\CouplingDetector\Formatter\Console\DotFormatter;
use Akeneo\CouplingDetector\Formatter\Console\PrettyFormatter;
use Akeneo\CouplingDetector\Formatter\SimpleFormatter;
use Akeneo\CouplingDetector\NodeParser\NodeParserResolver;
use Akeneo\CouplingDetector\RuleChecker;
use Symfony\Component\Console\Command\Command;
Expand All @@ -31,7 +32,7 @@ class DetectCommand extends Command
const EXIT_WITH_WARNINGS = 10;
const EXIT_WITH_ERRORS = 99;

private $formats = ['pretty', 'dot'];
private $formats = ['pretty', 'dot', 'simple'];

/**
* {@inheritedDoc}.
Expand Down Expand Up @@ -230,6 +231,9 @@ private function initEventDispatcher(OutputInterface $output, $formatterName, $v
$formatter = new DotFormatter($output);
} elseif ('pretty' === $formatterName) {
$formatter = new PrettyFormatter($output, $verbose);
}
elseif ('simple' === $formatterName) {
$formatter = new SimpleFormatter();
} else {
throw new \RuntimeException(
sprintf('Format "%s" is unknown. Available formats: %s.', $formatterName, implode(', ', $this->formats))
Expand Down
84 changes: 84 additions & 0 deletions src/Akeneo/CouplingDetector/Formatter/SimpleFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Akeneo\CouplingDetector\Formatter;

use Akeneo\CouplingDetector\Domain\ViolationInterface;
use Akeneo\CouplingDetector\Event\PostNodesParsedEvent;
use Akeneo\CouplingDetector\Event\NodeChecked;
use Akeneo\CouplingDetector\Event\NodeParsedEvent;
use Akeneo\CouplingDetector\Event\PreNodesParsedEvent;
use Akeneo\CouplingDetector\Event\PreRulesCheckedEvent;
use Akeneo\CouplingDetector\Event\RuleCheckedEvent;
use Akeneo\CouplingDetector\Event\PostRulesCheckedEvent;

/**
* Output the results really simply. Just the number of errors is displayed.
* E/W
* where E is the number of errors and W is the number of warnings
*
* @author Julien Janvier <[email protected]>
* @license http://opensource.org/licenses/MIT MIT
*/
class SimpleFormatter extends AbstractFormatter
{
/**
* {@inheritdoc}
*/
protected function outputPreNodesParsed(PreNodesParsedEvent $event)
{
}

/**
* {@inheritdoc}
*/
protected function outputNodeParsed(NodeParsedEvent $event)
{
}

/**
* {@inheritdoc}
*/
protected function outputPostNodesParsed(PostNodesParsedEvent $event)
{
}

/**
* {@inheritdoc}
*/
protected function outputPreRulesChecked(PreRulesCheckedEvent $event)
{
}

/**
* {@inheritdoc}
*/
protected function outputNodeChecked(NodeChecked $event)
{
}

/**
* {@inheritdoc}
*/
protected function outputRuleChecked(RuleCheckedEvent $event)
{
}

/**
* {@inheritdoc}
*/
protected function outputPostRulesChecked(PostRulesCheckedEvent $event)
{
$errorCount = 0;
$warningCount = 0;

foreach ($event->getViolations() as $violation) {
if (ViolationInterface::TYPE_ERROR === $violation->getType()) {
$errorCount++;
} else {
$warningCount++;
}
}

echo sprintf("%d/%d", $errorCount, $warningCount);
}
}

0 comments on commit 4f23b4e

Please sign in to comment.