Skip to content

Commit

Permalink
Revert "Solve phpstan deprecation"
Browse files Browse the repository at this point in the history
This reverts commit c110e57.
  • Loading branch information
ondrejmirtes committed May 4, 2023
1 parent 24fc706 commit dff01ff
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
Expand Down Expand Up @@ -208,22 +209,19 @@ static function (Type $type, callable $traverse) use ($objectManager): Type {

private function getScalarHydratedReturnType(Type $queryResultType): Type
{
if (!$queryResultType->isArray()->yes()) {
if (!$queryResultType instanceof ArrayType) {
return new ArrayType(new MixedType(), new MixedType());
}

foreach ($queryResultType->getArrays() as $arrayType) {
$itemType = $arrayType->getItemType();
$itemType = $queryResultType->getItemType();
$hasNoObject = (new ObjectWithoutClassType())->isSuperTypeOf($itemType)->no();
$hasNoArray = $itemType->isArray()->no();

if (
!(new ObjectWithoutClassType())->isSuperTypeOf($itemType)->no()
|| !$itemType->isArray()->no()
) {
return new ArrayType(new MixedType(), new MixedType());
}
if ($hasNoArray && $hasNoObject) {
return $queryResultType;
}

return $queryResultType;
return new ArrayType(new MixedType(), new MixedType());
}

private function getSimpleObjectHydratedReturnType(Type $queryResultType): Type
Expand All @@ -238,41 +236,31 @@ private function getSimpleObjectHydratedReturnType(Type $queryResultType): Type
private function getSingleScalarHydratedReturnType(Type $queryResultType): Type
{
$queryResultType = $this->getScalarHydratedReturnType($queryResultType);
if (!$queryResultType->isConstantArray()->yes()) {
if (!$queryResultType instanceof ConstantArrayType) {
return new MixedType();
}

$types = [];
foreach ($queryResultType->getConstantArrays() as $constantArrayType) {
$values = $constantArrayType->getValueTypes();
if (count($values) !== 1) {
return new MixedType();
}

$types[] = $constantArrayType->getFirstIterableValueType();
$values = $queryResultType->getValueTypes();
if (count($values) !== 1) {
return new MixedType();
}

return TypeCombinator::union(...$types);
return $queryResultType->getFirstIterableValueType();
}

private function getScalarColumnHydratedReturnType(Type $queryResultType): Type
{
$queryResultType = $this->getScalarHydratedReturnType($queryResultType);
if (!$queryResultType->isConstantArray()->yes()) {
if (!$queryResultType instanceof ConstantArrayType) {
return new MixedType();
}

$types = [];
foreach ($queryResultType->getConstantArrays() as $constantArrayType) {
$values = $constantArrayType->getValueTypes();
if (count($values) !== 1) {
return new MixedType();
}

$types[] = $constantArrayType->getFirstIterableValueType();
$values = $queryResultType->getValueTypes();
if (count($values) !== 1) {
return new MixedType();
}

return TypeCombinator::union(...$types);
return $queryResultType->getFirstIterableValueType();
}

private function originalReturnType(MethodReflection $methodReflection): Type
Expand Down

0 comments on commit dff01ff

Please sign in to comment.