Skip to content

Commit 2caa832

Browse files
staabmondrejmirtes
authored andcommitted
InitializerExprTypeResolver: move work out of loop
1 parent 196f44d commit 2caa832

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,19 @@ public function getArrayType(Expr\Array_ $expr, callable $getTypeCallback): Type
643643
$constantArrays = $valueType->getConstantArrays();
644644
if (count($constantArrays) === 1) {
645645
$constantArrayType = $constantArrays[0];
646+
646647
$hasStringKey = false;
647-
foreach ($constantArrayType->getKeyTypes() as $keyType) {
648-
if ($keyType->isString()->yes()) {
649-
$hasStringKey = true;
650-
break;
648+
if ($this->phpVersion->supportsArrayUnpackingWithStringKeys()) {
649+
foreach ($constantArrayType->getKeyTypes() as $keyType) {
650+
if ($keyType->isString()->yes()) {
651+
$hasStringKey = true;
652+
break;
653+
}
651654
}
652655
}
653656

654657
foreach ($constantArrayType->getValueTypes() as $i => $innerValueType) {
655-
if ($hasStringKey && $this->phpVersion->supportsArrayUnpackingWithStringKeys()) {
658+
if ($hasStringKey) {
656659
$arrayBuilder->setOffsetValueType($constantArrayType->getKeyTypes()[$i], $innerValueType, $constantArrayType->isOptionalKey($i));
657660
} else {
658661
$arrayBuilder->setOffsetValueType(null, $innerValueType, $constantArrayType->isOptionalKey($i));

0 commit comments

Comments
 (0)