|
26 | 26 | use function count; |
27 | 27 | use function in_array; |
28 | 28 | use function is_int; |
29 | | -use function is_string; |
30 | 29 |
|
31 | 30 | #[AutowiredService] |
32 | 31 | final class ArrayMergeFunctionDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension |
@@ -100,26 +99,25 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, |
100 | 99 | } |
101 | 100 |
|
102 | 101 | if ($keyTypes === []) { |
103 | | - foreach ($offsetTypes as [&$generalize, $offsetType]) { |
104 | | - $generalize = true; |
| 102 | + foreach ($offsetTypes as $key => [$generalize, $offsetValueType]) { |
| 103 | + $offsetTypes[$key][0] = true; |
105 | 104 | } |
106 | | - unset($generalize); |
107 | 105 | } |
108 | 106 |
|
109 | | - if ($newArrayBuilder === null) { |
110 | | - foreach (TypeUtils::getAccessoryTypes($argType) as $accessoryType) { |
111 | | - if ( |
112 | | - !($accessoryType instanceof HasOffsetType) |
113 | | - && !($accessoryType instanceof HasOffsetValueType) |
114 | | - ) { |
115 | | - continue; |
116 | | - } |
117 | | - |
118 | | - $offsetType = $accessoryType->getOffsetType(); |
119 | | - $offsetValueType = $argType->getOffsetValueType($offsetType); |
120 | | - $offsetTypes[$offsetType->getValue()] = [false, $offsetValueType]; |
| 107 | + foreach (TypeUtils::getAccessoryTypes($argType) as $accessoryType) { |
| 108 | + if ( |
| 109 | + !($accessoryType instanceof HasOffsetType) |
| 110 | + && !($accessoryType instanceof HasOffsetValueType) |
| 111 | + ) { |
| 112 | + continue; |
121 | 113 | } |
122 | 114 |
|
| 115 | + $offsetType = $accessoryType->getOffsetType(); |
| 116 | + $offsetValueType = $argType->getOffsetValueType($offsetType); |
| 117 | + $offsetTypes[$offsetType->getValue()] = [false, $offsetValueType]; |
| 118 | + } |
| 119 | + |
| 120 | + if ($newArrayBuilder === null) { |
123 | 121 | continue; |
124 | 122 | } |
125 | 123 |
|
@@ -182,7 +180,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, |
182 | 180 | } |
183 | 181 | $keyType = new ConstantStringType($key); |
184 | 182 |
|
185 | | - if (!$generalize && is_string($key)) { |
| 183 | + if (!$generalize) { |
186 | 184 | // the last string-keyed offset will overwrite previous values |
187 | 185 | $hasOffsetType = new HasOffsetValueType( |
188 | 186 | $keyType, |
|
0 commit comments