Skip to content

Commit 86b9306

Browse files
committed
ConstantArrayTypeBuilder - fix for potential problems
1 parent 67d3a88 commit 86b9306

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ public static function createEmpty(): self
4444

4545
public static function createFromConstantArray(ConstantArrayType $startArrayType): self
4646
{
47-
return new self(
47+
$builder = new self(
4848
$startArrayType->getKeyTypes(),
4949
$startArrayType->getValueTypes(),
5050
$startArrayType->getNextAutoIndex(),
5151
$startArrayType->getOptionalKeys(),
5252
);
53+
54+
if (count($startArrayType->getKeyTypes()) > self::ARRAY_COUNT_LIMIT) {
55+
$builder->degradeToGeneralArray();
56+
}
57+
58+
return $builder;
5359
}
5460

5561
public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $optional = false): void
@@ -85,6 +91,11 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
8591
if (!is_float($newNextAutoIndex)) {
8692
$this->nextAutoIndex = $newNextAutoIndex;
8793
}
94+
95+
if (count($this->keyTypes) > self::ARRAY_COUNT_LIMIT) {
96+
$this->degradeToGeneralArray = true;
97+
}
98+
8899
return;
89100
}
90101

0 commit comments

Comments
 (0)