@@ -163,6 +163,9 @@ public function processNodes(
163163if (!($ node instanceof \PhpParser \Node)) {
164164continue ;
165165}
166+ if ($ node instanceof Node \Stmt \Expression) {
167+ $ node = $ node ->expr ;
168+ }
166169
167170if ($ scope ->getInFunctionCall () !== null && $ node instanceof Arg) {
168171$ functionCall = $ scope ->getInFunctionCall ();
@@ -247,6 +250,10 @@ private function specifyProperty(Scope $scope, Expr $expr): Scope
247250
248251private function specifyFetchedPropertyForInnerScope (Node $ node , Scope $ inScope , bool $ inEarlyTermination , Scope &$ scope ): void
249252{
253+ if ($ node instanceof Node \Stmt \Expression) {
254+ $ node = $ node ->expr ;
255+ }
256+
250257if ($ inEarlyTermination === $ inScope ->isNegated ()) {
251258if ($ node instanceof Isset_) {
252259foreach ($ node ->vars as $ var ) {
@@ -276,6 +283,10 @@ private function specifyFetchedPropertyForInnerScope(Node $node, Scope $inScope,
276283
277284private function lookForArrayDestructuringArray (Scope $ scope , Node $ node ): Scope
278285{
286+ if ($ node instanceof Node \Stmt \Expression) {
287+ $ node = $ node ->expr ;
288+ }
289+
279290if ($ node instanceof Array_) {
280291foreach ($ node ->items as $ item ) {
281292if ($ item === null ) {
@@ -867,6 +878,10 @@ private function ensureNonNullability(
867878bool $ findMethods
868879): Scope
869880{
881+ if ($ node instanceof Node \Stmt \Expression) {
882+ $ node = $ node ->expr ;
883+ }
884+
870885$ scope = $ this ->assignVariable ($ scope , $ node , TrinaryLogic::createYes ());
871886$ nodeToSpecify = $ node ;
872887while (
@@ -950,6 +965,10 @@ private function lookForAssigns(
950965LookForAssignsSettings $ lookForAssignsSettings
951966): Scope
952967{
968+ if ($ node instanceof Node \Stmt \Expression) {
969+ $ node = $ node ->expr ;
970+ }
971+
953972if ($ node instanceof StaticVar) {
954973if (!is_string ($ node ->var ->name )) {
955974throw new \PHPStan \ShouldNotHappenException ();
@@ -1339,6 +1358,10 @@ private function updateScopeForVariableAssign(
13391358LookForAssignsSettings $ lookForAssignsSettings
13401359): Scope
13411360{
1361+ if ($ node instanceof Node \Stmt \Expression) {
1362+ $ node = $ node ->expr ;
1363+ }
1364+
13421365if ($ node instanceof Assign || $ node instanceof AssignRef || $ node instanceof Expr \AssignOp || $ node instanceof Node \Stmt \Global_) {
13431366if ($ node instanceof Assign || $ node instanceof AssignRef || $ node instanceof Expr \AssignOp) {
13441367$ scope = $ this ->lookForAssigns ($ scope , $ node ->var , TrinaryLogic::createYes (), $ lookForAssignsSettings );
@@ -1438,6 +1461,10 @@ private function assignVariable(
14381461?Type $ subNodeType = null
14391462): Scope
14401463{
1464+ if ($ var instanceof Node \Stmt \Expression) {
1465+ $ var = $ var ->expr ;
1466+ }
1467+
14411468if ($ var instanceof Variable && is_string ($ var ->name )) {
14421469$ scope = $ scope ->assignVariable ($ var ->name , $ subNodeType !== null ? $ subNodeType : new MixedType (), $ certainty );
14431470} elseif ($ var instanceof ArrayDimFetch) {
@@ -1588,6 +1615,10 @@ private function lookForAssignsInBranches(
15881615private function findEarlyTermination (array $ statements , Scope $ scope ): ?\PhpParser \Node
15891616{
15901617foreach ($ statements as $ statement ) {
1618+ if ($ statement instanceof Node \Stmt \Expression) {
1619+ $ statement = $ statement ->expr ;
1620+ }
1621+
15911622$ statement = $ this ->findStatementEarlyTermination ($ statement , $ scope );
15921623if ($ statement !== null ) {
15931624return $ statement ;
@@ -1599,6 +1630,10 @@ private function findEarlyTermination(array $statements, Scope $scope): ?\PhpPar
15991630
16001631private function findStatementEarlyTermination (Node $ statement , Scope $ scope ): ?\PhpParser \Node
16011632{
1633+ if ($ statement instanceof Node \Stmt \Expression) {
1634+ $ statement = $ statement ->expr ;
1635+ }
1636+
16021637if (
16031638$ statement instanceof Throw_
16041639|| $ statement instanceof Return_
@@ -1737,6 +1772,10 @@ private function processTraitUse(Node\Stmt\TraitUse $node, Scope $classScope, \C
17371772private function processNodesForTraitUse ($ node , string $ traitName , Scope $ classScope , \Closure $ nodeCallback ): void
17381773{
17391774if ($ node instanceof Node) {
1775+ if ($ node instanceof Node \Stmt \Expression) {
1776+ $ node = $ node ->expr ;
1777+ }
1778+
17401779if ($ node instanceof Node \Stmt \Trait_ && $ traitName === (string ) $ node ->namespacedName ) {
17411780$ this ->processNodes ($ node ->stmts , $ classScope ->enterFirstLevelStatements (), $ nodeCallback );
17421781return ;
0 commit comments