1515use PHPStan \DependencyInjection \AutowiredService ;
1616use PHPStan \TrinaryLogic ;
1717use PHPStan \Type \TypeCombinator ;
18- use function array_unshift ;
1918
2019#[AutowiredService]
2120final class NonNullabilityHelper
@@ -32,9 +31,7 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
3231 // keep certainty
3332 $ certainty = TrinaryLogic::createYes ();
3433 $ hasExpressionType = $ originalScope ->hasExpressionType ($ exprToSpecify );
35- if (
36- !$ hasExpressionType ->no ()
37- ) {
34+ if (!$ hasExpressionType ->no ()) {
3835 $ certainty = $ hasExpressionType ;
3936 }
4037
@@ -51,11 +48,7 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
5148 return new EnsuredNonNullabilityResult ($ scope , []);
5249 }
5350
54- $ nativeType = $ scope ->getNativeType ($ exprToSpecify );
55-
56- $ specifiedExpressions = [
57- new EnsuredNonNullabilityResultExpression ($ exprToSpecify , $ exprType , $ nativeType , $ certainty ),
58- ];
51+ $ specifiedExpressions = [];
5952
6053 // When narrowing an ArrayDimFetch, specifyExpressionType also recursively
6154 // narrows the parent array's offset type via intersection with HasOffsetValueType.
@@ -64,14 +57,16 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
6457 $ parentExpr = $ exprToSpecify ->var ;
6558 $ hasParentExpressionType = $ originalScope ->hasExpressionType ($ parentExpr );
6659
67- array_unshift ( $ specifiedExpressions, new EnsuredNonNullabilityResultExpression (
60+ $ specifiedExpressions[] = new EnsuredNonNullabilityResultExpression (
6861 $ parentExpr ,
6962 $ scope ->getType ($ parentExpr ),
7063 $ scope ->getNativeType ($ parentExpr ),
7164 $ hasParentExpressionType ,
72- )) ;
65+ );
7366 }
7467
68+ $ nativeType = $ scope ->getNativeType ($ exprToSpecify );
69+ $ specifiedExpressions [] = new EnsuredNonNullabilityResultExpression ($ exprToSpecify , $ exprType , $ nativeType , $ certainty );
7570 $ scope = $ scope ->specifyExpressionType (
7671 $ exprToSpecify ,
7772 $ exprTypeWithoutNull ,
0 commit comments