Find the best Rector rule to solve your problem
Refactor MyCLabs enum fetch to Enum const
-$name = SomeEnum::VALUE()->getKey();
+$name = SomeEnum::VALUE;
Refactor Spatie enum method calls
-$value1 = SomeEnum::SOME_CONSTANT()->getValue();
-$value2 = SomeEnum::SOME_CONSTANT()->value;
-$name1 = SomeEnum::SOME_CONSTANT()->getName();
-$name2 = SomeEnum::SOME_CONSTANT()->name;
+$value1 = SomeEnum::SOME_CONSTANT->value;
+$value2 = SomeEnum::SOME_CONSTANT->value;
+$name1 = SomeEnum::SOME_CONSTANT->name;
+$name2 = SomeEnum::SOME_CONSTANT->name;
Change null to strict string defined function call args
class SomeClass
{
public function run()
{
- preg_split("#a#", null);
+ preg_split("#a#", '');
}
}
Decorate read-only property with readonly
attribute
class SomeClass
{
public function __construct(
- private string $name
+ private readonly string $name
) {
}
public function getName()
{
return $this->name;
}
}
Upgrade array callable to first class callable
final class SomeClass
{
public function run()
{
- $name = [$this, 'name'];
+ $name = $this->name(...);
}
public function name()
{
}
}
Refactor Spatie enum class to native Enum
-use \Spatie\Enum\Enum;
-
-/**
- * @method static self draft()
- * @method static self published()
- * @method static self archived()
- */
-class StatusEnum extends Enum
+enum StatusEnum : string
{
+ case DRAFT = 'draft';
+ case PUBLISHED = 'published';
+ case ARCHIVED = 'archived';
}
Refactor MyCLabs enum class to native Enum
-use MyCLabs\Enum\Enum;
-
-final class Action extends Enum
+enum Action : string
{
- private const VIEW = 'view';
- private const EDIT = 'edit';
+ case VIEW = 'view';
+ case EDIT = 'edit';
}
Replace property declaration of new state with direct new
class SomeClass
{
- private Logger $logger;
-
public function __construct(
- ?Logger $logger = null,
+ private Logger $logger = new NullLogger,
) {
- $this->logger = $logger ?? new NullLogger;
}
}
Add "never" return-type for methods that never return anything
final class SomeClass
{
- public function run()
+ public function run(): never
{
throw new InvalidException();
}
}