Find the best Rector rule to solve your problem. Searching through 676 rules.

Found 4 rules:

CommandHelpToAttributeRector

Moves $this->setHelp() to the "help" named argument of #[AsCommand]

 use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Command\Command;

-#[AsCommand(name: 'app:some')]
+#[AsCommand(name: 'app:some', help: <<<'TXT'
+Some help text
+TXT)]
 final class SomeCommand extends Command
 {
-    protected function configure(): void
-    {
-        $this->setHelp('Some help text');
-    }
 }

GetFiltersToAsTwigFilterAttributeRector

Changes getFilters() in TwigExtension to #[TwigFilter] marker attribute above function

 use Twig\Extension\AbstractExtension;
+use Twig\Attribute\AsTwigFilter;

 class SomeClass extends AbstractExtension
 {
-    public function getFilters()
-    {
-        return [
-            new \Twig\TwigFilter('filter_name', [$this, 'localMethod']),
-        ];
-    }
-
+    #[TwigFilter('filter_name')]
     public function localMethod($value)
     {
         return $value;
     }
 }

GetFunctionsToAsTwigFunctionAttributeRector

Changes getFunctions() in TwigExtension to #[AsTwigFunction] marker attribute above local class method

 use Twig\Extension\AbstractExtension;
+use Twig\Attribute\AsTwigFunction;

 class SomeClass extends AbstractExtension
 {
-    public function getFunctions()
-    {
-        return [
-            new \Twig\TwigFunction('function_name', [$this, 'localMethod']),
-        ];
-    }
-
+    #[AsTwigFunction('function_name')]
     public function localMethod($value)
     {
         return $value;
     }
 }

InvokableCommandInputAttributeRector

Change Symfony Command with execute() + configure() to __invoke() with attributes

-use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Command\Argument;
+use Symfony\Component\Console\Command\Option;

-#[AsCommand(name: 'some_name')]
-final class SomeCommand extends Command
+final class SomeCommand
 {
-    public function configure()
-    {
-        $this->addArgument('argument', InputArgument::REQUIRED, 'Argument description');
-        $this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
-    }
-
-    public function execute(InputInterface $input, OutputInterface $output)
-    {
-        $someArgument = $input->getArgument('argument');
-        $someOption = $input->getOption('option');
+    public function __invoke(
+        #[Argument(name: 'argument', mode: Argument::REQUIRED, description: 'Argument description')]
+        string $argument,
+        #[Option]
+        bool $option = false,
+    ) {
+        $someArgument = $argument;
+        $someOption = $option;

         // ...

         return 1;
     }
 }