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: 0, float|int\"\nRun Rector with \"--debug\" option and post the report here: https://github.com/rectorphp/rector/issues/new", "file": "/var/www/storage/demo/k78w78o13kusu7orrhnv/rector_analyzed_file.php", "line": 70 } ] }
Run Rector on your code to see what it can do for you:
PHP snippet to change
<?php final class DemoFile { /** * @param array<PaymentPeriod> $arr */ public function run(array $arr) { $sumCents = \array_reduce($arr, function ($carry, PaymentPeriod $paymentPeriod) : float|int { return $carry + $paymentPeriod->getSum(); }, 0); } } interface PaymentPeriod { public function getSum() : float|null; }
Config
rector.php
<?php use Rector\Config\RectorConfig; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; use Rector\ValueObject\PhpVersion; return RectorConfig::configure() ->withRules([ \Rector\TypeDeclaration\Rector\FunctionLike\AddClosureParamTypeForArrayReduceRector::class ]);
Run Rector
Rector version:
b855ff
- released at 2026-01-22 19:37