Skip to content

Commit

Permalink
Optimization?
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 3, 2022
1 parent 91c7507 commit 5400b58
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,24 @@ public function getOffsetValueType(Type $offsetType): Type
{
$offsetType = ArrayType::castToArrayKeyType($offsetType);
$matchingValueTypes = [];
$all = true;
foreach ($this->keyTypes as $i => $keyType) {
if ($keyType->isSuperTypeOf($offsetType)->no()) {
$all = false;
continue;
}

$matchingValueTypes[] = $this->valueTypes[$i];
}

if ($all) {
if (count($this->keyTypes) === 0) {
return new ErrorType();
}

return $this->getIterableValueType();
}

if (count($matchingValueTypes) > 0) {
$type = TypeCombinator::union(...$matchingValueTypes);
if ($type instanceof ErrorType) {
Expand Down

0 comments on commit 5400b58

Please sign in to comment.