Skip to content

fix: ReturnTypeFromReturnNewRector#7291

Closed
calebdw wants to merge 1 commit intorectorphp:mainfrom
calebdw:calebdw/push-munqolyzpsuw
Closed

fix: ReturnTypeFromReturnNewRector#7291
calebdw wants to merge 1 commit intorectorphp:mainfrom
calebdw:calebdw/push-munqolyzpsuw

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Sep 15, 2025

Closes rectorphp/rector#9378

Thanks!

@calebdw calebdw force-pushed the calebdw/push-munqolyzpsuw branch from c5bfaec to 07f69c1 Compare September 15, 2025 14:58

if (is_string($returnedNewClassName)) {
$node->returnType = new FullyQualified($returnedNewClassName);
$node->returnType = str_starts_with($returnedNewClassName, 'AnonymousClass')
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be covered by NodeTypeResolver itself, via ClassReflection->isAnonymous(), check in TypeTraverser::map(), see example

return TypeTraverser::map($mainType, function (Type $traversedType, callable $traverseCallback): Type {

Copy link
Member

Choose a reason for hiding this comment

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

use getNativeType() over getType() should works for this.

Copy link
Member

Choose a reason for hiding this comment

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

I created separate PR:

to use native type, which more reliable for this strict type rule.

@github-actions
Copy link
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of ReturnTypeFromReturnNewRector

2 participants