@@ -2458,15 +2458,9 @@ static function () use ($expr, $rightResult): MutatingScope {
24582458 $ expr ->args ,
24592459 $ constructorReflection ->getVariants ()
24602460 );
2461- if ($ constructorReflection ->getThrowType () !== null ) {
2462- $ throwType = $ constructorReflection ->getThrowType ();
2463- if (!$ throwType instanceof VoidType) {
2464- $ throwPoints [] = ThrowPoint::createExplicit ($ scope , $ throwType , $ expr , true );
2465- }
2466- } elseif ($ this ->implicitThrows ) {
2467- if ($ classReflection ->getName () !== \Throwable::class && !$ classReflection ->isSubclassOf (\Throwable::class)) {
2468- $ throwPoints [] = ThrowPoint::createImplicit ($ scope , $ expr );
2469- }
2461+ $ constructorThrowPoint = $ this ->getConstructorThrowPoint ($ constructorReflection , $ classReflection , $ expr , $ expr ->class , $ expr ->args , $ scope );
2462+ if ($ constructorThrowPoint !== null ) {
2463+ $ throwPoints [] = $ constructorThrowPoint ;
24702464 }
24712465 }
24722466 } else {
@@ -2720,6 +2714,39 @@ private function getMethodThrowPoint(MethodReflection $methodReflection, MethodC
27202714 return null ;
27212715 }
27222716
2717+ /**
2718+ * @param Node\Arg[] $args
2719+ */
2720+ private function getConstructorThrowPoint (MethodReflection $ constructorReflection , ClassReflection $ classReflection , New_ $ new , Name $ className , array $ args , MutatingScope $ scope ): ?ThrowPoint
2721+ {
2722+ $ methodCall = new StaticCall ($ className , $ constructorReflection ->getName (), $ args );
2723+ foreach ($ this ->dynamicThrowTypeExtensionProvider ->getDynamicStaticMethodThrowTypeExtensions () as $ extension ) {
2724+ if (!$ extension ->isStaticMethodSupported ($ constructorReflection )) {
2725+ continue ;
2726+ }
2727+
2728+ $ throwType = $ extension ->getThrowTypeFromStaticMethodCall ($ constructorReflection , $ methodCall , $ scope );
2729+ if ($ throwType === null ) {
2730+ return null ;
2731+ }
2732+
2733+ return ThrowPoint::createExplicit ($ scope , $ throwType , $ new , false );
2734+ }
2735+
2736+ if ($ constructorReflection ->getThrowType () !== null ) {
2737+ $ throwType = $ constructorReflection ->getThrowType ();
2738+ if (!$ throwType instanceof VoidType) {
2739+ return ThrowPoint::createExplicit ($ scope , $ throwType , $ new , true );
2740+ }
2741+ } elseif ($ this ->implicitThrows ) {
2742+ if ($ classReflection ->getName () !== \Throwable::class && !$ classReflection ->isSubclassOf (\Throwable::class)) {
2743+ return ThrowPoint::createImplicit ($ scope , $ methodCall );
2744+ }
2745+ }
2746+
2747+ return null ;
2748+ }
2749+
27232750 private function getStaticMethodThrowPoint (MethodReflection $ methodReflection , StaticCall $ methodCall , MutatingScope $ scope ): ?ThrowPoint
27242751 {
27252752 foreach ($ this ->dynamicThrowTypeExtensionProvider ->getDynamicStaticMethodThrowTypeExtensions () as $ extension ) {
0 commit comments