ConstructorReadonlyAssignToDefaultRector
Move a constant constructor assignment of a readonly property to a property default value
final class SomeClass
{
- public readonly int $number;
+ public readonly int $number = 100;
public function __construct()
{
- $this->number = 100;
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\Php86\Rector\Class_\ConstructorReadonlyAssignToDefaultRector;
return RectorConfig::configure()
->withRules([
ConstructorReadonlyAssignToDefaultRector::class,
]);