Find a Rector rule

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

Found 10 rules, grouped by set: Clear

Not in a set 4 matches

Changes action in rule definitions from string to array notation.

-$router->get('/user', 'UserController@get');
+$router->get('/user', ['uses => 'UserController@get']);

Changes the string or class const used for a service container make call

-app('encrypter')->encrypt('...');
-\Illuminate\Support\Facades\Application::make('encrypter')->encrypt('...');
+app(Illuminate\Contracts\Encryption\Encrypter::class)->encrypt('...');
+\Illuminate\Support\Facades\Application::make(Illuminate\Contracts\Encryption\Encrypter::class)->encrypt('...');

Convert to where comparison to whereNull method call

-$query->where('foo', null);
-$query->where('foo', '=', null);
-$query->where('foo');
-$query->where('foo', '!=', null);
+$query->whereNull('foo');
+$query->whereNull('foo');
+$query->whereNull('foo');
+$query->whereNotNull('foo');

Changes middlewares from rule definitions from string to array notation.

-$router->get('/user', ['middleware => 'test']);
-$router->post('/user', ['middleware => 'test|authentication']);
+$router->get('/user', ['middleware => ['test']]);
+$router->post('/user', ['middleware => ['test', 'authentication']]);
laravel/framework 10 1 match

Convert DB Expression __toString() calls to getValue() method calls.

 use Illuminate\Support\Facades\DB;

-$string = DB::raw('select 1')->__toString();
+$string = DB::raw('select 1')->getValue(DB::connection()->getQueryGrammar());
Collection 1 match

Use the base collection methods instead of their aliases.

 use Illuminate\Support\Collection;

 $collection = new Collection([0, 1, null, -1]);
-$collection->average();
-$collection->some(fn (?int $number): bool => is_null($number));
+$collection->avg();
+$collection->contains(fn (?int $number): bool => is_null($number));
Testing 1 match

Replace (new \Illuminate\Testing\TestResponse)->assertStatus(200) with (new \Illuminate\Testing\TestResponse)->assertOk()

 class ExampleTest extends \Illuminate\Foundation\Testing\TestCase
 {
     public function testFoo()
     {
-        $this->get('/')->assertStatus(200);
-        $this->get('/')->assertStatus(201);
-        $this->get('/')->assertStatus(202);
-        $this->get('/')->assertStatus(204);
-        $this->get('/')->assertStatus(301);
-        $this->get('/')->assertStatus(302);
-        $this->get('/')->assertStatus(304);
-        $this->get('/')->assertStatus(307);
-        $this->get('/')->assertStatus(308);
-        $this->get('/')->assertStatus(400);
-        $this->get('/')->assertStatus(401);
-        $this->get('/')->assertStatus(402);
-        $this->get('/')->assertStatus(403);
-        $this->get('/')->assertStatus(404);
-        $this->get('/')->assertStatus(405);
-        $this->get('/')->assertStatus(406);
-        $this->get('/')->assertStatus(408);
-        $this->get('/')->assertStatus(409);
-        $this->get('/')->assertStatus(410);
-        $this->get('/')->assertStatus(415);
-        $this->get('/')->assertStatus(422);
-        $this->get('/')->assertStatus(424);
-        $this->get('/')->assertStatus(429);
-        $this->get('/')->assertStatus(500);
-        $this->get('/')->assertStatus(503);
+        $this->get('/')->assertOk();
+        $this->get('/')->assertCreated();
+        $this->get('/')->assertAccepted();
+        $this->get('/')->assertNoContent();
+        $this->get('/')->assertMovedPermanently();
+        $this->get('/')->assertFound();
+        $this->get('/')->assertNotModified();
+        $this->get('/')->assertTemporaryRedirect();
+        $this->get('/')->assertPermanentRedirect();
+        $this->get('/')->assertBadRequest();
+        $this->get('/')->assertUnauthorized();
+        $this->get('/')->assertPaymentRequired();
+        $this->get('/')->assertForbidden();
+        $this->get('/')->assertNotFound();
+        $this->get('/')->assertMethodNotAllowed();
+        $this->get('/')->assertNotAcceptable();
+        $this->get('/')->assertRequestTimeout();
+        $this->get('/')->assertConflict();
+        $this->get('/')->assertGone();
+        $this->get('/')->assertUnsupportedMediaType();
+        $this->get('/')->assertUnprocessable();
+        $this->get('/')->assertFailedDependency();
+        $this->get('/')->assertTooManyRequests();
+        $this->get('/')->assertInternalServerError();
+        $this->get('/')->assertServiceUnavailable();
     }
 }
laravel/framework 5 1 match

Refactor whereDate() queries to include both date and time comparisons with Carbon

 use Illuminate\Database\Query\Builder;

 final class SomeClass
 {
     public function run(Builder $query)
     {
-        $query->whereDate('created_at', '<', Carbon::now());
+        $dateTime = Carbon::now();
+        $query->whereDate('created_at', '<=', $dateTime);
+        $query->whereTime('created_at', '<=', $dateTime);
     }
 }
Code Quality 2 matches

Changes orderBy() to latest() or oldest()

 use Illuminate\Database\Eloquent\Builder;

 $column = 'tested_at';

-$builder->orderBy('created_at');
-$builder->orderBy('created_at', 'desc');
-$builder->orderBy('submitted_at');
-$builder->orderByDesc('submitted_at');
-$builder->orderBy($allowed_variable_name);
+$builder->oldest();
+$builder->latest();
+$builder->oldest('submitted_at');
+$builder->latest('submitted_at');
+$builder->oldest($allowed_variable_name);
 $builder->orderBy($unallowed_variable_name);
 $builder->orderBy('unallowed_column_name');

Reverse conditionable method calls

-$conditionable->when(!$condition, function () {});
+$conditionable->unless($condition, function () {});