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:

  1. Errors during verbose output (https://github.com/rectorphp/rector/issues/6903#issuecomment-1013741544)
  2. 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:

  1. 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)
  2. 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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

🥳 On the release! Bounty sent via sponsorship.

I tested with dev-main and 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

Screenshot 2022-01-18 at 03 48 25

Basically the same change I made but with a safety check first 👍

Sent from my iPhone

On 17 Jan 2022, at 15:48, MGatner @.***> wrote:

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.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

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.