Bug Report
| Subject |
Details |
| Rector version |
Tested on 0.15.18, 0.15.24, and 0.15.25 |
When using the following three rules together, Rector halts upon encountering a uasort that satisfies IfToSpaceshipRector, then begins rapidly consuming memory until it hits the limit or the host crashes:
- PHP 5.6:
AddDefaultValueForUndefinedVariableRector
- PHP 7.0:
IfToSpaceshipRector
- PHP 7.4:
ClosureToArrowFunctionRector
This was initially discovered when using LevelSetList::UP_TO_PHP_82.
EDIT: It may also be note-worthy that when this happens, the user can Ctrl+C to end the process. When running again without --clear-cache, the issue will not re-occur in the same file but the rules will be skipped. The issue will re-occur if another file has the same issue or if --clear-cache is provided.
Minimal PHP Code Causing Issue
https://getrector.com/demo/dd221fce-626a-4664-9f07-c16fc5ff68aa
Based on this demo, the issue only seems to occur when the IfToSpaceshipRector and ClosureToArrowFunction interact as a function parameter. Individually, all rules work normally. When not nested inside a function call, the interaction of the latter two rules still works as expected.
I'm not sure why AddDefaultValueForUndefinedVariableRector is required for reproduction, but removing it or adding it to the skip list fixes the crash.
Expected Behaviour
The minimum error demo above should be refactored to:
<?php
final class DemoFile
{
public function run()
{
uasort([], fn ($a, $b) => $a <=> $b;
}
}
I appreciate your time!