@@ -3653,31 +3653,6 @@ static function (): void {
36533653
36543654 } else {
36553655 $ classReflection = $ this ->reflectionProvider ->getAnonymousClassReflection ($ expr ->class , $ scope ); // populates $expr->class->name
3656- $ constructorResult = null ;
3657- $ this ->processStmtNode ($ expr ->class , $ scope , static function (Node $ node , Scope $ scope ) use ($ nodeCallback , $ classReflection , &$ constructorResult ): void {
3658- $ nodeCallback ($ node , $ scope );
3659- if (!$ node instanceof MethodReturnStatementsNode) {
3660- return ;
3661- }
3662- if ($ constructorResult !== null ) {
3663- return ;
3664- }
3665- $ currentClassReflection = $ node ->getClassReflection ();
3666- if ($ currentClassReflection ->getName () !== $ classReflection ->getName ()) {
3667- return ;
3668- }
3669- if (!$ currentClassReflection ->hasConstructor ()) {
3670- return ;
3671- }
3672- if ($ currentClassReflection ->getConstructor ()->getName () !== $ node ->getMethodReflection ()->getName ()) {
3673- return ;
3674- }
3675- $ constructorResult = $ node ;
3676- }, StatementContext::createTopLevel ());
3677- if ($ constructorResult !== null ) {
3678- $ throwPoints = array_merge ($ throwPoints , $ constructorResult ->getStatementResult ()->getThrowPoints ());
3679- $ impurePoints = array_merge ($ impurePoints , $ constructorResult ->getImpurePoints ());
3680- }
36813656 if ($ classReflection ->hasConstructor ()) {
36823657 $ constructorReflection = $ classReflection ->getConstructor ();
36833658 $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs (
@@ -3686,6 +3661,54 @@ static function (): void {
36863661 $ constructorReflection ->getVariants (),
36873662 $ constructorReflection ->getNamedArgumentsVariants (),
36883663 );
3664+
3665+ if ($ constructorReflection ->getDeclaringClass ()->getName () === $ classReflection ->getName ()) {
3666+ $ constructorResult = null ;
3667+ $ this ->processStmtNode ($ expr ->class , $ scope , static function (Node $ node , Scope $ scope ) use ($ nodeCallback , $ classReflection , &$ constructorResult ): void {
3668+ $ nodeCallback ($ node , $ scope );
3669+ if (!$ node instanceof MethodReturnStatementsNode) {
3670+ return ;
3671+ }
3672+ if ($ constructorResult !== null ) {
3673+ return ;
3674+ }
3675+ $ currentClassReflection = $ node ->getClassReflection ();
3676+ if ($ currentClassReflection ->getName () !== $ classReflection ->getName ()) {
3677+ return ;
3678+ }
3679+ if (!$ currentClassReflection ->hasConstructor ()) {
3680+ return ;
3681+ }
3682+ if ($ currentClassReflection ->getConstructor ()->getName () !== $ node ->getMethodReflection ()->getName ()) {
3683+ return ;
3684+ }
3685+ $ constructorResult = $ node ;
3686+ }, StatementContext::createTopLevel ());
3687+ if ($ constructorResult !== null ) {
3688+ $ throwPoints = $ constructorResult ->getStatementResult ()->getThrowPoints ();
3689+ $ impurePoints = $ constructorResult ->getImpurePoints ();
3690+ }
3691+ } else {
3692+ $ this ->processStmtNode ($ expr ->class , $ scope , $ nodeCallback , StatementContext::createTopLevel ());
3693+ $ declaringClass = $ constructorReflection ->getDeclaringClass ();
3694+ $ constructorThrowPoint = $ this ->getConstructorThrowPoint ($ constructorReflection , $ parametersAcceptor , $ classReflection , $ expr , new Name \FullyQualified ($ declaringClass ->getName ()), $ expr ->getArgs (), $ scope );
3695+ if ($ constructorThrowPoint !== null ) {
3696+ $ throwPoints [] = $ constructorThrowPoint ;
3697+ }
3698+
3699+ if (!$ constructorReflection ->hasSideEffects ()->no ()) {
3700+ $ certain = $ constructorReflection ->isPure ()->no ();
3701+ $ impurePoints [] = new ImpurePoint (
3702+ $ scope ,
3703+ $ expr ,
3704+ 'new ' ,
3705+ sprintf ('instantiation of class %s ' , $ declaringClass ->getDisplayName ()),
3706+ $ certain ,
3707+ );
3708+ }
3709+ }
3710+ } else {
3711+ $ this ->processStmtNode ($ expr ->class , $ scope , $ nodeCallback , StatementContext::createTopLevel ());
36893712 }
36903713 }
36913714
0 commit comments