Find the best Rector rule to solve your problem
Add method return type based on strict ternary values
final class SomeClass
{
- public function getValue($number)
+ public function getValue($number): int
{
return $number ? 100 : 500;
}
}
Add strict return array type based on created empty array and returned
final class SomeClass
{
- public function run()
+ public function run(): array
{
$values = [];
return $values;
}
}
Add strict return type based native function or native method
final class SomeClass
{
- public function run()
+ public function run(): int
{
return strlen('value');
}
}
Add int/float return type based on strict typed returns
class SomeClass
{
- public function increase($value)
+ public function increase($value): int
{
return ++$value;
}
}
Add int/float return type based on strict scalar returns type
class SomeClass
{
- public function getNumber()
+ public function getNumber(): int
{
return 200;
}
}
Add bool return type based on strict bool returns type operations
class SomeClass
{
- public function resolve($first, $second)
+ public function resolve($first, $second): bool
{
return $first > $second;
}
}
Add return method return type based on strict typed property
final class SomeClass
{
private int $age = 100;
- public function getAge()
+ public function getAge(): int
{
return $this->age;
}
}
Add return type from strict return $this
final class SomeClass
{
- public function run()
+ public function run(): self
{
return $this;
}
}
Add strict type declaration based on returned constants
class SomeClass
{
public const NAME = 'name';
- public function run()
+ public function run(): string
{
return self::NAME;
}
}
Add return type from strict return type of call
final class SomeClass
{
- public function getData()
+ public function getData(): int
{
return $this->getNumber();
}
private function getNumber(): int
{
return 1000;
}
}