rector: Global Execution Bugs
Bug Report
| Subject | Details |
|---|---|
| PHP Versions | 7.4 and 8.1 at least |
| Rector Version | 0.12.13 |
| Execution | Global |
Using the tool globally causes unexpected differences in behavior. Documented examples include:
- Errors during verbose output (https://github.com/rectorphp/rector/issues/6903#issuecomment-1013741544)
- Differing detection of parent class methods (https://github.com/codeigniter4/devkit/pull/8#issuecomment-1014630719)
The docs contain a single buried reference to global execution (https://github.com/rectorphp/rector/blob/main/docs/static_reflection_and_autoload.md#call-command-with--a-option) stating it is “not recommended as autoload may overlapped”.
Minimal PHP Code Causing Issue
See example repo with steps to reproduce at https://github.com/MGatner/rector-error.
Expected Behaviour
Two options in my mind:
- Global and local execution should result in identical results. The likely resolution is for
autoloadProjectAutoloaderFile()to be made more robust at detecting the correct autoload file (see https://github.com/rectorphp/rector-src/pull/1683, but even better) - Remove support for global execution, or make one of the workarounds (https://github.com/rectorphp/rector/blob/main/docs/static_reflection_and_autoload.md#dealing-with-class--was-not-found-while-trying-to-analyse-it) mandatory. Rector should not “guess” at an autoload during global execution. This unannounced behavior is the source of the very confusing behavior noted above.
I have a strong preference for option 1). I believe static analysis tools that are not actual dependency should not be declared as such. That said, I don’t have time to learn the Rector codebase to implement this solution, nor the institutional knowledge to declare it “best for the project”.
I do not want to influence the decision about what is best, but should the team decide to go with option 1) I put forth a $40 bounty on its execution to go toward supporting this project.
References
- Initial resolution attempt: https://github.com/rectorphp/rector-src/pull/1683
- Reversion of the first attempt: https://github.com/rectorphp/rector-src/pull/1685
- Repo demonstrating Problem 1: https://github.com/MGatner/rector-error
- Repo/conversation demonstrating Problem 2: https://github.com/codeigniter4/devkit/pull/8
- Tagging @PhilETaylor
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (3 by maintainers)
Commits related to this issue
- possible solution for global execution Ref https://github.com/rectorphp/rector/issues/6945 — committed to rectorphp/rector-src by samsonasik 2 years ago
- possible solution for global execution Ref https://github.com/rectorphp/rector/issues/6945 — committed to rectorphp/rector-src by samsonasik 2 years ago
- possible solution for global execution Ref https://github.com/rectorphp/rector/issues/6945 — committed to rectorphp/rector-src by samsonasik 2 years ago
- possible solution for global execution Ref https://github.com/rectorphp/rector/issues/6945 — committed to rectorphp/rector-src by samsonasik 2 years ago
- possible solution for global execution (#1692) * possible solution for global execution Ref https://github.com/rectorphp/rector/issues/6945 * try with no constant no getcwd(), direct vendor/au... — committed to rectorphp/rector-src by samsonasik 2 years ago
🥳 On the release! Bounty sent via sponsorship.
I tested with
dev-mainand both problems appear to be resolved! I will do some more thorough experimenting once this is released.that works for me on the “could not process” error, when running a global rector
Basically the same change I made but with a safety check first 👍
Sent from my iPhone
Looking good so far! Definitely solves the “Class not found.” I’m going to test it in a fresh environment with different PHP version and get back.