Call For recurseFunc inline

After https://github.com/phpstan/phpstan-src/pull/3554 this now makes it easier for PHPStan to
understands what's going on.

This will allow TwigStan to handle for loops in v4.
This commit is contained in:
Ruud Kamphuis
2024-10-17 12:28:35 +02:00
parent eca86f1a32
commit e4f6bf8e8a
2 changed files with 12 additions and 18 deletions
+2 -3
View File
@@ -49,7 +49,7 @@ class ForNode extends Node
->write("\$$iteratorVar = new \Twig\Runtime\LoopIterator(")
->subcompile($this->getNode('seq'))
->raw(");\n")
->write("\$$functionVar = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {\n")
->write("yield from (\$$functionVar = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {\n")
->indent()
->write("\$macros = \$this->macros;\n")
->write("\$parent = \$context;\n")
@@ -94,8 +94,7 @@ class ForNode extends Node
$compiler
->write("yield from [];\n")
->outdent()
->write("};\n")
->write("yield from \$$functionVar(\$$iteratorVar, \$context, \$blocks, \$$functionVar, 0);\n")
->write("})(\$$iteratorVar, \$context, \$blocks, \$$functionVar, 0);\n")
;
}
}
+10 -15
View File
@@ -68,7 +68,7 @@ class ForTest extends NodeTestCase
$tests[] = [$node, <<<EOF
// line 1
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$itemsGetter});
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
\$macros = \$this->macros;
\$parent = \$context;
foreach (\$iterator as \$context["key"] => \$context["item"]) {
@@ -77,8 +77,7 @@ class ForTest extends NodeTestCase
unset(\$context['key'], \$context['item']);
\$context = array_intersect_key(\$context, \$parent) + \$parent;
yield from [];
};
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
EOF
];
@@ -93,7 +92,7 @@ EOF
$tests[] = [$node, <<<EOF
// line 1
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$valuesGetter});
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
\$macros = \$this->macros;
\$parent = \$context;
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
@@ -103,8 +102,7 @@ EOF
unset(\$context['k'], \$context['v'], \$context['loop']);
\$context = array_intersect_key(\$context, \$parent) + \$parent;
yield from [];
};
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
EOF
];
@@ -119,7 +117,7 @@ EOF
$tests[] = [$node, <<<EOF
// line 1
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$valuesGetter});
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
\$macros = \$this->macros;
\$parent = \$context;
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
@@ -129,8 +127,7 @@ EOF
unset(\$context['k'], \$context['v'], \$context['loop']);
\$context = array_intersect_key(\$context, \$parent) + \$parent;
yield from [];
};
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
EOF
];
@@ -146,7 +143,7 @@ EOF
$tests[] = [$node, <<<EOF
// line 1
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$valuesGetter});
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
\$macros = \$this->macros;
\$parent = \$context;
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
@@ -161,8 +158,7 @@ EOF
unset(\$context['k'], \$context['v'], \$context['loop']);
\$context = array_intersect_key(\$context, \$parent) + \$parent;
yield from [];
};
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
EOF
];
@@ -173,7 +169,7 @@ EOF
$tests[] = [$node, <<<EOF
// line 1
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$itemsGetter});
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
\$macros = \$this->macros;
\$parent = \$context;
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
@@ -183,8 +179,7 @@ EOF
unset(\$context['_key'], \$context['item'], \$context['loop']);
\$context = array_intersect_key(\$context, \$parent) + \$parent;
yield from [];
};
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
EOF
, $env];