Skip to content

Commit 7e0f73b

Browse files
Improve
1 parent 6f99f04 commit 7e0f73b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Rules/Arrays/InvalidKeyInArrayDimFetchRule.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public function processNode(Node $node, Scope $scope): array
4747
static fn (Type $varType): bool => $varType->isArray()->no(),
4848
)->getType();
4949

50-
if ($varType instanceof ErrorType || $varType->isArray()->no()) {
50+
if ($varType instanceof ErrorType) {
51+
return [];
52+
}
53+
54+
$isArray = $varType->isArray();
55+
if ($isArray->no() || ($isArray->maybe() && !$this->reportMaybes)) {
5156
return [];
5257
}
5358

@@ -68,7 +73,11 @@ public function processNode(Node $node, Scope $scope): array
6873

6974
return [
7075
RuleErrorBuilder::message(
71-
sprintf('%s array key type %s.', $isSuperType->no() ? 'Invalid' : 'Possibly invalid', $dimensionType->describe(VerbosityLevel::typeOnly())),
76+
sprintf(
77+
'%s array key type %s.',
78+
$isArray->yes() && $isSuperType->no() ? 'Invalid' : 'Possibly invalid',
79+
$dimensionType->describe(VerbosityLevel::typeOnly()),
80+
),
7281
)->identifier('offsetAccess.invalidOffset')->build(),
7382
];
7483
}

tests/PHPStan/Levels/data/arrayOffsetAccess-7.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"ignorable": true
1111
},
1212
{
13-
"message": "Invalid array key type DateTimeImmutable.",
13+
"message": "Possibly invalid array key type DateTimeImmutable.",
1414
"line": 26,
1515
"ignorable": true
1616
},

0 commit comments

Comments
 (0)