@@ -33,10 +33,21 @@ class TwigFileExtractor implements FileVisitorInterface, \Twig_NodeVisitorInterf
33
33
* @var \SplFileInfo
34
34
*/
35
35
private $ file ;
36
+
37
+ /**
38
+ * @var MessageCatalogue
39
+ */
36
40
private $ catalogue ;
41
+
42
+ /**
43
+ * @var \Twig_NodeTraverser
44
+ */
37
45
private $ traverser ;
46
+
47
+ /**
48
+ * @var \Twig_NodeInterface[]
49
+ */
38
50
private $ stack = array ();
39
- private $ stackCount = 0 ;
40
51
41
52
/**
42
53
* @var LoggerInterface
@@ -91,13 +102,15 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
91
102
$ message ->addSource (new FileSource ((string ) $ this ->file , $ node ->getLine ()));
92
103
93
104
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) {
95
108
break ;
96
109
}
97
110
98
- $ name = $ this -> stack [ $ i ] ->getNode ('filter ' )->getAttribute ('value ' );
111
+ $ name = $ currentNode ->getNode ('filter ' )->getAttribute ('value ' );
99
112
if ('desc ' === $ name || 'meaning ' === $ name ) {
100
- $ arguments = $ this -> stack [ $ i ] ->getNode ('arguments ' );
113
+ $ arguments = $ currentNode ->getNode ('arguments ' );
101
114
if (!$ arguments ->hasNode (0 )) {
102
115
throw new RuntimeException (sprintf ('The "%s" filter requires exactly one argument, the description text. ' , $ name ));
103
116
}
@@ -162,6 +175,11 @@ public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env)
162
175
public function visitFile (\SplFileInfo $ file , MessageCatalogue $ catalogue ) { }
163
176
public function visitPhpFile (\SplFileInfo $ file , MessageCatalogue $ catalogue , array $ ast ) { }
164
177
178
+ /**
179
+ * Inject a Logger
180
+ *
181
+ * @param LoggerInterface $logger
182
+ */
165
183
public function setLogger (LoggerInterface $ logger )
166
184
{
167
185
$ this ->logger = $ logger ;
@@ -170,6 +188,7 @@ public function setLogger(LoggerInterface $logger)
170
188
/**
171
189
* @param \Twig_Node $node
172
190
* @return bool
191
+ * @throws RuntimeException
173
192
*/
174
193
private function checkNodeIsConstant (\Twig_Node $ node )
175
194
{
0 commit comments