Skip to content

Commit e8fe43a

Browse files
Rework
1 parent 4a7fe14 commit e8fe43a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class ConstantArrayTypeBuilder
4242

4343
private bool $oversized = false;
4444

45-
private bool $forceUpdatesAutoIncrementKeyForNegativeValues = false;
45+
private bool $initializedEmpty = false;
4646

4747
/**
4848
* @param list<Type> $keyTypes
@@ -75,10 +75,7 @@ public static function createFromConstantArray(ConstantArrayType $startArrayType
7575
$startArrayType->isList(),
7676
);
7777

78-
$phpVersion = PhpVersionStaticAccessor::getInstance();
79-
if ($phpVersion->updatesAutoIncrementKeyForNegativeValuesOnlyInNonEmptyInitializer()) {
80-
$builder->forceUpdatesAutoIncrementKeyForNegativeValues = !self::wasInitializedEmpty($startArrayType);
81-
}
78+
$builder->initializedEmpty = self::wasInitializedEmpty($startArrayType);
8279

8380
if (count($startArrayType->getKeyTypes()) > self::ARRAY_COUNT_LIMIT) {
8481
$builder->degradeToGeneralArray(true);
@@ -442,7 +439,11 @@ private function shouldUpdateAutoIndex(int $offsetValue, int $max): bool
442439
return true;
443440
}
444441

445-
return !$this->forceUpdatesAutoIncrementKeyForNegativeValues;
442+
if ($phpVersion->updatesAutoIncrementKeyForNegativeValuesOnlyInNonEmptyInitializer()) {
443+
return !$this->initializedEmpty;
444+
}
445+
446+
return false;
446447
}
447448

448449
private static function wasInitializedEmpty(ConstantArrayType $startArrayType): bool

0 commit comments

Comments
 (0)