Find a Rector rule

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

Found 6 rules, grouped by set: Clear

laravel/framework 11 6 matches

Changes model newCollection method to use the CollectedBy attribute

 use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\Collection;
 use App\Collections\UserCollection;
+use Illuminate\Database\Eloquent\Attributes\CollectedBy;

+#[CollectedBy(UserCollection::class)]
 class User extends Model
 {
-    /**
-     * @param  array<int, \Illuminate\Database\Eloquent\Model>  $models
-     * @return \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model>
-     */
-    public function newCollection(array $models = []): Collection
-    {
-        return new UserCollection($models);
-    }
 }

Changes the deleteWhenMissingModels property to use the DeleteWhenMissingModels attribute

 use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\Attributes\DeleteWhenMissingModels;

+#[DeleteWhenMissingModels]
 final class ProcessPodcast implements ShouldQueue
 {
-    public $deleteWhenMissingModels = true;
 }

refactors calls with the pre Laravel 11 methods for blueprint geometry columns

-$blueprint->point('coordinates')->spatialIndex();
+$blueprint->geometry('coordinates', 'point')->spatialIndex();
AssertSeeToAssertSeeHtmlRector laravel/framework >=11.0

Replace assertSee with assertSeeHtml when testing HTML with escape set to false

-$response->assertSee("<li>foo</li>", false);
+$response->assertSeeHtml("<li>foo</li>");

Replace Dispatchable, InteractsWithQueue, Queueable, and SerializesModels traits with the Queueable trait

 use Illuminate\Bus\Queueable;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;

 class SomeJob
 {
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+    use \Illuminate\Foundation\Queue\Queueable;
 }

Refactor Model $casts property with casts() method

 use Illuminate\Database\Eloquent\Model;

 class Person extends Model
 {
-    protected $casts = [
-        'age' => 'integer',
-    ];
+    protected function casts(): array
+    {
+        return [
+            'age' => 'integer',
+        ];
+    }
 }