Skip to content

Commit

Permalink
PHPCS of TwigFileExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoît Burnichon committed Mar 25, 2016
1 parent acc43e0 commit 657a498
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Translation/Extractor/File/TwigFileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,21 @@ class TwigFileExtractor implements FileVisitorInterface, \Twig_NodeVisitorInterf
* @var \SplFileInfo
*/
private $file;

/**
* @var MessageCatalogue
*/
private $catalogue;

/**
* @var \Twig_NodeTraverser
*/
private $traverser;

/**
* @var \Twig_NodeInterface[]
*/
private $stack = array();
private $stackCount = 0;

/**
* @var LoggerInterface
Expand Down Expand Up @@ -91,13 +102,15 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
$message->addSource(new FileSource((string) $this->file, $node->getLine()));

for ($i=count($this->stack)-2; $i>=0; $i-=1) {
if (!$this->stack[$i] instanceof \Twig_Node_Expression_Filter) {
$currentNode = $this->stack[$i];

if (!$currentNode instanceof \Twig_Node_Expression_Filter) {
break;
}

$name = $this->stack[$i]->getNode('filter')->getAttribute('value');
$name = $currentNode->getNode('filter')->getAttribute('value');
if ('desc' === $name || 'meaning' === $name) {
$arguments = $this->stack[$i]->getNode('arguments');
$arguments = $currentNode->getNode('arguments');
if (!$arguments->hasNode(0)) {
throw new RuntimeException(sprintf('The "%s" filter requires exactly one argument, the description text.', $name));
}
Expand Down Expand Up @@ -162,6 +175,11 @@ public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env)
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue) { }
public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, array $ast) { }

/**
* Inject a Logger
*
* @param LoggerInterface $logger
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
Expand All @@ -170,6 +188,7 @@ public function setLogger(LoggerInterface $logger)
/**
* @param \Twig_Node $node
* @return bool
* @throws RuntimeException
*/
private function checkNodeIsConstant(\Twig_Node $node)
{
Expand Down

0 comments on commit 657a498

Please sign in to comment.