From 2b887e64d5e823376d965e500604fc31e3c8aae6 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Fri, 6 Sep 2024 09:42:11 +0200 Subject: [PATCH] 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`. --- src/Node/ForLoopNode.php | 2 +- tests/Node/ForTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Node/ForLoopNode.php b/src/Node/ForLoopNode.php index 3e044bbb09f..1f0a4f32134 100644 --- a/src/Node/ForLoopNode.php +++ b/src/Node/ForLoopNode.php @@ -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") diff --git a/tests/Node/ForTest.php b/tests/Node/ForTest.php index c4c11253d00..047c2a1092d 100644 --- a/tests/Node/ForTest.php +++ b/tests/Node/ForTest.php @@ -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']; @@ -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']; @@ -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'];