Skip to content

Commit

Permalink
Fix isset in ForLoopNode
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ruudk committed Sep 6, 2024
1 parent b1cdda2 commit 2b887e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Node/ForLoopNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function compile(Compiler $compiler): void
->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")
Expand Down
6 changes: 3 additions & 3 deletions tests/Node/ForTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function provideTests(): iterable
++\$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'];
Expand Down Expand Up @@ -143,7 +143,7 @@ public static function provideTests(): iterable
++\$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'];
Expand Down Expand Up @@ -187,7 +187,7 @@ public static function provideTests(): iterable
++\$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'];
Expand Down

0 comments on commit 2b887e6

Please # to comment.