Skip to content

Fix rule when method is __invoke#884

Merged
TomasVotruba merged 2 commits intorectorphp:mainfrom
wilfi00:fix-inline-class-route-prefix
Nov 25, 2025
Merged

Fix rule when method is __invoke#884
TomasVotruba merged 2 commits intorectorphp:mainfrom
wilfi00:fix-inline-class-route-prefix

Conversation

@wilfi00
Copy link
Copy Markdown
Contributor

@wilfi00 wilfi00 commented Nov 25, 2025

Hello,

When we use the magic __invoke method, the InlineClassRoutePrefix rule does not apply even though it should: https://getrector.com/demo/3caf4eca-9383-470b-be3a-a34e2f5adbc1

I tried to fix it, feel free to review my changes.

Copy link
Copy Markdown
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general magic is on purpose to avoid __construct included.

To ensure it only apply on __invoke only, use

\Rector\NodeAnalyzer\MagicClassMethodAnalyzer::isUnsafeOverridden() method, see

https://github.com/rectorphp/rector-src/blob/fa54d46a5458068ef378c2f7b54cbedd1a6f398c/src/NodeAnalyzer/MagicClassMethodAnalyzer.php#L18

@wilfi00
Copy link
Copy Markdown
Contributor Author

wilfi00 commented Nov 25, 2025

Nice, thank you for your feedback, I just commited to use isUnsafeOverridden method 👍

@wilfi00 wilfi00 requested a review from samsonasik November 25, 2025 15:59
@TomasVotruba TomasVotruba merged commit ec51521 into rectorphp:main Nov 25, 2025
5 checks passed
@TomasVotruba
Copy link
Copy Markdown
Member

Thank you

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.

4 participants