|
10 | 10 | use PHPStan\Type\IntegerRangeType; |
11 | 11 | use PHPStan\Type\IntegerType; |
12 | 12 | use PHPStan\Type\IterableType; |
13 | | -use PHPStan\Type\MixedType; |
14 | 13 | use PHPStan\Type\ObjectWithoutClassType; |
15 | 14 | use PHPStan\Type\Type; |
16 | 15 | use PHPStan\Type\TypeCombinator; |
17 | | -use PHPStan\Type\TypeTraverser; |
18 | 16 | use PHPStan\Type\TypeUtils; |
19 | | -use PHPStan\Type\TypeWithClassName; |
20 | 17 | use PHPStan\Type\VoidType; |
21 | 18 |
|
22 | 19 | class HydrationModeReturnTypeResolver |
@@ -47,9 +44,6 @@ public function getMethodReturnTypeForHydrationMode( |
47 | 44 | switch ($hydrationMode) { |
48 | 45 | case AbstractQuery::HYDRATE_OBJECT: |
49 | 46 | break; |
50 | | - case AbstractQuery::HYDRATE_ARRAY: |
51 | | - $queryResultType = $this->getArrayHydratedReturnType($queryResultType, $objectManager); |
52 | | - break; |
53 | 47 | case AbstractQuery::HYDRATE_SIMPLEOBJECT: |
54 | 48 | $queryResultType = $this->getSimpleObjectHydratedReturnType($queryResultType); |
55 | 49 | break; |
@@ -90,48 +84,6 @@ public function getMethodReturnTypeForHydrationMode( |
90 | 84 | } |
91 | 85 | } |
92 | 86 |
|
93 | | - /** |
94 | | - * When we're array-hydrating object, we're not sure of the shape of the array. |
95 | | - * We could return `new ArrayType(new MixedType(), new MixedType())` |
96 | | - * but the lack of precision in the array keys/values would give false positive. |
97 | | - * |
98 | | - * @see https://github.com/phpstan/phpstan-doctrine/pull/412#issuecomment-1497092934 |
99 | | - */ |
100 | | - private function getArrayHydratedReturnType(Type $queryResultType, ?ObjectManager $objectManager): ?Type |
101 | | - { |
102 | | - $mixedFound = false; |
103 | | - $queryResultType = TypeTraverser::map( |
104 | | - $queryResultType, |
105 | | - static function (Type $type, callable $traverse) use ($objectManager, &$mixedFound): Type { |
106 | | - $isObject = (new ObjectWithoutClassType())->isSuperTypeOf($type); |
107 | | - if ($isObject->no()) { |
108 | | - return $traverse($type); |
109 | | - } |
110 | | - if ( |
111 | | - $isObject->maybe() |
112 | | - || !$type instanceof TypeWithClassName |
113 | | - || $objectManager === null |
114 | | - ) { |
115 | | - $mixedFound = true; |
116 | | - |
117 | | - return new MixedType(); |
118 | | - } |
119 | | - |
120 | | - /** @var class-string $className */ |
121 | | - $className = $type->getClassName(); |
122 | | - if (!$objectManager->getMetadataFactory()->hasMetadataFor($className)) { |
123 | | - return $traverse($type); |
124 | | - } |
125 | | - |
126 | | - $mixedFound = true; |
127 | | - |
128 | | - return new MixedType(); |
129 | | - } |
130 | | - ); |
131 | | - |
132 | | - return $mixedFound ? null : $queryResultType; |
133 | | - } |
134 | | - |
135 | 87 | private function getSimpleObjectHydratedReturnType(Type $queryResultType): ?Type |
136 | 88 | { |
137 | 89 | if ((new ObjectWithoutClassType())->isSuperTypeOf($queryResultType)->yes()) { |
|
0 commit comments