Find the best Rector rule to solve your problem. Searching through 778 rules.
Found 5 rules:
Reverse conditionable method calls
-$conditionable->when(!$condition, function () {});
+$conditionable->unless($condition, function () {});
Replace magical call on $this->app["something"] to standalone type assign variable
class SomeClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function run()
{
- $validator = $this->app['validator']->make('...');
+ /** @var \Illuminate\Validation\Factory $validationFactory */
+ $validationFactory = $this->app['validator'];
+ $validator = $validationFactory->make('...');
}
}
Replace app environment comparison with parameter or method call
-$app->environment() === 'local';
-$app->environment() !== 'production';
-$app->environment() === 'testing';
-in_array($app->environment(), ['local', 'testing']);
+$app->isLocal();
+! $app->isProduction();
+$app->environment('testing');
+$app->environment(['local', 'testing']);
Apply default instead of null coalesce
-custom_helper('app.name') ?? 'Laravel';
+custom_helper('app.name', 'Laravel');
Makes Model attributes and scopes protected
class User extends Model
{
- public function foo(): Attribute
+ protected function foo(): Attribute
{
return Attribute::get(fn () => $this->bar);
}
#[Scope]
- public function active(Builder $query): Builder
+ protected function active(Builder $query): Builder
{
return $query->where('active', true);
}
}