Skip to content

Commit

Permalink
fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Oct 12, 2022
1 parent 89d446e commit cbf413f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Type/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,22 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $uni
$offsetType = self::castToArrayKeyType($offsetType);
}

$isConstantOffset = $offsetType instanceof ConstantStringType || $offsetType instanceof ConstantIntegerType;

if ($isConstantOffset && $offsetType->isSuperTypeOf($this->keyType)->yes()) {
if (
($offsetType instanceof ConstantStringType || $offsetType instanceof ConstantIntegerType)
&& $offsetType->isSuperTypeOf($this->keyType)->yes()
) {
$builder = ConstantArrayTypeBuilder::createEmpty();
$builder->setOffsetValueType($offsetType, $valueType);
return $builder->getArray();
}

$array = new self(
TypeCombinator::union($this->keyType, $offsetType),
$unionValues || $isConstantOffset ? TypeCombinator::union($this->itemType, $valueType) : $valueType,
$unionValues || $offsetType instanceof ConstantStringType || $offsetType instanceof ConstantIntegerType
? TypeCombinator::union($this->itemType, $valueType)
: $valueType,
);
if ($isConstantOffset) {
if ($offsetType instanceof ConstantStringType || $offsetType instanceof ConstantIntegerType) {
return TypeCombinator::intersect($array, new HasOffsetValueType($offsetType, $valueType), new NonEmptyArrayType());
}

Expand Down

0 comments on commit cbf413f

Please sign in to comment.