Fix isset in ForLoopNode

Even though the code works perfectly fine, PHPStan doesn't understand it.

Since we want to work with `revindex` and `revindex0`, we can better check for their
existence, instead of `length`.
This commit is contained in:
Ruud Kamphuis
2024-09-06 09:42:11 +02:00
parent b1cdda25c6
commit 2b887e64d5
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ class ForLoopNode extends Node
->write("++\$context['loop']['index0'];\n")
->write("++\$context['loop']['index'];\n")
->write("\$context['loop']['first'] = false;\n")
->write("if (isset(\$context['loop']['length'])) {\n")
->write("if (isset(\$context['loop']['revindex0'], \$context['loop']['revindex'])) {\n")
->indent()
->write("--\$context['loop']['revindex0'];\n")
->write("--\$context['loop']['revindex'];\n")
+3 -3
View File
@@ -101,7 +101,7 @@ foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
++\$context['loop']['index0'];
++\$context['loop']['index'];
\$context['loop']['first'] = false;
if (isset(\$context['loop']['length'])) {
if (isset(\$context['loop']['revindex0'], \$context['loop']['revindex'])) {
--\$context['loop']['revindex0'];
--\$context['loop']['revindex'];
\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];
@@ -143,7 +143,7 @@ foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
++\$context['loop']['index0'];
++\$context['loop']['index'];
\$context['loop']['first'] = false;
if (isset(\$context['loop']['length'])) {
if (isset(\$context['loop']['revindex0'], \$context['loop']['revindex'])) {
--\$context['loop']['revindex0'];
--\$context['loop']['revindex'];
\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];
@@ -187,7 +187,7 @@ foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
++\$context['loop']['index0'];
++\$context['loop']['index'];
\$context['loop']['first'] = false;
if (isset(\$context['loop']['length'])) {
if (isset(\$context['loop']['revindex0'], \$context['loop']['revindex'])) {
--\$context['loop']['revindex0'];
--\$context['loop']['revindex'];
\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];