@@ -2769,25 +2769,26 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
27692769 );
27702770 }
27712771
2772+ $ normalizedExpr = $ expr ;
27722773 if ($ parametersAcceptor !== null ) {
2773- $ expr = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
2774+ $ normalizedExpr = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
27742775 $ returnType = $ parametersAcceptor ->getReturnType ();
27752776 $ isAlwaysTerminating = $ isAlwaysTerminating || $ returnType instanceof NeverType && $ returnType ->isExplicit ();
27762777 }
27772778
27782779 if (
2779- $ expr ->name instanceof Name
2780+ $ normalizedExpr ->name instanceof Name
27802781 && $ functionReflection !== null
27812782 && $ functionReflection ->getName () === 'clone '
2782- && count ($ expr ->getArgs ()) === 2
2783+ && count ($ normalizedExpr ->getArgs ()) === 2
27832784 ) {
2784- $ clonePropertiesArgType = $ scope ->getType ($ expr ->getArgs ()[1 ]->value );
2785- $ cloneExpr = new TypeExpr ($ scope ->getType (new Expr \Clone_ ($ expr ->getArgs ()[0 ]->value )));
2785+ $ clonePropertiesArgType = $ scope ->getType ($ normalizedExpr ->getArgs ()[1 ]->value );
2786+ $ cloneExpr = new TypeExpr ($ scope ->getType (new Expr \Clone_ ($ normalizedExpr ->getArgs ()[0 ]->value )));
27862787 $ clonePropertiesArgTypeConstantArrays = $ clonePropertiesArgType ->getConstantArrays ();
27872788 foreach ($ clonePropertiesArgTypeConstantArrays as $ clonePropertiesArgTypeConstantArray ) {
27882789 foreach ($ clonePropertiesArgTypeConstantArray ->getKeyTypes () as $ i => $ clonePropertyKeyType ) {
27892790 $ clonePropertyKeyTypeScalars = $ clonePropertyKeyType ->getConstantScalarValues ();
2790- $ propertyAttributes = $ expr ->getAttributes ();
2791+ $ propertyAttributes = $ normalizedExpr ->getAttributes ();
27912792 $ propertyAttributes ['inCloneWith ' ] = true ;
27922793 if (count ($ clonePropertyKeyTypeScalars ) === 1 ) {
27932794 $ this ->processVirtualAssign (
@@ -2813,23 +2814,23 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
28132814 }
28142815 }
28152816
2816- $ result = $ this ->processArgs ($ stmt , $ functionReflection , null , $ parametersAcceptor , $ expr , $ scope , $ storage , $ nodeCallback , $ context );
2817+ $ result = $ this ->processArgs ($ stmt , $ functionReflection , null , $ parametersAcceptor , $ normalizedExpr , $ scope , $ storage , $ nodeCallback , $ context );
28172818 $ scope = $ result ->getScope ();
28182819 $ hasYield = $ result ->hasYield ();
28192820 $ throwPoints = array_merge ($ throwPoints , $ result ->getThrowPoints ());
28202821 $ impurePoints = array_merge ($ impurePoints , $ result ->getImpurePoints ());
28212822 $ isAlwaysTerminating = $ isAlwaysTerminating || $ result ->isAlwaysTerminating ();
28222823
2823- if ($ expr ->name instanceof Expr) {
2824- $ nameType = $ scope ->getType ($ expr ->name );
2824+ if ($ normalizedExpr ->name instanceof Expr) {
2825+ $ nameType = $ scope ->getType ($ normalizedExpr ->name );
28252826 if (
28262827 $ nameType ->isObject ()->yes ()
28272828 && $ nameType ->isCallable ()->yes ()
28282829 && (new ObjectType (Closure::class))->isSuperTypeOf ($ nameType )->no ()
28292830 ) {
28302831 $ invokeResult = $ this ->processExprNode (
28312832 $ stmt ,
2832- new MethodCall ($ expr ->name , '__invoke ' , $ expr ->getArgs (), $ expr ->getAttributes ()),
2833+ new MethodCall ($ normalizedExpr ->name , '__invoke ' , $ normalizedExpr ->getArgs (), $ normalizedExpr ->getAttributes ()),
28332834 $ scope ,
28342835 $ storage ,
28352836 new NoopNodeCallback (),
@@ -2842,7 +2843,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
28422843 }
28432844
28442845 if ($ functionReflection !== null ) {
2845- $ functionThrowPoint = $ this ->getFunctionThrowPoint ($ functionReflection , $ parametersAcceptor , $ expr , $ scope );
2846+ $ functionThrowPoint = $ this ->getFunctionThrowPoint ($ functionReflection , $ parametersAcceptor , $ normalizedExpr , $ scope );
28462847 if ($ functionThrowPoint !== null ) {
28472848 $ throwPoints [] = $ functionThrowPoint ;
28482849 }
@@ -2870,18 +2871,18 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
28702871 if (
28712872 $ functionReflection !== null
28722873 && $ functionReflection ->getName () === 'file_put_contents '
2873- && count ($ expr ->getArgs ()) > 0
2874+ && count ($ normalizedExpr ->getArgs ()) > 0
28742875 ) {
2875- $ scope = $ scope ->invalidateExpression (new FuncCall (new Name ('file_get_contents ' ), [$ expr ->getArgs ()[0 ]]))
2876- ->invalidateExpression (new FuncCall (new Name \FullyQualified ('file_get_contents ' ), [$ expr ->getArgs ()[0 ]]));
2876+ $ scope = $ scope ->invalidateExpression (new FuncCall (new Name ('file_get_contents ' ), [$ normalizedExpr ->getArgs ()[0 ]]))
2877+ ->invalidateExpression (new FuncCall (new Name \FullyQualified ('file_get_contents ' ), [$ normalizedExpr ->getArgs ()[0 ]]));
28772878 }
28782879
28792880 if (
28802881 $ functionReflection !== null
28812882 && in_array ($ functionReflection ->getName (), ['array_pop ' , 'array_shift ' ], true )
2882- && count ($ expr ->getArgs ()) >= 1
2883+ && count ($ normalizedExpr ->getArgs ()) >= 1
28832884 ) {
2884- $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2885+ $ arrayArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
28852886
28862887 $ arrayArgType = $ scope ->getType ($ arrayArg );
28872888 $ arrayArgNativeType = $ scope ->getNativeType ($ arrayArg );
@@ -2903,18 +2904,18 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
29032904 if (
29042905 $ functionReflection !== null
29052906 && in_array ($ functionReflection ->getName (), ['array_push ' , 'array_unshift ' ], true )
2906- && count ($ expr ->getArgs ()) >= 2
2907+ && count ($ normalizedExpr ->getArgs ()) >= 2
29072908 ) {
2908- $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2909+ $ arrayArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
29092910
29102911 $ scope = $ this ->processVirtualAssign (
29112912 $ scope ,
29122913 $ storage ,
29132914 $ stmt ,
29142915 $ arrayArg ,
29152916 new NativeTypeExpr (
2916- $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope , $ expr ),
2917- $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope ->doNotTreatPhpDocTypesAsCertain (), $ expr ),
2917+ $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope , $ normalizedExpr ),
2918+ $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope ->doNotTreatPhpDocTypesAsCertain (), $ normalizedExpr ),
29182919 ),
29192920 $ nodeCallback ,
29202921 )->getScope ();
@@ -2931,7 +2932,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
29312932 $ functionReflection !== null
29322933 && $ functionReflection ->getName () === 'shuffle '
29332934 ) {
2934- $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2935+ $ arrayArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
29352936
29362937 $ scope = $ this ->processVirtualAssign (
29372938 $ scope ,
@@ -2946,15 +2947,15 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
29462947 if (
29472948 $ functionReflection !== null
29482949 && $ functionReflection ->getName () === 'array_splice '
2949- && count ($ expr ->getArgs ()) >= 2
2950+ && count ($ normalizedExpr ->getArgs ()) >= 2
29502951 ) {
2951- $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2952+ $ arrayArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
29522953 $ arrayArgType = $ scope ->getType ($ arrayArg );
29532954 $ arrayArgNativeType = $ scope ->getNativeType ($ arrayArg );
29542955
2955- $ offsetType = $ scope ->getType ($ expr ->getArgs ()[1 ]->value );
2956- $ lengthType = isset ($ expr ->getArgs ()[2 ]) ? $ scope ->getType ($ expr ->getArgs ()[2 ]->value ) : new NullType ();
2957- $ replacementType = isset ($ expr ->getArgs ()[3 ]) ? $ scope ->getType ($ expr ->getArgs ()[3 ]->value ) : new ConstantArrayType ([], []);
2956+ $ offsetType = $ scope ->getType ($ normalizedExpr ->getArgs ()[1 ]->value );
2957+ $ lengthType = isset ($ normalizedExpr ->getArgs ()[2 ]) ? $ scope ->getType ($ normalizedExpr ->getArgs ()[2 ]->value ) : new NullType ();
2958+ $ replacementType = isset ($ normalizedExpr ->getArgs ()[3 ]) ? $ scope ->getType ($ normalizedExpr ->getArgs ()[3 ]->value ) : new ConstantArrayType ([], []);
29582959
29592960 $ scope = $ this ->processVirtualAssign (
29602961 $ scope ,
@@ -2972,9 +2973,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
29722973 if (
29732974 $ functionReflection !== null
29742975 && in_array ($ functionReflection ->getName (), ['sort ' , 'rsort ' , 'usort ' ], true )
2975- && count ($ expr ->getArgs ()) >= 1
2976+ && count ($ normalizedExpr ->getArgs ()) >= 1
29762977 ) {
2977- $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2978+ $ arrayArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
29782979
29792980 $ scope = $ this ->processVirtualAssign (
29802981 $ scope ,
@@ -2989,9 +2990,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
29892990 if (
29902991 $ functionReflection !== null
29912992 && in_array ($ functionReflection ->getName (), ['natcasesort ' , 'natsort ' , 'arsort ' , 'asort ' , 'ksort ' , 'krsort ' , 'uasort ' , 'uksort ' ], true )
2992- && count ($ expr ->getArgs ()) >= 1
2993+ && count ($ normalizedExpr ->getArgs ()) >= 1
29932994 ) {
2994- $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2995+ $ arrayArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
29952996
29962997 $ scope = $ this ->processVirtualAssign (
29972998 $ scope ,
@@ -3007,7 +3008,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
30073008 $ functionReflection !== null
30083009 && $ functionReflection ->getName () === 'extract '
30093010 ) {
3010- $ extractedArg = $ expr ->getArgs ()[0 ]->value ;
3011+ $ extractedArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
30113012 $ extractedType = $ scope ->getType ($ extractedArg );
30123013 $ constantArrays = $ extractedType ->getConstantArrays ();
30133014 if (count ($ constantArrays ) > 0 ) {
@@ -3121,8 +3122,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
31213122 );
31223123 }
31233124
3125+ $ normalizedExpr = $ expr ;
31243126 if ($ parametersAcceptor !== null ) {
3125- $ expr = ArgumentsNormalizer::reorderMethodArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
3127+ $ normalizedExpr = ArgumentsNormalizer::reorderMethodArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
31263128 $ returnType = $ parametersAcceptor ->getReturnType ();
31273129 $ isAlwaysTerminating = $ returnType instanceof NeverType && $ returnType ->isExplicit ();
31283130 }
@@ -3132,7 +3134,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
31323134 $ methodReflection ,
31333135 $ methodReflection !== null ? $ scope ->getNakedMethod ($ calledOnType , $ methodReflection ->getName ()) : null ,
31343136 $ parametersAcceptor ,
3135- $ expr ,
3137+ $ normalizedExpr ,
31363138 $ scope ,
31373139 $ storage ,
31383140 $ nodeCallback ,
@@ -3143,21 +3145,21 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
31433145 if ($ methodReflection !== null ) {
31443146 $ hasSideEffects = $ methodReflection ->hasSideEffects ();
31453147 if ($ hasSideEffects ->yes () || $ methodReflection ->getName () === '__construct ' ) {
3146- $ this ->callNodeCallback ($ nodeCallback , new InvalidateExprNode ($ expr ->var ), $ scope , $ storage );
3147- $ scope = $ scope ->invalidateExpression ($ expr ->var , true );
3148+ $ this ->callNodeCallback ($ nodeCallback , new InvalidateExprNode ($ normalizedExpr ->var ), $ scope , $ storage );
3149+ $ scope = $ scope ->invalidateExpression ($ normalizedExpr ->var , true );
31483150 }
31493151 if ($ parametersAcceptor !== null && !$ methodReflection ->isStatic ()) {
31503152 $ selfOutType = $ methodReflection ->getSelfOutType ();
31513153 if ($ selfOutType !== null ) {
31523154 $ scope = $ scope ->assignExpression (
3153- $ expr ->var ,
3155+ $ normalizedExpr ->var ,
31543156 TemplateTypeHelper::resolveTemplateTypes (
31553157 $ selfOutType ,
31563158 $ parametersAcceptor ->getResolvedTemplateTypeMap (),
31573159 $ parametersAcceptor instanceof ExtendedParametersAcceptor ? $ parametersAcceptor ->getCallSiteVarianceMap () : TemplateTypeVarianceMap::createEmpty (),
31583160 TemplateTypeVariance::createCovariant (),
31593161 ),
3160- $ scope ->getNativeType ($ expr ->var ),
3162+ $ scope ->getNativeType ($ normalizedExpr ->var ),
31613163 );
31623164 }
31633165 }
@@ -3320,12 +3322,13 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
33203322 );
33213323 }
33223324
3325+ $ normalizedExpr = $ expr ;
33233326 if ($ parametersAcceptor !== null ) {
3324- $ expr = ArgumentsNormalizer::reorderStaticCallArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
3327+ $ normalizedExpr = ArgumentsNormalizer::reorderStaticCallArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
33253328 $ returnType = $ parametersAcceptor ->getReturnType ();
33263329 $ isAlwaysTerminating = $ returnType instanceof NeverType && $ returnType ->isExplicit ();
33273330 }
3328- $ result = $ this ->processArgs ($ stmt , $ methodReflection , null , $ parametersAcceptor , $ expr , $ scope , $ storage , $ nodeCallback , $ context , $ closureBindScope ?? null );
3331+ $ result = $ this ->processArgs ($ stmt , $ methodReflection , null , $ parametersAcceptor , $ normalizedExpr , $ scope , $ storage , $ nodeCallback , $ context , $ closureBindScope ?? null );
33293332 $ scope = $ result ->getScope ();
33303333 $ scopeFunction = $ scope ->getFunction ();
33313334
@@ -3857,6 +3860,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
38573860 $ impurePoints = [];
38583861 $ isAlwaysTerminating = false ;
38593862 $ className = null ;
3863+ $ normalizedExpr = $ expr ;
38603864 if ($ expr ->class instanceof Expr || $ expr ->class instanceof Name) {
38613865 if ($ expr ->class instanceof Expr) {
38623866 $ objectClasses = $ scope ->getType ($ expr )->getObjectClassNames ();
@@ -3923,7 +3927,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
39233927 }
39243928
39253929 if ($ parametersAcceptor !== null ) {
3926- $ expr = ArgumentsNormalizer::reorderNewArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
3930+ $ normalizedExpr = ArgumentsNormalizer::reorderNewArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
39273931 }
39283932
39293933 } else {
@@ -3987,7 +3991,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
39873991 }
39883992 }
39893993
3990- $ result = $ this ->processArgs ($ stmt , $ constructorReflection , null , $ parametersAcceptor , $ expr , $ scope , $ storage , $ nodeCallback , $ context );
3994+ $ result = $ this ->processArgs ($ stmt , $ constructorReflection , null , $ parametersAcceptor , $ normalizedExpr , $ scope , $ storage , $ nodeCallback , $ context );
39913995 $ scope = $ result ->getScope ();
39923996 $ hasYield = $ hasYield || $ result ->hasYield ();
39933997 $ throwPoints = array_merge ($ throwPoints , $ result ->getThrowPoints ());
0 commit comments