Skip to content

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.

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.

Incorrect behavior of ReturnTypeFromReturnNewRector

2 participants