Skip to content

Commit 87c3cb2

Browse files
committed
refactor
1 parent 8896025 commit 87c3cb2

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/Type/Php/ArrayMergeFunctionDynamicReturnTypeExtension.php

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,42 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
7878
static fn (Type $argType) => $argType->isConstantArray(),
7979
);
8080

81-
$offsetTypes = [];
82-
$newArrayBuilder = null;
8381
if ($allConstant->yes()) {
8482
$newArrayBuilder = ConstantArrayTypeBuilder::createEmpty();
85-
}
86-
foreach ($argTypes as $argType) {
87-
/** @var array<int|string, ConstantIntegerType|ConstantStringType> $keyTypes */
88-
$keyTypes = [];
89-
foreach ($argType->getConstantArrays() as $constantArray) {
90-
foreach ($constantArray->getKeyTypes() as $keyType) {
91-
$keyTypes[$keyType->getValue()] = $keyType;
92-
93-
$hasOffsetValue = TrinaryLogic::createFromBoolean($argType->hasOffsetValueType($keyType)->yes());
94-
$offsetTypes[$keyType->getValue()] = [
95-
$hasOffsetValue,
83+
foreach ($argTypes as $argType) {
84+
/** @var array<int|string, ConstantIntegerType|ConstantStringType> $keyTypes */
85+
$keyTypes = [];
86+
foreach ($argType->getConstantArrays() as $constantArray) {
87+
foreach ($constantArray->getKeyTypes() as $keyType) {
88+
$keyTypes[$keyType->getValue()] = $keyType;
89+
}
90+
}
91+
92+
foreach ($keyTypes as $keyType) {
93+
$newArrayBuilder->setOffsetValueType(
94+
$keyType instanceof ConstantIntegerType ? null : $keyType,
9695
$argType->getOffsetValueType($keyType),
97-
];
96+
!$argType->hasOffsetValueType($keyType)->yes(),
97+
);
9898
}
9999
}
100100

101-
if ($keyTypes === []) {
101+
return $newArrayBuilder->getArray();
102+
}
103+
104+
$offsetTypes = [];
105+
foreach ($argTypes as $argType) {
106+
if ($argType->isConstantArray()->yes()) {
107+
foreach ($argType->getConstantArrays() as $constantArray) {
108+
foreach ($constantArray->getKeyTypes() as $keyType) {
109+
$hasOffsetValue = TrinaryLogic::createFromBoolean($argType->hasOffsetValueType($keyType)->yes());
110+
$offsetTypes[$keyType->getValue()] = [
111+
$hasOffsetValue,
112+
$argType->getOffsetValueType($keyType),
113+
];
114+
}
115+
}
116+
} else {
102117
foreach ($offsetTypes as $key => [$hasOffsetValue, $offsetValueType]) {
103118
$offsetTypes[$key] = [
104119
$hasOffsetValue->and(TrinaryLogic::createMaybe()),
@@ -121,22 +136,6 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
121136
$argType->getOffsetValueType($offsetType),
122137
];
123138
}
124-
125-
if ($newArrayBuilder === null) {
126-
continue;
127-
}
128-
129-
foreach ($keyTypes as $keyType) {
130-
$newArrayBuilder->setOffsetValueType(
131-
$keyType instanceof ConstantIntegerType ? null : $keyType,
132-
$argType->getOffsetValueType($keyType),
133-
!$argType->hasOffsetValueType($keyType)->yes(),
134-
);
135-
}
136-
}
137-
138-
if ($newArrayBuilder !== null) {
139-
return $newArrayBuilder->getArray();
140139
}
141140

142141
$keyTypes = [];

0 commit comments

Comments
 (0)