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); } }
Applied Rules:
Not a change you expect?
rector.php