Run Rector on your code to see what it can do for you:

 <?php
 
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 
 class ExampleController extends AbstractController
 {
-    public function example(Foo $foo)
-    {
-        $this->problematic($foo);
+    public function __construct(private readonly \Foo $foo)
+    {
+    }
+    public function example()
+    {
+        $this->problematic($this->foo);
     }
     
-    public function problematic(Foo $foo, ?string $optional = "test")
+    public function problematic(?string $optional = "test")
     {
-        dump($foo);
+        dump($this->foo);
         dump($optional);
     }
 }
PHP snippet to change

Applied Rules:

Not a change you expect?

Config  rector.php
Rector version: 3a3942 - released at 2026-03-17 17:46