Static closure rule ignores arguments with $this binding
Changes
- Adds a new
CallLikeExpectsThisBindedClosureArgsAnalyzerwhich allows the detection of the@param-closure-this. - Adds a mechanism in the Static Closure rule to apply an attribute to closures that might conflict with
@param-closure-thisand then skip these closures - Sets up the tests to cover these scenarios
Why
Often there's a few scenarios where the static closure rule causes problems and starts to add the keyword where it will break code because it's being used as a argument for a parameter which will be later bound to an object. This can't be done if the closure is static and causes a runtime error.
This happens quite a lot in Laravel projects. Example issues https://github.com/driftingly/rector-laravel/issues/102
Notes
I had to use method.notFound to silence PHPStan. I don't know why this is the case as the code works but something is up with PHPStan.
I also created a new analyser to make this work but I'm happy to take this method and put it into a pre-existing one if adding a new one seems pointless.
@peterfox unit test somehow error
Lets give this a go. Thank you Peter :+1: