Try Rector
Docs
Hire Team
Find Rule
Blog
Contact
AST
Try Rector
Docs
Hire Team
Find Rule
Blog
Contact
AST
Rector run Failed:
{ "totals": { "changed_files": 0, "errors": 1 }, "errors": [ { "message": "System error: \"Cannot create PHPStan\\Type\\UnionType with: (Doctrine\\Common\\Collections\\ArrayCollection&Doctrine\\Common\\Collections\\Collection)|(Doctrine\\Common\\Collections\\Collection&TReturn), Doctrine\\Common\\Collections\\ArrayCollection\"\nRun Rector with \"--debug\" option and post the report here: https://github.com/rectorphp/rector/issues/new", "file": "/var/www/storage/demo/49jb382ys2fdvip2bmsh/rector_analyzed_file.php", "line": 67 } ] }
Run Rector on your code to see what it can do for you:
PHP snippet to change
<?php use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; $items = ['a', 'b', 'b', 'c']; $reduces = \array_reduce($items, static function (Collection $carry, string $item) { if (!$carry->contains($item)) { $carry->add($item); } return $carry; }, new ArrayCollection());
Config
rector.php
<?php use Rector\Config\RectorConfig; use Rector\TypeDeclaration\Rector\FunctionLike\AddClosureParamTypeForArrayReduceRector; return RectorConfig::configure() ->withRules([ AddClosureParamTypeForArrayReduceRector::class ]);
Run Rector
Rector version:
b5e58f
- released at 2025-09-16 16:38