Skip to content

Commit

Permalink
Make use of toPhpDocNode() - take #4 (#4559)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 20, 2023
1 parent 1ed4cf9 commit ef6aa9e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\Type;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -21,7 +19,6 @@
final class ClassStringTypeMapper implements TypeMapperInterface
{
public function __construct(
private readonly GenericClassStringTypeMapper $genericClassStringTypeMapper,
private readonly PhpVersionProvider $phpVersionProvider
) {
}
Expand All @@ -39,11 +36,7 @@ public function getNodeClass(): string
*/
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
if ($type instanceof GenericClassStringType) {
return $this->genericClassStringTypeMapper->mapToPHPStanPhpDocTypeNode($type);
}

return new IdentifierTypeNode('class-string');
return $type->toPhpDocNode();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\StaticType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -42,7 +41,7 @@ public function getNodeClass(): string
*/
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
return new ThisTypeNode();
return $type->toPhpDocNode();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
Expand All @@ -30,7 +29,7 @@ public function getNodeClass(): string
*/
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
return new ThisTypeNode();
return $type->toPhpDocNode();
}

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/PostRector/Rector/NameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Rector\PostRector\Rector;

use PhpParser\Node\Param;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\InlineHTML;
Expand Down Expand Up @@ -64,7 +64,9 @@ public function enterNode(Node $node): ?Node
return $this->processNodeName($node, $file);
}

if (($node instanceof Stmt || $node instanceof Param) && SimpleParameterProvider::provideBoolParameter(Option::AUTO_IMPORT_DOC_BLOCK_NAMES)) {
if (($node instanceof Stmt || $node instanceof Param) && SimpleParameterProvider::provideBoolParameter(
Option::AUTO_IMPORT_DOC_BLOCK_NAMES
)) {
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$this->docBlockNameImporter->importNames($phpDocInfo->getPhpDocNode(), $node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ClassStringCaseSensitive
class ClassStringCaseSensitive
{
/**
* @var class-string<\ClassStringCaseSensitive>
* @var class-string<ClassStringCaseSensitive>
*/
public $value;
public function set()
Expand Down

0 comments on commit ef6aa9e

Please sign in to comment.