Skip to content

Commit 398b701

Browse files
Refactor
1 parent efd51a8 commit 398b701

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

src/Type/TypeUtils.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPStan\Internal\CombinationsHelper;
66
use PHPStan\Type\Accessory\AccessoryType;
77
use PHPStan\Type\Accessory\HasPropertyType;
8-
use PHPStan\Type\Constant\ConstantArrayType;
98
use PHPStan\Type\Constant\ConstantIntegerType;
109
use PHPStan\Type\Generic\TemplateBenevolentUnionType;
1110
use PHPStan\Type\Generic\TemplateType;
@@ -134,14 +133,23 @@ public static function toStrictUnion(Type $type): Type
134133
*/
135134
public static function flattenTypes(Type $type): array
136135
{
137-
if ($type instanceof ConstantArrayType) {
138-
return $type->getAllArrays();
136+
if ($type instanceof UnionType) {
137+
$types = [];
138+
foreach ($type->getTypes() as $innerType) {
139+
$flattenTypes = self::flattenTypes($innerType);
140+
foreach ($flattenTypes as $flattenType) {
141+
$types[] = $flattenType;
142+
}
143+
}
144+
145+
return $types;
139146
}
140147

141-
if ($type instanceof IntersectionType && $type->isConstantArray()->yes()) {
148+
$constantArrays = $type->getConstantArrays();
149+
if ($constantArrays !== []) {
142150
$newTypes = [];
143-
foreach ($type->getTypes() as $innerType) {
144-
$newTypes[] = self::flattenTypes($innerType);
151+
foreach ($constantArrays as $constantArray) {
152+
$newTypes[] = $constantArray->getAllArrays();
145153
}
146154

147155
return array_filter(
@@ -153,18 +161,6 @@ public static function flattenTypes(Type $type): array
153161
);
154162
}
155163

156-
if ($type instanceof UnionType) {
157-
$types = [];
158-
foreach ($type->getTypes() as $innerType) {
159-
$flattenTypes = self::flattenTypes($innerType);
160-
foreach ($flattenTypes as $flattenType) {
161-
$types[] = $flattenType;
162-
}
163-
}
164-
165-
return $types;
166-
}
167-
168164
return [$type];
169165
}
170166

0 commit comments

Comments
 (0)