Find the best Rector rule to solve your problem. Searching through 650 rules.

Found 10 rules:

AddTypeToConstRector

Add type to constants based on their value

 final class SomeClass
 {
-    public const TYPE = 'some_type';
+    public const string TYPE = 'some_type';
 }
SETS:  PHP 8.3

Configurable

AddPropertyTypeDeclarationRector

Add type to property by added rules, mostly public/property by parent type

 class SomeClass extends ParentClass
 {
-    public $name;
+    public string $name;
 }

AddClosureParamTypeFromIterableMethodCallRector

Applies type hints to closures on Iterable method calls where key/value types are documented

 class SomeClass
 {
     /**
      * @param Collection<int, string> $collection
      */
     public function run(Collection $collection)
     {
-        return $collection->map(function ($item, $key) {
+        return $collection->map(function (string $item, int $key) {
             return $item . $key;
         });
     }
 }

Configurable

AddClosureParamTypeFromObjectRector

Add closure param type based on the object of the method call

 $request = new Request();
-$request->when(true, function ($request) {});
+$request->when(true, function (Request $request) {});

AddReturnTypeDeclarationFromYieldsRector

Add return type declarations from yields

 class SomeClass
 {
-    public function provide()
+    /**
+     * @return Iterator<int>
+     */
+    public function provide(): Iterator
     {
         yield 1;
     }
 }

AddClosureParamTypeForArrayReduceRector

Applies type hints to array_map closures

-array_reduce($strings, function ($carry, $value, $key): string {
+array_reduce($strings, function (string $carry, string $value): string {
     return $carry . $value;
 }, $initialString);

AddClosureParamTypeForArrayMapRector

Applies type hints to array_map closures

-array_map(function ($value, $key): string {
+array_map(function (string $value, int $key): bool {
     return $value . $key;
 }, $strings);

AddParamTypeSplFixedArrayRector

Add exact fixed array type in known cases

+use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;

 class SomeClass
 {
+    /**
+     * @param Tokens<Token>
+     */
     public function run(Tokens $tokens)
     {
     }
 }

Configurable

AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector

Add param types where needed

-(new SomeClass)->process(function ($parameter) {});
+(new SomeClass)->process(function (string $parameter) {});

Configurable

AddClosureParamTypeFromArgRector

Add closure param type based on known passed service/string types of method calls

 $app = new Container();
-$app->extend(SomeClass::class, function ($parameter) {});
+$app->extend(SomeClass::class, function (SomeClass $parameter) {});