Skip to content

[perf] Skip AnnotationToAttributeRector for nodes without a docblock - #8627

Merged
TomasVotruba merged 2 commits into
mainfrom
perf-annotation-to-attribute-skip-nondoc
Oct 11, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
perf-annotation-to-attribute-skip-nondoc

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Follow-up to the RenameClassRector phpdoc-guard optimization.

AnnotationToAttributeRector subscribes to eight node types (Class_, Property, Param, ClassMethod, Function_, Closure, ArrowFunction, Interface_) and built a PhpDocInfo for every visited node. The attribute groups it produces come only from docblock annotations, and it reprints an existing docblock - it never adds one to a doc-less node - so a node without a docblock always ends in return null.

Guard the phpdoc path behind getDocComment() !== null, placed after the existing configuration check so that behaviour is preserved.

Tests: rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector (65) green, ECS + PHPStan level 8 clean.

TomasVotruba and others added 2 commits October 11, 2026 18:43
The rule subscribes to eight node types (Class_, Property, Param, ClassMethod, Function_, Closure, ArrowFunction, Interface_) and built a PhpDocInfo for every one. The attributes it produces come only from docblock annotations, and it reprints an existing docblock rather than adding a new one, so a node without a docblock always returns null. Guard the phpdoc path behind getDocComment() after the configuration check. Behaviour unchanged.
@TomasVotruba
TomasVotruba merged commit 0c985e4 into main Oct 11, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the perf-annotation-to-attribute-skip-nondoc branch October 11, 2026 16:52
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.

2 participants