Skip to content

[rector] Add AddParamTypeToRefactorMethodRector if missing#8061

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-rector-utils
Jun 20, 2026
Merged

[rector] Add AddParamTypeToRefactorMethodRector if missing#8061
TomasVotruba merged 2 commits into
mainfrom
tv-rector-utils

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jun 20, 2026

Copy link
Copy Markdown
Member

Adds new AddParamTypeToRefactorMethodRector to the rector-preset set.

When a Rector rule's getNodeTypes() returns a single concrete node type via an inline array literal, the rule adds the matching @param annotation to refactor(). This lets PHPStan know the concrete $node type, removing the need for instanceof checks inside refactor() and avoiding "unknown type" errors when a method is called on $node.

 public function getNodeTypes(): array
 {
     return [MethodCall::class];
 }

+/**
+ * @param MethodCall $node
+ */
 public function refactor(Node $node): ?Node
 {
 }

Pairs with the existing RemoveRefactorDuplicatedNodeInstanceCheckRector (add @param -> remove now-redundant instanceof).

Skips (avoid noisy/incorrect output):

  • @param node already present (never overrides a more precise type)
  • interface node types (e.g. StmtsAwareInterface) that expand to a large implementer union
  • non-array returns such as NodeGroup::STMTS_AWARE constant groups

Self-applied to own source: missing @param added to 5 rules (ConstFetch, Variable, ClassLike, Class_, Function_).

@TomasVotruba TomasVotruba enabled auto-merge (squash) June 20, 2026 10:54
@TomasVotruba TomasVotruba merged commit 84d949c into main Jun 20, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the tv-rector-utils branch June 20, 2026 10:57
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