Skip to content

Commit

Permalink
ConstantArrayTypeBuilder - fix for potential problems
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 17, 2022
1 parent 67d3a88 commit 86b9306
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Type/Constant/ConstantArrayTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ public static function createEmpty(): self

public static function createFromConstantArray(ConstantArrayType $startArrayType): self
{
return new self(
$builder = new self(
$startArrayType->getKeyTypes(),
$startArrayType->getValueTypes(),
$startArrayType->getNextAutoIndex(),
$startArrayType->getOptionalKeys(),
);

if (count($startArrayType->getKeyTypes()) > self::ARRAY_COUNT_LIMIT) {
$builder->degradeToGeneralArray();
}

return $builder;
}

public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $optional = false): void
Expand Down Expand Up @@ -85,6 +91,11 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
if (!is_float($newNextAutoIndex)) {
$this->nextAutoIndex = $newNextAutoIndex;
}

if (count($this->keyTypes) > self::ARRAY_COUNT_LIMIT) {
$this->degradeToGeneralArray = true;
}

return;
}

Expand Down

0 comments on commit 86b9306

Please sign in to comment.