Skip to content

Commit 4eed51c

Browse files
committed
Faster IntersectionTypeMethodReflection->getVariants()
1 parent 29af0ba commit 4eed51c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Reflection/Type/IntersectionTypeMethodReflection.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,22 @@ public function getPrototype(): ClassMemberReflection
8080

8181
public function getVariants(): array
8282
{
83-
$returnType = TypeCombinator::intersect(...array_map(static fn (MethodReflection $method): Type => TypeCombinator::intersect(...array_map(static fn (ParametersAcceptor $acceptor): Type => $acceptor->getReturnType(), $method->getVariants())), $this->methods));
84-
$phpDocReturnType = TypeCombinator::intersect(...array_map(static fn (MethodReflection $method): Type => TypeCombinator::intersect(...array_map(static fn (ParametersAcceptor $acceptor): Type => $acceptor->getPhpDocReturnType(), $method->getVariants())), $this->methods));
85-
$nativeReturnType = TypeCombinator::intersect(...array_map(static fn (MethodReflection $method): Type => TypeCombinator::intersect(...array_map(static fn (ParametersAcceptor $acceptor): Type => $acceptor->getNativeReturnType(), $method->getVariants())), $this->methods));
83+
$returnTypes = [];
84+
$phpDocReturnTypes = [];
85+
$nativeReturnTypes = [];
86+
foreach($this->methods as $method) {
87+
$variants = $method->getVariants();
88+
89+
foreach ($variants as $acceptor) {
90+
$returnTypes[] = $acceptor->getReturnType();
91+
$phpDocReturnTypes[] = $acceptor->getPhpDocReturnType();
92+
$nativeReturnTypes[] = $acceptor->getNativeReturnType();
93+
}
94+
}
8695

96+
$returnType = TypeCombinator::intersect(...$returnTypes);
97+
$phpDocReturnType = TypeCombinator::intersect(...$phpDocReturnTypes);
98+
$nativeReturnType = TypeCombinator::intersect(...$nativeReturnTypes);
8799
return array_map(static fn (ExtendedParametersAcceptor $acceptor): ExtendedParametersAcceptor => new ExtendedFunctionVariant(
88100
$acceptor->getTemplateTypeMap(),
89101
$acceptor->getResolvedTemplateTypeMap(),

0 commit comments

Comments
 (0)