Skip to content

Commit

Permalink
[console] Fix generated lines of code feature. (#242)
Browse files Browse the repository at this point in the history
* [console] Fix generated lines of code feature.

* [console] Fix generated lines of code feature.
  • Loading branch information
jmolivas committed Oct 28, 2017
1 parent fa1da99 commit 0f0c82e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ private function registerEvents()
$this->container->get('console.translator_manager')
)
);

$dispatcher->addSubscriber(
new ShowGenerateCountCodeLinesListener(
$this->container->get('console.translator_manager'),
$this->container->get('console.count_code_lines')
)
);
Expand Down
26 changes: 21 additions & 5 deletions src/EventSubscriber/ShowGenerateCountCodeLinesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

namespace Drupal\Console\Core\EventSubscriber;

use Drupal\Console\Core\Utils\CountCodeLines;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Console\Command\Command;
use Drupal\Console\Core\Utils\TranslatorManagerInterface;
use Drupal\Console\Core\Utils\CountCodeLines;
use Drupal\Console\Core\Style\DrupalStyle;

/**
Expand All @@ -27,33 +28,48 @@ class ShowGenerateCountCodeLinesListener implements EventSubscriberInterface
*/
protected $countCodeLines;

/**
* @var TranslatorManagerInterface
*/
protected $translator;

/**
* ShowGenerateChainListener constructor.
*
* @param TranslatorManagerInterface $translator
*
* @param CountCodeLines $countCodeLines
*
*/
public function __construct(
TranslatorManagerInterface $translator,
CountCodeLines $countCodeLines
) {
$this->translator = $translator;
$this->countCodeLines = $countCodeLines;
}

/**
* @param ConsoleTerminateEvent $event
*/
public function showGenerateCountLines(ConsoleTerminateEvent $event)
public function showGenerateCountCodeLines(ConsoleTerminateEvent $event)
{
if ($event->getExitCode() != 0) {
return;
}

/* @var Command $command */
$command = $event->getCommand();
/* @var DrupalStyle $io */
$io = new DrupalStyle($event->getInput(), $event->getOutput());

$countCodeLines = $this->countCodeLines->getCountCodeLines();
$io->writeln($countCodeLines);
if ($countCodeLines > 0) {
$io->commentBlock(
sprintf(
$this->translator->trans('application.messages.lines-code'),
$countCodeLines
)
);
}
}

/**
Expand Down

0 comments on commit 0f0c82e

Please sign in to comment.