Skip to content

Commit c8435cd

Browse files
staabmondrejmirtes
authored andcommitted
Refactor: NonNullabilityHelper
1 parent cd5a6f6 commit c8435cd

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/Analyser/ExprHandler/Helper/NonNullabilityHelper.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PHPStan\DependencyInjection\AutowiredService;
1616
use PHPStan\TrinaryLogic;
1717
use PHPStan\Type\TypeCombinator;
18-
use function array_unshift;
1918

2019
#[AutowiredService]
2120
final class NonNullabilityHelper
@@ -49,11 +48,7 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
4948
return new EnsuredNonNullabilityResult($scope, []);
5049
}
5150

52-
$nativeType = $scope->getNativeType($exprToSpecify);
53-
54-
$specifiedExpressions = [
55-
new EnsuredNonNullabilityResultExpression($exprToSpecify, $exprType, $nativeType, $certainty),
56-
];
51+
$specifiedExpressions = [];
5752

5853
// When narrowing an ArrayDimFetch, specifyExpressionType also recursively
5954
// narrows the parent array's offset type via intersection with HasOffsetValueType.
@@ -65,14 +60,16 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
6560
if (!$hasParentExpressionType->no()) {
6661
$parentCertainty = $hasParentExpressionType;
6762
}
68-
array_unshift($specifiedExpressions, new EnsuredNonNullabilityResultExpression(
63+
$specifiedExpressions[] = new EnsuredNonNullabilityResultExpression(
6964
$parentExpr,
7065
$scope->getType($parentExpr),
7166
$scope->getNativeType($parentExpr),
7267
$parentCertainty,
73-
));
68+
);
7469
}
7570

71+
$nativeType = $scope->getNativeType($exprToSpecify);
72+
$specifiedExpressions[] = new EnsuredNonNullabilityResultExpression($exprToSpecify, $exprType, $nativeType, $certainty);
7673
$scope = $scope->specifyExpressionType(
7774
$exprToSpecify,
7875
$exprTypeWithoutNull,

0 commit comments

Comments
 (0)