Skip to content

Commit d6dab64

Browse files
committed
Faster ArrayType->hasOffsetValueType()
1 parent 0fbb507 commit d6dab64

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Type/ArrayType.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,12 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
268268

269269
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
270270
{
271-
$allowedArrayKeys = AllowedArrayKeysTypes::getType();
272-
$offsetType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey();
271+
$offsetArrayKeyType = $offsetType->toArrayKey();
272+
if ($offsetArrayKeyType instanceof ErrorType) {
273+
$allowedArrayKeys = AllowedArrayKeysTypes::getType();
274+
$offsetArrayKeyType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey();
275+
}
276+
$offsetType = $offsetArrayKeyType;
273277

274278
if ($this->getKeyType()->isSuperTypeOf($offsetType)->no()
275279
&& ($offsetType->isString()->no() || !$offsetType->isConstantScalarValue()->no())

0 commit comments

Comments
 (0)