diff --git a/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/class_string_case_sensitive.php.inc b/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/class_string_case_sensitive.php.inc index de896c8132b..29ba6a5af3b 100644 --- a/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/class_string_case_sensitive.php.inc +++ b/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/class_string_case_sensitive.php.inc @@ -17,7 +17,7 @@ class ClassStringCaseSensitive class ClassStringCaseSensitive { /** - * @var class-string + * @var class-string<\ClassStringCaseSensitive> */ public $value; public function set() diff --git a/rules-tests/DeadCode/Rector/FunctionLike/NarrowTooWideReturnTypeRector/Fixture/phpdocs.php.inc b/rules-tests/DeadCode/Rector/FunctionLike/NarrowTooWideReturnTypeRector/Fixture/phpdocs.php.inc index 40d92c06dd3..9099aeb6698 100644 --- a/rules-tests/DeadCode/Rector/FunctionLike/NarrowTooWideReturnTypeRector/Fixture/phpdocs.php.inc +++ b/rules-tests/DeadCode/Rector/FunctionLike/NarrowTooWideReturnTypeRector/Fixture/phpdocs.php.inc @@ -83,14 +83,14 @@ final class PhpDocs /** * @param class-string $class - * @return class-string + * @return class-string<\Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Source\SomeInterface> */ public function bar(string $class): string { return $class; } - /** @return class-string */ + /** @return class-string<\Rector\Tests\DeadCode\Rector\FunctionLike\NarrowTooWideReturnTypeRector\Source\SomeInterface> */ public function baz(string $class): string { return SomeInterface::class; diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector/Fixture/add_prefix_backslash.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector/Fixture/add_prefix_backslash.php.inc new file mode 100644 index 00000000000..76a5ed639c9 --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector/Fixture/add_prefix_backslash.php.inc @@ -0,0 +1,54 @@ +>> */ + protected array $duplicateNames, + ) { + parent::__construct( + 'Some solutions have duplicate names.', + ); + } + + public function getDuplicateNames(): array + { + return $this->duplicateNames; + } +} + +?> +----- +>> */ + protected array $duplicateNames, + ) { + parent::__construct( + 'Some solutions have duplicate names.', + ); + } + + /** + * @return array[]> + */ + public function getDuplicateNames(): array + { + return $this->duplicateNames; + } +} + +?> diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php index 623ac047ea2..2249fbe94e0 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php @@ -8,7 +8,9 @@ use PhpParser\Node\Identifier; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\ClassStringType; +use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use PHPStan\Type\TypeTraverser; use Rector\Php\PhpVersionProvider; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\ValueObject\PhpVersionFeature; @@ -33,6 +35,20 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { + $type = TypeTraverser::map($type, static function (Type $type, callable $traverse): Type { + if (! $type instanceof ObjectType) { + return $traverse($type); + } + + $typeClass = $type::class; + + if ($typeClass === 'PHPStan\Type\ObjectType') { + return new ObjectType('\\' . $type->getClassName()); + } + + return $traverse($type); + }); + return $type->toPhpDocNode(); }