1010use ReflectionClass ;
1111use Twig \Environment ;
1212use Twig \Node \Expression \ArrowFunctionExpression ;
13+ use Twig \Node \Expression \ConstantExpression ;
1314use Twig \Node \Expression \GetAttrExpression ;
15+ use Twig \Node \Expression \NameExpression ;
1416use Twig \Node \Expression \Variable \ContextVariable ;
1517use Twig \Node \ForNode ;
1618use Twig \Node \MacroNode ;
@@ -73,11 +75,12 @@ public function enterNode(Node $node, Environment $env): Node
7375 if (
7476 $ node instanceof GetAttrExpression &&
7577 $ node ->getAttribute ('type ' ) !== Template::ARRAY_CALL &&
76- ($ nameNode = $ node ->getNode ('node ' )) instanceof ContextVariable
78+ ($ nameNode = $ node ->getNode ('node ' )) instanceof ContextVariable &&
79+ ($ attributeNode = $ node ->getNode ('attribute ' )) instanceof ConstantExpression
7780 ) {
7881 $ location = new NodeLocation ($ node );
7982 $ name = $ nameNode ->getAttribute ('name ' );
80- $ attribute = $ node -> getNode ( ' attribute ' ) ->getAttribute ('value ' );
83+ $ attribute = $ attributeNode ->getAttribute ('value ' );
8184 $ this ->checkOperation ($ name , $ attribute , $ location );
8285 }
8386
@@ -97,7 +100,7 @@ private function checkOperation(string $name, string $attribute, NodeLocation $l
97100 if (str_starts_with ($ type , '? ' )) {
98101 $ type = substr ($ type , 1 );
99102 }
100-
103+
101104 if (in_array ($ type , self ::UNSUPPORTED_TYPES )) {
102105 trigger_error (
103106 sprintf ('Invalid dot operation on unsupported type \'%s \' (at %s) ' , $ type , $ location ),
@@ -187,7 +190,7 @@ private function extractScopedVariableTypes(ArrowFunctionExpression|ForNode|SetN
187190 }
188191
189192 if ($ node instanceof ForNode) {
190- $ keyName = $ node ->getNode ('key_target ' ) ->getAttribute ('name ' );
193+ $ keyName = $ node ->getNode ('key_target ' )->getAttribute ('name ' );
191194 $ valueName = $ node ->getNode ('value_target ' )->getAttribute ('name ' );
192195
193196 $ keyType = $ valueType = 'mixed ' ;
0 commit comments