Skip to content

Conversation

@bryannielsen
Copy link
Contributor

I hit an issue today in downgrading some Laravel code.
The ArrowFunctionToAnonymousFunctionRector rule would take this function

fn ($deferred) => app(DeferredCallbackCollection::class)[] = $deferred

and transform it to this

function ($deferred) use ($deferred) {
    return app(DeferredCallbackCollection::class)[] = $deferred;
}

and this would result in a PHP error

Fatal error: Cannot use lexical variable $deferred as a parameter name in <file_path>

My patch works well for solving my problem but if there's a better way to fix this that would be great too.
Thanks for your hard work!

@TomasVotruba
Copy link
Member

Hi, thanks for the fix. Could you add also failing test fixture, so we have it covered?

@samsonasik
Copy link
Member

@bryannielsen
Copy link
Contributor Author

bryannielsen commented Mar 20, 2025

Sorry about that!
I added the test but the only case that was failing before my patch was singleArrayAssignment which mirrors the situation I hit today.

The rest of the cases all worked properly which surprised me so maybe there is a better/different fix that should be made for that case?

@bryannielsen
Copy link
Contributor Author

@TomasVotruba and @samsonasik I don't understand the last failing check but I'm happy to try and resolve it if you can point me in the right direction. Thanks!

@samsonasik
Copy link
Member

You can run:

vendor/bin/rector && composer fix-cs

to fix ci

@samsonasik
Copy link
Member

cs needs fix, see notice https://github.com/rectorphp/rector-downgrade-php/actions/runs/14113130318/job/39536748104?pr=268#step:6:1

you can run

composer fix-cs

or

vendor/bin/ecs check --fix

@samsonasik
Copy link
Member

Let's give it a try, thank you @bryannielsen

@samsonasik samsonasik merged commit 480f1cf into rectorphp:main Mar 27, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants