Skip to content

Commit fe6a172

Browse files
staabmondrejmirtes
authored andcommitted
Lazier type-resolving in isset-checks
1 parent c6e9577 commit fe6a172

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Analyser/MutatingScope.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1995,17 +1995,17 @@ public function issetCheck(Expr $expr, callable $typeCallback, ?bool $result = n
19951995
return $result;
19961996
} elseif ($expr instanceof Node\Expr\ArrayDimFetch && $expr->dim !== null) {
19971997
$type = $this->getType($expr->var);
1998-
$dimType = $this->getType($expr->dim);
1999-
$hasOffsetValue = $type->hasOffsetValueType($dimType);
20001998
if (!$type->isOffsetAccessible()->yes()) {
20011999
return $result ?? $this->issetCheckUndefined($expr->var);
20022000
}
20032001

2002+
$dimType = $this->getType($expr->dim);
2003+
$hasOffsetValue = $type->hasOffsetValueType($dimType);
20042004
if ($hasOffsetValue->no()) {
20052005
return false;
20062006
}
20072007

2008-
// If offset is cannot be null, store this error message and see if one of the earlier offsets is.
2008+
// If offset cannot be null, store this error message and see if one of the earlier offsets is.
20092009
// E.g. $array['a']['b']['c'] ?? null; is a valid coalesce if a OR b or C might be null.
20102010
if ($hasOffsetValue->yes()) {
20112011
$result = $typeCallback($type->getOffsetValueType($dimType));

src/Rules/IssetCheck.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function check(Expr $expr, Scope $scope, string $operatorDescription, cal
5959
$type = $this->treatPhpDocTypesAsCertain
6060
? $scope->getType($expr->var)
6161
: $scope->getNativeType($expr->var);
62-
$dimType = $this->treatPhpDocTypesAsCertain
63-
? $scope->getType($expr->dim)
64-
: $scope->getNativeType($expr->dim);
65-
$hasOffsetValue = $type->hasOffsetValueType($dimType);
6662
if (!$type->isOffsetAccessible()->yes()) {
6763
return $error ?? $this->checkUndefined($expr->var, $scope, $operatorDescription);
6864
}
6965

66+
$dimType = $this->treatPhpDocTypesAsCertain
67+
? $scope->getType($expr->dim)
68+
: $scope->getNativeType($expr->dim);
69+
$hasOffsetValue = $type->hasOffsetValueType($dimType);
7070
if ($hasOffsetValue->no()) {
7171
if (!$this->checkAdvancedIsset) {
7272
return null;
@@ -82,7 +82,7 @@ public function check(Expr $expr, Scope $scope, string $operatorDescription, cal
8282
)->build();
8383
}
8484

85-
// If offset is cannot be null, store this error message and see if one of the earlier offsets is.
85+
// If offset cannot be null, store this error message and see if one of the earlier offsets is.
8686
// E.g. $array['a']['b']['c'] ?? null; is a valid coalesce if a OR b or C might be null.
8787
if ($hasOffsetValue->yes() || $scope->hasExpressionType($expr)->yes()) {
8888
if (!$this->checkAdvancedIsset) {

0 commit comments

Comments
 (0)