diff --git a/Translation/Extractor/File/TwigFileExtractor.php b/Translation/Extractor/File/TwigFileExtractor.php index a77e82fb..47c6e661 100644 --- a/Translation/Extractor/File/TwigFileExtractor.php +++ b/Translation/Extractor/File/TwigFileExtractor.php @@ -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 @@ -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)); } @@ -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; @@ -170,6 +188,7 @@ public function setLogger(LoggerInterface $logger) /** * @param \Twig_Node $node * @return bool + * @throws RuntimeException */ private function checkNodeIsConstant(\Twig_Node $node) {