114114use PHPStan \Node \MethodReturnStatementsNode ;
115115use PHPStan \Node \NoopExpressionNode ;
116116use PHPStan \Node \PropertyAssignNode ;
117+ use PHPStan \Node \PropertyHookStatementNode ;
117118use PHPStan \Node \ReturnStatement ;
118119use PHPStan \Node \StaticMethodCallableNode ;
119120use PHPStan \Node \UnreachableStatementNode ;
@@ -343,6 +344,7 @@ public function processStmtNodes(
343344 $ stmtCount = count ($ stmts );
344345 $ shouldCheckLastStatement = $ parentNode instanceof Node \Stmt \Function_
345346 || $ parentNode instanceof Node \Stmt \ClassMethod
347+ || $ parentNode instanceof PropertyHookStatementNode
346348 || $ parentNode instanceof Expr \Closure;
347349 foreach ($ stmts as $ i => $ stmt ) {
348350 if ($ alreadyTerminated && !($ stmt instanceof Node \Stmt \Function_ || $ stmt instanceof Node \Stmt \ClassLike)) {
@@ -360,7 +362,7 @@ public function processStmtNodes(
360362 $ hasYield = $ hasYield || $ statementResult ->hasYield ();
361363
362364 if ($ shouldCheckLastStatement && $ isLast ) {
363- /** @var Node\Stmt\Function_|Node\Stmt\ClassMethod|Expr\Closure $parentNode */
365+ /** @var Node\Stmt\Function_|Node\Stmt\ClassMethod|PropertyHookStatementNode| Expr\Closure $parentNode */
364366 $ parentNode = $ parentNode ;
365367
366368 $ endStatements = $ statementResult ->getEndStatements ();
@@ -377,7 +379,7 @@ public function processStmtNodes(
377379 $ endStatementResult ->getThrowPoints (),
378380 $ endStatementResult ->getImpurePoints (),
379381 ),
380- $ parentNode ->returnType !== null ,
382+ $ parentNode ->getReturnType () !== null ,
381383 ), $ endStatementResult ->getScope ());
382384 }
383385 } else {
@@ -391,7 +393,7 @@ public function processStmtNodes(
391393 $ statementResult ->getThrowPoints (),
392394 $ statementResult ->getImpurePoints (),
393395 ),
394- $ parentNode ->returnType !== null ,
396+ $ parentNode ->getReturnType () !== null ,
395397 ), $ scope );
396398 }
397399 }
@@ -414,9 +416,9 @@ public function processStmtNodes(
414416
415417 $ statementResult = new StatementResult ($ scope , $ hasYield , $ alreadyTerminated , $ exitPoints , $ throwPoints , $ impurePoints );
416418 if ($ stmtCount === 0 && $ shouldCheckLastStatement ) {
417- /** @var Node\Stmt\Function_|Node\Stmt\ClassMethod|Expr\Closure $parentNode */
419+ /** @var Node\Stmt\Function_|Node\Stmt\ClassMethod|PropertyHookStatementNode| Expr\Closure $parentNode */
418420 $ parentNode = $ parentNode ;
419- $ returnTypeNode = $ parentNode ->returnType ;
421+ $ returnTypeNode = $ parentNode ->getReturnType () ;
420422 if ($ parentNode instanceof Expr \Closure) {
421423 $ parentNode = new Node \Stmt \Expression ($ parentNode , $ parentNode ->getAttributes ());
422424 }
@@ -4700,7 +4702,7 @@ private function processPropertyHooks(
47004702 $ this ->processExprNode ($ stmt , $ hook ->body , $ hookScope , $ nodeCallback , ExpressionContext::createTopLevel ());
47014703 $ nodeCallback (new PropertyAssignNode (new PropertyFetch (new Variable ('this ' ), $ propertyName , $ hook ->body ->getAttributes ()), $ hook ->body , false ), $ hookScope );
47024704 } elseif (is_array ($ hook ->body )) {
4703- $ this ->processStmtNodes ($ stmt , $ hook ->body , $ hookScope , $ nodeCallback , StatementContext::createTopLevel ());
4705+ $ this ->processStmtNodes (new PropertyHookStatementNode ( $ hook ) , $ hook ->body , $ hookScope , $ nodeCallback , StatementContext::createTopLevel ());
47044706 }
47054707
47064708 }
0 commit comments