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
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockGetterReturnArrayFromPropertyDocblockVarRector\Fixture;

final class SkipMixedArray
{
private array $names = [];

public function getNames(): array
{
return $this->names;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockGetterReturnArrayFromPropertyDocblockVarRector\Fixture;

final class SkipNullableMixedArray
{
private ?array $names = [];

public function getNames(): array
{
return $this->names;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\UnionType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -99,6 +102,17 @@ public function refactor(Node $node): ?Node
}

$propertyFetchType = $this->getType($propertyFetch);
if ($propertyFetchType instanceof ArrayType
&& $propertyFetchType->getKeyType() instanceof MixedType
&& $propertyFetchType->getItemType() instanceof MixedType
) {
return null;
}

if ($propertyFetchType instanceof UnionType) {
return null;
}

$propertyFetchDocTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($propertyFetchType);

$returnTagValueNode = new ReturnTagValueNode($propertyFetchDocTypeNode, '');
Expand Down
Loading