Skip to content

Commit 657a498

Browse files
author
Benoît Burnichon
committed
PHPCS of TwigFileExtractor
1 parent acc43e0 commit 657a498

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Diff for: Translation/Extractor/File/TwigFileExtractor.php

+23-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ class TwigFileExtractor implements FileVisitorInterface, \Twig_NodeVisitorInterf
3333
* @var \SplFileInfo
3434
*/
3535
private $file;
36+
37+
/**
38+
* @var MessageCatalogue
39+
*/
3640
private $catalogue;
41+
42+
/**
43+
* @var \Twig_NodeTraverser
44+
*/
3745
private $traverser;
46+
47+
/**
48+
* @var \Twig_NodeInterface[]
49+
*/
3850
private $stack = array();
39-
private $stackCount = 0;
4051

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

93104
for ($i=count($this->stack)-2; $i>=0; $i-=1) {
94-
if (!$this->stack[$i] instanceof \Twig_Node_Expression_Filter) {
105+
$currentNode = $this->stack[$i];
106+
107+
if (!$currentNode instanceof \Twig_Node_Expression_Filter) {
95108
break;
96109
}
97110

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

178+
/**
179+
* Inject a Logger
180+
*
181+
* @param LoggerInterface $logger
182+
*/
165183
public function setLogger(LoggerInterface $logger)
166184
{
167185
$this->logger = $logger;
@@ -170,6 +188,7 @@ public function setLogger(LoggerInterface $logger)
170188
/**
171189
* @param \Twig_Node $node
172190
* @return bool
191+
* @throws RuntimeException
173192
*/
174193
private function checkNodeIsConstant(\Twig_Node $node)
175194
{

0 commit comments

Comments
 (0)