driftingly / rector-laravel

Rector upgrades rules for Laravel
http://getrector.org
MIT License
540 stars 52 forks source link

Adds UseComponentPropertyWithinCommandsRector rule #140

Closed peterfox closed 1 year ago

peterfox commented 1 year ago

Adds a new rule to refactor commands and make use of the component property that handles using Termwind output like most of the Laravel commands have used.

UseComponentPropertyWithinCommandsRector

Use $this->components property within commands

 use Illuminate\Console\Command;

 class CommandWithComponents extends Command
 {
     public function handle()
     {
-        $this->ask('What is your name?');
-        $this->line('A line!');
-        $this->info('Info!');
-        $this->error('Error!');
+        $this->components->ask('What is your name?');
+        $this->components->line('A line!');
+        $this->components->info('Info!');
+        $this->components->error('Error!');
     }
 }

Will only affect inheriting from Console commands and will only do the specific methods.