-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TypeInfo] Handle custom collection objects properly #54661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
55fc9bf
to
106fec9
Compare
106fec9
to
b2a7627
Compare
@@ -164,7 +162,7 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ | |||
default => $this->resolveCustomIdentifier($node->name, $typeContext), | |||
}; | |||
|
|||
if ($type instanceof ObjectType && \in_array($type->getClassName(), self::COLLECTION_CLASS_NAMES, true)) { | |||
if ($type instanceof ObjectType && (is_a($type->getClassName(), \Traversable::class, true) || is_a($type->getClassName(), \ArrayAccess::class, true))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_subclass_of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using is_subclass_of
, only subclasses will return true. And I think that it'd be great to be able to understand Traversable
as a collection as well. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean. is_subclass_of works with interfaces too: https://3v4l.org/bP6JN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess what @mtarld means is that is_subclass_of(\Traversable::class, \Traversable::class);
returns false
: https://3v4l.org/1CbGV
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, thanks @xabbuh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you @mtarld. |
Understand custom collection objects.