Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Skip require of files with top-level side effects in RemovePsr4AutoloadedIncludeRector#8175

Open
lll-lll-lll-lll wants to merge 1 commit into
rectorphp:tv-remove-dead-include-requirerectorphp/rector-src:tv-remove-dead-include-requirefrom
lll-lll-lll-lll:side-effect-guard-for-psr4-include-removallll-lll-lll-lll/rector-src:side-effect-guard-for-psr4-include-removalCopy head branch name to clipboard
Open

Skip require of files with top-level side effects in RemovePsr4AutoloadedIncludeRector#8175
lll-lll-lll-lll wants to merge 1 commit into
rectorphp:tv-remove-dead-include-requirerectorphp/rector-src:tv-remove-dead-include-requirefrom
lll-lll-lll-lll:side-effect-guard-for-psr4-include-removallll-lll-lll-lll/rector-src:side-effect-guard-for-psr4-include-removalCopy head branch name to clipboard

Conversation

@lll-lll-lll-lll

Copy link
Copy Markdown

Adds the side-effect guard discussed in #8149 (comment) (thanks @samsonasik for the catch).

resolveSingleDeclaredClassName() now bails out unless the target file's top level contains only type declarations: class-likes, use statements, statement-form declare, and comments (namespace is checked recursively). Files with top-level function/const definitions or executed statements — e.g. Cli::init(); after the class — keep their require load-bearing, since autoloading replays only the type declarations.

The guard is one extra condition in front of the existing checks, with existing code untouched, so it can only make the rule remove less, never more.

Fixtures:

  • skip_class_with_side_effect — class followed by ClassWithInit::init(); (the CodeIgniter-style case)
  • skip_class_with_function — class plus a top-level function

Both fail (the require gets removed) without the guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.