Skip to content

Commit 4e279f6

Browse files
authored
cover nested mixed[] and object type (#7283)
1 parent 1c425fe commit 4e279f6

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/complex_array.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockRetur
3131
class ComplexArray
3232
{
3333
/**
34-
* @return array<string, mixed>
34+
* @return array<string, object|mixed[]>
3535
*/
3636
public function run(): array
3737
{

rules/TypeDeclarationDocblocks/TypeResolver/ConstantArrayTypeGeneralizer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
88
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
9+
use PHPStan\Type\ArrayType;
910
use PHPStan\Type\BooleanType;
1011
use PHPStan\Type\Constant\ConstantArrayType;
1112
use PHPStan\Type\FloatType;
1213
use PHPStan\Type\IntegerType;
1314
use PHPStan\Type\IntersectionType;
1415
use PHPStan\Type\MixedType;
1516
use PHPStan\Type\NeverType;
17+
use PHPStan\Type\ObjectWithoutClassType;
1618
use PHPStan\Type\StringType;
1719
use PHPStan\Type\Type;
1820
use PHPStan\Type\UnionType;
@@ -98,6 +100,10 @@ private function constantToGenericType(Type $type): Type
98100
return new FloatType();
99101
}
100102

103+
if ($type->isObject()->yes()) {
104+
return new ObjectWithoutClassType();
105+
}
106+
101107
if ($type instanceof UnionType || $type instanceof IntersectionType) {
102108
$genericComplexTypes = [];
103109
foreach ($type->getTypes() as $splitType) {
@@ -112,6 +118,10 @@ private function constantToGenericType(Type $type): Type
112118
return $genericComplexTypes[0];
113119
}
114120

121+
if ($type instanceof ConstantArrayType) {
122+
return new ArrayType(new MixedType(), new MixedType());
123+
}
124+
115125
// unclear
116126
return new MixedType();
117127
}

0 commit comments

Comments
 (0)