8383use PHPStan \Node \Expr \PropertyInitializationExpr ;
8484use PHPStan \Node \Expr \SetExistingOffsetValueTypeExpr ;
8585use PHPStan \Node \Expr \SetOffsetValueTypeExpr ;
86+ use PHPStan \Node \Expr \TypeExpr ;
8687use PHPStan \Node \Expr \UnsetOffsetExpr ;
8788use PHPStan \Node \FinallyExitPointsNode ;
8889use PHPStan \Node \FunctionCallableNode ;
107108use PHPStan \Node \ReturnStatement ;
108109use PHPStan \Node \StaticMethodCallableNode ;
109110use PHPStan \Node \UnreachableStatementNode ;
111+ use PHPStan \Node \VariableAssignNode ;
110112use PHPStan \Node \VarTagChangedExpressionTypeNode ;
111113use PHPStan \Parser \ArrowFunctionArgVisitor ;
112114use PHPStan \Parser \ClosureArgVisitor ;
@@ -1554,7 +1556,7 @@ public function leaveNode(Node $node): ?ExistingArrayDimFetch
15541556 $ clonedVar ,
15551557 new UnsetOffsetExpr ($ var ->var , $ var ->dim ),
15561558 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
1557- if (!$ node instanceof PropertyAssignNode) {
1559+ if (!$ node instanceof PropertyAssignNode && ! $ node instanceof VariableAssignNode ) {
15581560 return ;
15591561 }
15601562
@@ -2845,7 +2847,7 @@ static function (): void {
28452847 $ expr ->var ,
28462848 $ newExpr ,
28472849 static function (Node $ node , Scope $ scope ) use ($ nodeCallback ): void {
2848- if (!$ node instanceof PropertyAssignNode) {
2850+ if (!$ node instanceof PropertyAssignNode && ! $ node instanceof VariableAssignNode ) {
28492851 return ;
28502852 }
28512853
@@ -3891,6 +3893,7 @@ private function processArgs(
38913893 if ($ assignByReference ) {
38923894 $ argValue = $ arg ->value ;
38933895 if ($ argValue instanceof Variable && is_string ($ argValue ->name )) {
3896+ $ nodeCallback (new VariableAssignNode ($ argValue , new TypeExpr ($ byRefType ), false ), $ scope );
38943897 $ scope = $ scope ->assignVariable ($ argValue ->name , $ byRefType , new MixedType ());
38953898 } else {
38963899 $ scope = $ scope ->invalidateExpression ($ argValue );
@@ -3987,6 +3990,7 @@ private function processAssignVar(
39873990 $ conditionalExpressions = $ this ->processSureTypesForConditionalExpressionsAfterAssign ($ scope , $ var ->name , $ conditionalExpressions , $ falseySpecifiedTypes , $ falseyType );
39883991 $ conditionalExpressions = $ this ->processSureNotTypesForConditionalExpressionsAfterAssign ($ scope , $ var ->name , $ conditionalExpressions , $ falseySpecifiedTypes , $ falseyType );
39893992
3993+ $ nodeCallback (new VariableAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ result ->getScope ());
39903994 $ scope = $ result ->getScope ()->assignVariable ($ var ->name , $ type , $ scope ->getNativeType ($ assignedExpr ));
39913995 foreach ($ conditionalExpressions as $ exprString => $ holders ) {
39923996 $ scope = $ scope ->addConditionalExpressions ($ exprString , $ holders );
@@ -4143,6 +4147,7 @@ private function processAssignVar(
41434147
41444148 if ($ varType ->isArray ()->yes () || !(new ObjectType (ArrayAccess::class))->isSuperTypeOf ($ varType )->yes ()) {
41454149 if ($ var instanceof Variable && is_string ($ var ->name )) {
4150+ $ nodeCallback (new VariableAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scope );
41464151 $ scope = $ scope ->assignVariable ($ var ->name , $ valueToWrite , $ nativeValueToWrite );
41474152 } else {
41484153 if ($ var instanceof PropertyFetch || $ var instanceof StaticPropertyFetch) {
@@ -4169,7 +4174,9 @@ private function processAssignVar(
41694174 }
41704175 }
41714176 } else {
4172- if ($ var instanceof PropertyFetch || $ var instanceof StaticPropertyFetch) {
4177+ if ($ var instanceof Variable) {
4178+ $ nodeCallback (new VariableAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scope );
4179+ } elseif ($ var instanceof PropertyFetch || $ var instanceof StaticPropertyFetch) {
41734180 $ nodeCallback (new PropertyAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scope );
41744181 if ($ var instanceof PropertyFetch && $ var ->name instanceof Node \Identifier && !$ isAssignOp ) {
41754182 $ scope = $ scope ->assignInitializedProperty ($ scope ->getType ($ var ->var ), $ var ->name ->toString ());
@@ -4385,6 +4392,7 @@ static function (): void {
43854392 }
43864393
43874394 if ($ var instanceof Variable && is_string ($ var ->name )) {
4395+ $ nodeCallback (new VariableAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scope );
43884396 $ scope = $ scope ->assignVariable ($ var ->name , $ valueToWrite , $ nativeValueToWrite );
43894397 } else {
43904398 if ($ var instanceof PropertyFetch || $ var instanceof StaticPropertyFetch) {
0 commit comments