Skip to content

Commit 106fc93

Browse files
authored
Cleanup ConstantArrayTypeBuilder (#4955)
1 parent ebc5354 commit 106fc93

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ parameters:
948948
-
949949
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
950950
identifier: phpstanApi.instanceofType
951-
count: 2
951+
count: 1
952952
path: src/Type/Constant/ConstantArrayTypeBuilder.php
953953

954954
-

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
240240
return;
241241
}
242242

243-
$scalarTypes = $offsetType->getConstantScalarTypes();
243+
$scalarTypes = $offsetType->toArrayKey()->getConstantScalarTypes();
244244
if (count($scalarTypes) === 0) {
245245
$integerRanges = TypeUtils::getIntegerRanges($offsetType);
246246
if (count($integerRanges) > 0) {
@@ -260,15 +260,11 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
260260
$match = true;
261261
$valueTypes = $this->valueTypes;
262262
foreach ($scalarTypes as $scalarType) {
263-
$scalarOffsetType = $scalarType->toArrayKey();
264-
if (!$scalarOffsetType instanceof ConstantIntegerType && !$scalarOffsetType instanceof ConstantStringType) {
265-
throw new ShouldNotHappenException();
266-
}
267263
$offsetMatch = false;
268264

269265
/** @var ConstantIntegerType|ConstantStringType $keyType */
270266
foreach ($this->keyTypes as $i => $keyType) {
271-
if ($keyType->getValue() !== $scalarOffsetType->getValue()) {
267+
if ($keyType->getValue() !== $scalarType->getValue()) {
272268
continue;
273269
}
274270

0 commit comments

Comments
 (0)