From 4eed51ce9d4ffad9ca222cbb22109c66dcb5ea72 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 20 Feb 2026 22:28:27 +0100 Subject: [PATCH 1/2] Faster IntersectionTypeMethodReflection->getVariants() --- .../Type/IntersectionTypeMethodReflection.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Reflection/Type/IntersectionTypeMethodReflection.php b/src/Reflection/Type/IntersectionTypeMethodReflection.php index b31124c17a7..4064196260d 100644 --- a/src/Reflection/Type/IntersectionTypeMethodReflection.php +++ b/src/Reflection/Type/IntersectionTypeMethodReflection.php @@ -80,10 +80,22 @@ public function getPrototype(): ClassMemberReflection public function getVariants(): array { - $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)); - $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)); - $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)); + $returnTypes = []; + $phpDocReturnTypes = []; + $nativeReturnTypes = []; + foreach($this->methods as $method) { + $variants = $method->getVariants(); + + foreach ($variants as $acceptor) { + $returnTypes[] = $acceptor->getReturnType(); + $phpDocReturnTypes[] = $acceptor->getPhpDocReturnType(); + $nativeReturnTypes[] = $acceptor->getNativeReturnType(); + } + } + $returnType = TypeCombinator::intersect(...$returnTypes); + $phpDocReturnType = TypeCombinator::intersect(...$phpDocReturnTypes); + $nativeReturnType = TypeCombinator::intersect(...$nativeReturnTypes); return array_map(static fn (ExtendedParametersAcceptor $acceptor): ExtendedParametersAcceptor => new ExtendedFunctionVariant( $acceptor->getTemplateTypeMap(), $acceptor->getResolvedTemplateTypeMap(), From 821975375f7d66d4d8c036c6025ec430ab67ed78 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 20 Feb 2026 22:29:05 +0100 Subject: [PATCH 2/2] Update IntersectionTypeMethodReflection.php --- src/Reflection/Type/IntersectionTypeMethodReflection.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Reflection/Type/IntersectionTypeMethodReflection.php b/src/Reflection/Type/IntersectionTypeMethodReflection.php index 4064196260d..76ab3d1afcc 100644 --- a/src/Reflection/Type/IntersectionTypeMethodReflection.php +++ b/src/Reflection/Type/IntersectionTypeMethodReflection.php @@ -10,7 +10,6 @@ use PHPStan\Reflection\ExtendedMethodReflection; use PHPStan\Reflection\ExtendedParametersAcceptor; use PHPStan\Reflection\MethodReflection; -use PHPStan\Reflection\ParametersAcceptor; use PHPStan\ShouldNotHappenException; use PHPStan\TrinaryLogic; use PHPStan\Type\Type; @@ -83,7 +82,7 @@ public function getVariants(): array $returnTypes = []; $phpDocReturnTypes = []; $nativeReturnTypes = []; - foreach($this->methods as $method) { + foreach ($this->methods as $method) { $variants = $method->getVariants(); foreach ($variants as $acceptor) {