8989use PHPStan \Node \Expr \GetIterableKeyTypeExpr ;
9090use PHPStan \Node \Expr \GetIterableValueTypeExpr ;
9191use PHPStan \Node \Expr \GetOffsetValueTypeExpr ;
92+ use PHPStan \Node \Expr \NativeTypeExpr ;
9293use PHPStan \Node \Expr \OriginalPropertyTypeExpr ;
9394use PHPStan \Node \Expr \PropertyInitializationExpr ;
9495use PHPStan \Node \Expr \SetExistingOffsetValueTypeExpr ;
@@ -2662,20 +2663,16 @@ static function (): void {
26622663
26632664 $ arrayArgType = $ scope ->getType ($ arrayArg );
26642665 $ arrayArgNativeType = $ scope ->getNativeType ($ arrayArg );
2665-
26662666 $ isArrayPop = $ functionReflection ->getName () === 'array_pop ' ;
2667- $ newType = $ isArrayPop ? $ arrayArgType ->popArray () : $ arrayArgType ->shiftArray ();
2668- $ scope = $ scope ->invalidateExpression ($ arrayArg )->assignExpression (
2669- $ arrayArg ,
2670- $ newType ,
2671- $ isArrayPop ? $ arrayArgNativeType ->popArray () : $ arrayArgNativeType ->shiftArray (),
2672- );
26732667
26742668 $ scope = $ this ->processAssignVar (
26752669 $ scope ,
26762670 $ stmt ,
26772671 $ arrayArg ,
2678- new TypeExpr ($ newType ),
2672+ new NativeTypeExpr (
2673+ $ isArrayPop ? $ arrayArgType ->popArray () : $ arrayArgType ->shiftArray (),
2674+ $ isArrayPop ? $ arrayArgNativeType ->popArray () : $ arrayArgNativeType ->shiftArray (),
2675+ ),
26792676 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
26802677 if (!$ node instanceof PropertyAssignNode && !$ node instanceof VariableAssignNode) {
26812678 return ;
@@ -2694,17 +2691,16 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
26942691 && in_array ($ functionReflection ->getName (), ['array_push ' , 'array_unshift ' ], true )
26952692 && count ($ expr ->getArgs ()) >= 2
26962693 ) {
2697- $ arrayType = $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope , $ expr );
2698- $ arrayNativeType = $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope ->doNotTreatPhpDocTypesAsCertain (), $ expr );
2699-
27002694 $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2701- $ scope = $ scope ->invalidateExpression ($ arrayArg )->assignExpression ($ arrayArg , $ arrayType , $ arrayNativeType );
27022695
27032696 $ scope = $ this ->processAssignVar (
27042697 $ scope ,
27052698 $ stmt ,
27062699 $ arrayArg ,
2707- new TypeExpr ($ arrayType ),
2700+ new NativeTypeExpr (
2701+ $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope , $ expr ),
2702+ $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope ->doNotTreatPhpDocTypesAsCertain (), $ expr ),
2703+ ),
27082704 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
27092705 if (!$ node instanceof PropertyAssignNode && !$ node instanceof VariableAssignNode) {
27102706 return ;
@@ -2730,18 +2726,12 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
27302726 && $ functionReflection ->getName () === 'shuffle '
27312727 ) {
27322728 $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2733- $ newType = $ scope ->getType ($ arrayArg )->shuffleArray ();
2734- $ scope = $ scope ->assignExpression (
2735- $ arrayArg ,
2736- $ newType ,
2737- $ scope ->getNativeType ($ arrayArg )->shuffleArray (),
2738- );
27392729
27402730 $ scope = $ this ->processAssignVar (
27412731 $ scope ,
27422732 $ stmt ,
27432733 $ arrayArg ,
2744- new TypeExpr ( $ newType ),
2734+ new NativeTypeExpr ( $ scope -> getType ( $ arrayArg )-> shuffleArray (), $ scope -> getNativeType ( $ arrayArg )-> shuffleArray () ),
27452735 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
27462736 if (!$ node instanceof PropertyAssignNode && !$ node instanceof VariableAssignNode) {
27472737 return ;
@@ -2768,18 +2758,14 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
27682758 $ lengthType = isset ($ expr ->getArgs ()[2 ]) ? $ scope ->getType ($ expr ->getArgs ()[2 ]->value ) : new NullType ();
27692759 $ replacementType = isset ($ expr ->getArgs ()[3 ]) ? $ scope ->getType ($ expr ->getArgs ()[3 ]->value ) : new ConstantArrayType ([], []);
27702760
2771- $ newType = $ arrayArgType ->spliceArray ($ offsetType , $ lengthType , $ replacementType );
2772- $ scope = $ scope ->invalidateExpression ($ arrayArg )->assignExpression (
2773- $ arrayArg ,
2774- $ newType ,
2775- $ arrayArgNativeType ->spliceArray ($ offsetType , $ lengthType , $ replacementType ),
2776- );
2777-
27782761 $ scope = $ this ->processAssignVar (
27792762 $ scope ,
27802763 $ stmt ,
27812764 $ arrayArg ,
2782- new TypeExpr ($ newType ),
2765+ new NativeTypeExpr (
2766+ $ arrayArgType ->spliceArray ($ offsetType , $ lengthType , $ replacementType ),
2767+ $ arrayArgNativeType ->spliceArray ($ offsetType , $ lengthType , $ replacementType ),
2768+ ),
27832769 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
27842770 if (!$ node instanceof PropertyAssignNode && !$ node instanceof VariableAssignNode) {
27852771 return ;
@@ -2799,18 +2785,12 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
27992785 && count ($ expr ->getArgs ()) >= 1
28002786 ) {
28012787 $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2802- $ newType = $ this ->getArraySortPreserveListFunctionType ($ scope ->getType ($ arrayArg ));
2803- $ scope = $ scope ->assignExpression (
2804- $ arrayArg ,
2805- $ newType ,
2806- $ this ->getArraySortPreserveListFunctionType ($ scope ->getNativeType ($ arrayArg )),
2807- );
28082788
28092789 $ scope = $ this ->processAssignVar (
28102790 $ scope ,
28112791 $ stmt ,
28122792 $ arrayArg ,
2813- new TypeExpr ( $ newType ),
2793+ new NativeTypeExpr ( $ this -> getArraySortPreserveListFunctionType ( $ scope -> getType ( $ arrayArg )), $ this -> getArraySortPreserveListFunctionType ( $ scope -> getNativeType ( $ arrayArg )) ),
28142794 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
28152795 if (!$ node instanceof PropertyAssignNode && !$ node instanceof VariableAssignNode) {
28162796 return ;
@@ -2830,18 +2810,12 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
28302810 && count ($ expr ->getArgs ()) >= 1
28312811 ) {
28322812 $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
2833- $ newType = $ this ->getArraySortDoNotPreserveListFunctionType ($ scope ->getType ($ arrayArg ));
2834- $ scope = $ scope ->assignExpression (
2835- $ arrayArg ,
2836- $ newType ,
2837- $ this ->getArraySortDoNotPreserveListFunctionType ($ scope ->getNativeType ($ arrayArg )),
2838- );
28392813
28402814 $ scope = $ this ->processAssignVar (
28412815 $ scope ,
28422816 $ stmt ,
28432817 $ arrayArg ,
2844- new TypeExpr ( $ newType ),
2818+ new NativeTypeExpr ( $ this -> getArraySortDoNotPreserveListFunctionType ( $ scope -> getType ( $ arrayArg )), $ this -> getArraySortDoNotPreserveListFunctionType ( $ scope -> getNativeType ( $ arrayArg )) ),
28452819 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
28462820 if (!$ node instanceof PropertyAssignNode && !$ node instanceof VariableAssignNode) {
28472821 return ;
0 commit comments