Add property type based on strict setter and getter method
final class SomeClass
{
- private $name = 'John';
+ private string $name = 'John';
public function setName(string $name): void
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector;
return RectorConfig::configure()
->withRules([
PropertyTypeFromStrictSetterGetterRector::class,
]);