mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 20:16:45 +00:00
Replace return; yield with yield from []
This has the same effect, but looks less hacky and makes PHPStan happy. https://phpstan.org/r/df7fcc88-1df8-428e-b675-5dc6965c34d6 Previously this was needed to work properly with output capturing.
This commit is contained in:
@@ -42,7 +42,7 @@ class BlockNode extends Node
|
||||
|
||||
$compiler
|
||||
->subcompile($this->getNode('body'))
|
||||
->write("return; yield '';\n") // needed when body doesn't yield anything
|
||||
->write("yield from [];\n")
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
;
|
||||
|
||||
@@ -39,7 +39,7 @@ class CaptureNode extends Node
|
||||
->raw("(function () use (&\$context, \$macros, \$blocks) {\n")
|
||||
->indent()
|
||||
->subcompile($this->getNode('body'))
|
||||
->write("return; yield '';\n")
|
||||
->write("yield from [];\n")
|
||||
->outdent()
|
||||
->write('})()')
|
||||
;
|
||||
|
||||
@@ -353,7 +353,7 @@ final class ModuleNode extends Node
|
||||
$compiler->subcompile($this->getNode('display_end'));
|
||||
|
||||
if (!$this->hasNode('parent')) {
|
||||
$compiler->write("return; yield '';\n"); // ensure at least one yield call even for templates with no output
|
||||
$compiler->write("yield from [];\n");
|
||||
}
|
||||
|
||||
$compiler
|
||||
|
||||
@@ -40,7 +40,7 @@ public function block_foo(array \$context, array \$blocks = []): iterable
|
||||
{
|
||||
\$macros = \$this->macros;
|
||||
yield "foo";
|
||||
return; yield '';
|
||||
yield from [];
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
|
||||
@@ -59,7 +59,7 @@ public function macro_foo(\$__foo__ = null, \$__bar__ = "Foo", ...\$__varargs__)
|
||||
|
||||
return ('' === \$tmp = implode('', iterator_to_array((function () use (&\$context, \$macros, \$blocks) {
|
||||
yield "foo";
|
||||
return; yield '';
|
||||
yield from [];
|
||||
})(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
|
||||
}
|
||||
EOF
|
||||
@@ -81,7 +81,7 @@ public function macro_foo(\$__foo__ = null, \$__bar__ = "Foo", ...\$__varargs__)
|
||||
|
||||
return ('' === \$tmp = \\Twig\\Extension\\CoreExtension::captureOutput((function () use (&\$context, \$macros, \$blocks) {
|
||||
yield "foo";
|
||||
return; yield '';
|
||||
yield from [];
|
||||
})())) ? '' : new Markup(\$tmp, \$this->env->getCharset());
|
||||
}
|
||||
EOF
|
||||
|
||||
@@ -103,7 +103,7 @@ class __TwigTemplate_%x extends Template
|
||||
\$macros = \$this->macros;
|
||||
// line 1
|
||||
yield "foo";
|
||||
return; yield '';
|
||||
yield from [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ EOF
|
||||
// line 1
|
||||
\$context["foo"] = ('' === \$tmp = implode('', iterator_to_array((function () use (&\$context, \$macros, \$blocks) {
|
||||
yield "foo";
|
||||
return; yield '';
|
||||
yield from [];
|
||||
})(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
@@ -67,7 +67,7 @@ EOF
|
||||
// line 1
|
||||
$context["foo"] = ('' === $tmp = \Twig\Extension\CoreExtension::captureOutput((function () use (&$context, $macros, $blocks) {
|
||||
yield "foo";
|
||||
return; yield '';
|
||||
yield from [];
|
||||
})())) ? '' : new Markup($tmp, $this->env->getCharset());
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
|
||||
Reference in New Issue
Block a user