CommandPropertyToAsCommandAttributeRector
Changes the name/signature and description properties of a console command to the AsCommand attribute
use Illuminate\Console\Command;
+use Symfony\Component\Console\Attribute\AsCommand;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+#[AsCommand(name: 'mail:send', description: 'Send the queued emails')]
class SendEmails extends Command
{
- protected $signature = 'mail:send {user} {--queue}';
+ protected function getArguments(): array
+ {
+ return [new InputArgument('user', InputArgument::REQUIRED)];
+ }
- protected $description = 'Send the queued emails';
+ protected function getOptions(): array
+ {
+ return [new InputOption('queue', null, InputOption::VALUE_NONE)];
+ }
}
Configure your rector.php:
<?php
use RectorLaravel\Rector\Class_\CommandPropertyToAsCommandAttributeRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
CommandPropertyToAsCommandAttributeRector::class,
]);
PACKAGE:
laravel/framework >=9.0