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

Found 6 rules:

CommandDefaultNameAndDescriptionToAsCommandAttributeRector

Replace getDefaultName() and getDefaultDescription() by #[AsCommand] attribute

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

+#[AsCommand(
+    name: 'app:some-command',
+    description: 'This is some command description'
+)]
 final class SomeCommand extends Command
 {
-    public static function getDefaultName(): string
-    {
-        return 'app:some-command';
-    }
-
-    public static function getDefaultDescription(): string
-    {
-        return 'This is some command description';
-    }
 }

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;
 use Twig\Environment;

 class SomeClass extends AbstractExtension
 {
-    public function getFilters()
-    {
-        return [
-            new \Twig\TwigFilter('filter_name', [$this, 'localMethod', 'needs_environment' => true]),
-        ];
-    }
-
+    #[TwigFilter('filter_name', needsEnvironment: true)]
     public function localMethod(Environment $env, $value)
     {
         return $value;
     }
 }

ConstraintOptionsToNamedArgumentsRector

Refactor Symfony constraints using array options to named arguments syntax for better readability and type safety.

 use Symfony\Component\Validator\Constraints\NotBlank;

-$constraint = new NotBlank(['message' => 'This field should not be blank.']);
+$constraint = new NotBlank(message: 'This field should not be blank.');

GetFunctionsToAsTwigFunctionAttributeRector

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

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

-class SomeClass extends AbstractExtension
+class SomeClass
 {
-    public function getFunctions()
-    {
-        return [
-            new \Twig\TwigFunction('function_name', [$this, 'localMethod', 'needs_environment' => true]),
-        ];
-    }
-
+    #[AsTwigFunction(name: 'function_name', needsEnvironment: true)]
     public function localMethod(Environment $env, $value)
     {
         return $value;
     }
 }

AddVoteArgumentToVoteOnAttributeRector

Adds a new $voter argument in protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token, ?Vote $vote = null): bool

 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
 use Symfony\Component\Security\Core\Authorization\Voter\Voter;

 final class MyVoter extends Voter
 {
     protected function supports(string $attribute, mixed $subject): bool
     {
         return true;
     }

-    protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
+    protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token, ?\Symfony\Component\Security\Core\Authorization\Voter\Vote $vote = null): bool
     {
         return true;
     }
 }