Find the best Rector rule to solve your problem. Searching through 780 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;
         });
     }
 }

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)
     {
     }
 }

AddClosureVoidReturnTypeWhereNoReturnRector

Add closure return type void if there is no return

-function () {
+function (): void {
 };

AddClosureNeverReturnTypeRector

Add "never" return-type for closure that never return anything

-function () {
+function (): never {
     throw new InvalidException();
 }

AddArrayFunctionClosureParamTypeRector

Add array_filter()/array_map() function closure param type, based on passed iterable

 $items = [1, 2, 3];
-$result = array_filter($items, fn ($item) => $item > 1);
+$result = array_filter($items, fn (int $item) => $item > 1);