Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockRetur
class ReturnEmpty
{
/**
* @return array<int, mixed>
* @return array{}
*/
public function run(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Rector\TypeDeclarationDocblocks\TypeResolver;

use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
Expand All @@ -30,7 +30,7 @@ public function __construct(
) {
}

public function generalize(ConstantArrayType $constantArrayType, bool $isFresh = true): GenericTypeNode
public function generalize(ConstantArrayType $constantArrayType, bool $isFresh = true): GenericTypeNode|ArrayShapeNode
{
if ($isFresh) {
$this->currentNesting = 0;
Expand All @@ -40,12 +40,12 @@ public function generalize(ConstantArrayType $constantArrayType, bool $isFresh =

$genericKeyType = $this->typeNormalizer->generalizeConstantTypes($constantArrayType->getKeyType());

if ($constantArrayType->getItemType() instanceof NeverType) {
$genericKeyType = new IntegerType();
}

$itemType = $constantArrayType->getItemType();

if ($itemType instanceof NeverType) {
return ArrayShapeNode::createSealed([]);
}

if ($itemType instanceof ConstantArrayType) {
if ($this->currentNesting >= self::MAX_NESTING) {
$genericItemType = new MixedType();
Expand All @@ -64,7 +64,7 @@ public function generalize(ConstantArrayType $constantArrayType, bool $isFresh =
return $this->createArrayGenericTypeNode($genericKeyType, $genericItemType);
}

private function createArrayGenericTypeNode(Type $keyType, Type|GenericTypeNode $itemType): GenericTypeNode
private function createArrayGenericTypeNode(Type $keyType, Type|GenericTypeNode|ArrayShapeNode $itemType): GenericTypeNode
{
$keyDocTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($keyType);

Expand Down
Loading