Find the best Rector rule to solve your problem


ReturnTypeFromStrictTernaryRector

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;
     }
 }

ReturnTypeFromStrictNewArrayRector

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;
     }
 }

ReturnTypeFromStrictNativeCallRector

Add strict return type based native function or native method

 final class SomeClass
 {
-    public function run()
+    public function run(): int
     {
         return strlen('value');
     }
 }

NumericReturnTypeFromStrictReturnsRector

Add int/float return type based on strict typed returns

 class SomeClass
 {
-    public function increase($value)
+    public function increase($value): int
     {
         return ++$value;
     }
 }

NumericReturnTypeFromStrictScalarReturnsRector

Add int/float return type based on strict scalar returns type

 class SomeClass
 {
-    public function getNumber()
+    public function getNumber(): int
     {
         return 200;
     }
 }

BoolReturnTypeFromBooleanStrictReturnsRector

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;
     }
 }

ReturnTypeFromStrictTypedPropertyRector

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;
     }
 }

ReturnTypeFromStrictFluentReturnRector

Add return type from strict return $this

 final class SomeClass
 {
-    public function run()
+    public function run(): self
     {
         return $this;
     }
 }

ReturnTypeFromStrictConstantReturnRector

Add strict type declaration based on returned constants

 class SomeClass
 {
     public const NAME = 'name';

-    public function run()
+    public function run(): string
     {
         return self::NAME;
     }
 }

ReturnTypeFromStrictTypedCallRector

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;
     }
 }