Repository: FriendsOfPHP/PHP-CS-Fixer (php)

Issue:
Bug in `static_lambda` rule
Hi,

It looks like the `static_lambda` rule is not working correctly in this case. Even if the case is totally unlikely to happen, it should not add the `static` keyword in the front.

```php
<?php

declare(strict_types=1);

namespace App;

class Foo
{
    public function foo()
    {
        return array_map(
            fn ($item) => $this,
            []
        );
    }
}

Current result:

```
--- /home/devlin/Code/XXX/src/Foo.php
+++ /home/devlin/Code/XXX/src/Foo.php
@@ -1,5 +1,12 @@
 <?php
 
 declare(strict_types=1);
 
 namespace App;
@@ -9,7 +16,7 @@
     public function foo()
     {
         return array_map(
-            fn ($item) => $this,
+            static fn ($item) => $this,
             []
         );
     }
```

Expected result:

It should not add the `static` keyword.

Pull request description:
bug: Fix #6439 issue in `StaticLambda` fixer
This PR fix #6439 

Patch:
diff --git a/src/Fixer/FunctionNotation/StaticLambdaFixer.php b/src/Fixer/FunctionNotation/StaticLambdaFixer.php
index 211f7c946..d844cfe82 100644
--- a/src/Fixer/FunctionNotation/StaticLambdaFixer.php
+++ b/src/Fixer/FunctionNotation/StaticLambdaFixer.php
@@ -134,7 +134,7 @@ private function findExpressionEnd(Tokens $tokens, int $index): int
      */
     private function hasPossibleReferenceToThis(Tokens $tokens, int $startIndex, int $endIndex): bool
     {
-        for ($i = $startIndex; $i < $endIndex; ++$i) {
+        for ($i = $startIndex; $i <= $endIndex; ++$i) {
             if ($tokens[$i]->isGivenKind(T_VARIABLE) && '$this' === strtolower($tokens[$i]->getContent())) {
                 return true; // directly accessing '$this'
             }


Test patch:
diff --git a/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php b/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php
index bda80a6b3..93dafb6a3 100644
--- a/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php
+++ b/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php
@@ -302,6 +302,20 @@ public function foo()
                     }
                 }',
             ],
+            [
+                '<?php
+                    class B
+                    {
+                        public function C()
+                        {
+                            return array_map(
+                                fn () => $this,
+                                []
+                            );
+                        }
+                    }
+                ',
+            ],
         ];
     }
 }