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

 <?php
 
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 
  final class SomeController extends AbstractController
  {
-     #[Route('/some-path/{from}/{to}', name: 'some_name')]
-     public function someAction(
-        \DateTimeImmutable $from,
-        \DateTimeImmutable $to,
-     ) {
-         return $this->render('template.html.twig', ['from' => $from, 'to' => $to]);
+     public function __construct(private readonly \DateTimeImmutable $from, private readonly \DateTimeImmutable $to)
+     {
+     }
+     #[Route('/some-path/{from}/{to}', name: 'some_name')]
+     public function someAction()
+     {
+         return $this->render('template.html.twig', ['from' => $this->from, 'to' => $this->to]);
      }
  }
PHP snippet to change

Applied Rules:

Not a change you expect?

Config  rector.php
Rector version: b09565 - released at 2026-05-25 06:37