New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Php72][TypeDeclaration] Fix infinite loop on ParseStrWithResultArgumentRector+DeclareStrictTypesRector #5699
Conversation
…entRector+DeclareStrictTypesRector
@kapersoft this should fix rectorphp/rector#8531 |
@kenjis this probably should fix infinite loop on CodeIgniter4 project as well when running |
All checks have passed 🎉 @TomasVotruba I am merging it ;) |
@samsonasik I have checked your fix with my codebase and the endless loops are gone 😄 Thanks for quick response! 👍 |
@kapersoft you're welcome, I am actually not sure why it may require |
The issue seems happen only on scoped code (php 7.2 compat), as can't be produced in rector-src on php 8.2, so array seems somewhere goes to // use 0 index to avoid infinite loop
- $rootStmt = $newStmts[0] ?? null;
+ reset($newStmts);
+ $rootStmt = current($newStmts);
$stmt = $rootStmt;
if ($rootStmt instanceof FileWithoutNamespace) {
// use 0 index to avoid infinite loop
- $currentStmt = $rootStmt->stmts[0] ?? null;
+ reset($rootStmt->stmts);
+ $currentStmt = current($rootStmt->stmts); |
current solution with index 0 seems ok as is :) |
I see, the issue is on $totalKeys = array_key_last($stmtsAware->stmts); downgraded to \end($stmtsAware->stmts);
$totalKeys = \key($stmtsAware->stmts); which make it always goes to last stmts, then it never \end($stmtsAware->stmts);
$totalKeys = \key($stmtsAware->stmts);
+ reset($stmtsAware->stmts); |
Fixes rectorphp/rector#8531