diff --git a/composer.json b/composer.json index c64367b11e3..8992166d9ca 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,6 @@ "Rector\\NetteTesterToPHPUnit\\": "packages/nette-tester-to-phpunit/src", "Rector\\NetteToSymfony\\": "packages/nette-to-symfony/src", "Rector\\Nette\\": "packages/nette/src", - "Rector\\NodeTypeMapper\\": "packages/node-type-mapper/src", "Rector\\NodeCollector\\": "packages/node-collector/src", "Rector\\NodeTypeResolver\\": "packages/node-type-resolver/src", "Rector\\NodeNameResolver\\": "packages/node-name-resolver/src", @@ -99,6 +98,7 @@ "Rector\\Sensio\\": "packages/sensio/src", "Rector\\Shopware\\": "packages/shopware/src", "Rector\\Silverstripe\\": "packages/silverstripe/src", + "Rector\\StaticTypeMapper\\": "packages/static-type-mapper/src", "Rector\\Sylius\\": "packages/sylius/src", "Rector\\SymfonyCodeQuality\\": "packages/symfony-code-quality/src", "Rector\\SymfonyPHPUnit\\": "packages/symfony-phpunit/src", diff --git a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfo.php b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfo.php index 2d2f472c44a..acf83181373 100644 --- a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfo.php +++ b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfo.php @@ -31,7 +31,7 @@ use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; use Rector\Core\Exception\NotImplementedException; use Rector\Core\Exception\ShouldNotHappenException; use Rector\NodeTypeResolver\PHPStan\TypeComparator; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; /** * @see \Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfo\PhpDocInfoTest diff --git a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php index 54e87ad2b22..2369bf51466 100644 --- a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php +++ b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php @@ -16,7 +16,7 @@ use Rector\BetterPhpDocParser\ValueObject\StartEndValueObject; use Rector\Core\Configuration\CurrentNodeProvider; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\TypeComparator; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; final class PhpDocInfoFactory { diff --git a/packages/coding-style/src/Node/NameImporter.php b/packages/coding-style/src/Node/NameImporter.php index 957ad1d2052..326c893f48d 100644 --- a/packages/coding-style/src/Node/NameImporter.php +++ b/packages/coding-style/src/Node/NameImporter.php @@ -15,8 +15,8 @@ use Rector\CodingStyle\Imports\ImportSkipper; use Rector\Core\Configuration\Option; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\NodeTypeResolver\StaticTypeMapper; use Rector\PHPStan\Type\FullyQualifiedObjectType; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\PackageBuilder\Parameter\ParameterProvider; final class NameImporter diff --git a/packages/dynamic-type-analysis/src/Rector/ClassMethod/AddArgumentTypeWithProbeDataRector.php b/packages/dynamic-type-analysis/src/Rector/ClassMethod/AddArgumentTypeWithProbeDataRector.php index 04193f6a984..20509d3d554 100644 --- a/packages/dynamic-type-analysis/src/Rector/ClassMethod/AddArgumentTypeWithProbeDataRector.php +++ b/packages/dynamic-type-analysis/src/Rector/ClassMethod/AddArgumentTypeWithProbeDataRector.php @@ -103,10 +103,6 @@ PHP // single value → can we add it? if (count($parameterData) === 1) { $typeNode = $this->staticTypeMapper->mapStringToPhpParserNode($parameterData[0]); - if ($typeNode === null) { - continue; - } - $param->type = $typeNode; } } diff --git a/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php b/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php index ec8ce678845..3838030c313 100644 --- a/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php +++ b/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php @@ -19,7 +19,7 @@ use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\NodeTypeResolver; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; use ReflectionProperty; /** diff --git a/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockClassRenamer.php b/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockClassRenamer.php index 626cf898d5a..38567e390b5 100644 --- a/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockClassRenamer.php +++ b/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockClassRenamer.php @@ -10,7 +10,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\Type\Type; use Rector\BetterPhpDocParser\Ast\PhpDocNodeTraverser; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; final class DocBlockClassRenamer { diff --git a/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockNameImporter.php b/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockNameImporter.php index 607417106b4..476997714f6 100644 --- a/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockNameImporter.php +++ b/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockNameImporter.php @@ -18,9 +18,9 @@ use Rector\Core\PhpParser\Printer\BetterStandardPrinter; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\ClassExistenceStaticHelper; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\NodeTypeResolver\StaticTypeMapper; use Rector\PHPStan\Type\FullyQualifiedObjectType; use Rector\PHPStan\Type\ShortenedObjectType; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\PackageBuilder\Parameter\ParameterProvider; final class DocBlockNameImporter diff --git a/packages/node-type-resolver/src/PhpDoc/PhpDocTypeRenamer.php b/packages/node-type-resolver/src/PhpDoc/PhpDocTypeRenamer.php index 6a8e1e44930..4997db049ca 100644 --- a/packages/node-type-resolver/src/PhpDoc/PhpDocTypeRenamer.php +++ b/packages/node-type-resolver/src/PhpDoc/PhpDocTypeRenamer.php @@ -11,7 +11,7 @@ use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\Ast\PhpDocNodeTraverser; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; final class PhpDocTypeRenamer { diff --git a/packages/node-type-resolver/tests/StaticTypeMapper/StaticTypeMapperTest.php b/packages/node-type-resolver/tests/StaticTypeMapper/StaticTypeMapperTest.php index 0ef69e81f8e..b80506dee89 100644 --- a/packages/node-type-resolver/tests/StaticTypeMapper/StaticTypeMapperTest.php +++ b/packages/node-type-resolver/tests/StaticTypeMapper/StaticTypeMapperTest.php @@ -15,7 +15,7 @@ use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; use Rector\Core\HttpKernel\RectorKernel; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\PackageBuilder\Tests\AbstractKernelTestCase; final class StaticTypeMapperTest extends AbstractKernelTestCase diff --git a/packages/removing-static/src/UniqueObjectFactoryFactory.php b/packages/removing-static/src/UniqueObjectFactoryFactory.php index 7483a553816..8066071aaaf 100644 --- a/packages/removing-static/src/UniqueObjectFactoryFactory.php +++ b/packages/removing-static/src/UniqueObjectFactoryFactory.php @@ -24,7 +24,7 @@ use Rector\Core\Naming\PropertyNaming; use Rector\Core\PhpParser\Node\NodeFactory; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; final class UniqueObjectFactoryFactory { diff --git a/packages/node-type-mapper/config/config.yaml b/packages/static-type-mapper/config/config.yaml similarity index 76% rename from packages/node-type-mapper/config/config.yaml rename to packages/static-type-mapper/config/config.yaml index a56628772cf..2d11ae30af4 100644 --- a/packages/node-type-mapper/config/config.yaml +++ b/packages/static-type-mapper/config/config.yaml @@ -3,5 +3,5 @@ services: public: true autowire: true - Rector\NodeTypeMapper\: + Rector\StaticTypeMapper\: resource: '../src' diff --git a/packages/static-type-mapper/src/Mapper/StringTypeToPhpParserNodeMapper.php b/packages/static-type-mapper/src/Mapper/StringTypeToPhpParserNodeMapper.php new file mode 100644 index 00000000000..2416a23f79d --- /dev/null +++ b/packages/static-type-mapper/src/Mapper/StringTypeToPhpParserNodeMapper.php @@ -0,0 +1,57 @@ +map($nullableType); + + return new NullableType($nameNode); + } + + if ($type === 'void') { + return new Identifier('void'); + } + + throw new NotImplementedException(sprintf('%s for "%s"', __METHOD__, $type)); + } +} diff --git a/packages/static-type-mapper/src/PHPStan/NameScopeFactory.php b/packages/static-type-mapper/src/PHPStan/NameScopeFactory.php new file mode 100644 index 00000000000..2a8bed5c262 --- /dev/null +++ b/packages/static-type-mapper/src/PHPStan/NameScopeFactory.php @@ -0,0 +1,56 @@ +getAttribute(AttributeKey::NAMESPACE_NAME); + + /** @var Use_[] $useNodes */ + $useNodes = (array) $node->getAttribute(AttributeKey::USE_NODES); + + $uses = $this->resolveUseNamesByAlias($useNodes); + $className = $node->getAttribute(AttributeKey::CLASS_NAME); + + return new NameScope($namespace, $uses, $className); + } + + /** + * @param Use_[] $useNodes + * @return string[] + */ + private function resolveUseNamesByAlias(array $useNodes): array + { + $useNamesByAlias = []; + + foreach ($useNodes as $useNode) { + foreach ($useNode->uses as $useUse) { + /** @var UseUse $useUse */ + $aliasName = $useUse->getAlias()->name; + + $useName = $useUse->name->toString(); + if (! is_string($useName)) { + throw new ShouldNotHappenException(); + } + + $useNamesByAlias[$aliasName] = $useName; + } + } + + return $useNamesByAlias; + } +} diff --git a/packages/node-type-resolver/src/StaticTypeMapper.php b/packages/static-type-mapper/src/StaticTypeMapper.php similarity index 53% rename from packages/node-type-resolver/src/StaticTypeMapper.php rename to packages/static-type-mapper/src/StaticTypeMapper.php index 73531a9e136..7b5d2d33bbd 100644 --- a/packages/node-type-resolver/src/StaticTypeMapper.php +++ b/packages/static-type-mapper/src/StaticTypeMapper.php @@ -2,18 +2,13 @@ declare(strict_types=1); -namespace Rector\NodeTypeResolver; +namespace Rector\StaticTypeMapper; -use Nette\Utils\Strings; use PhpParser\Node; use PhpParser\Node\Identifier; use PhpParser\Node\Name; -use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\NullableType; -use PhpParser\Node\Stmt\Use_; -use PhpParser\Node\Stmt\UseUse; use PhpParser\Node\UnionType as PhpParserUnionType; -use PHPStan\Analyser\NameScope; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; @@ -21,12 +16,11 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\Type; use Rector\Core\Exception\NotImplementedException; -use Rector\Core\Exception\ShouldNotHappenException; -use Rector\NodeNameResolver\NodeNameResolver; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PhpDoc\PhpDocTypeMapper; use Rector\NodeTypeResolver\TypeMapper\PhpParserNodeMapper; use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper; +use Rector\StaticTypeMapper\Mapper\StringTypeToPhpParserNodeMapper; +use Rector\StaticTypeMapper\PHPStan\NameScopeFactory; /** * Maps PhpParser <=> PHPStan <=> PHPStan doc <=> string type nodes between all possible formats @@ -38,11 +32,6 @@ final class StaticTypeMapper */ private $phpStanStaticTypeMapper; - /** - * @var NodeNameResolver - */ - private $nodeNameResolver; - /** * @var PhpParserNodeMapper */ @@ -53,16 +42,28 @@ final class StaticTypeMapper */ private $phpDocTypeMapper; + /** + * @var StringTypeToPhpParserNodeMapper + */ + private $stringTypeToPhpParserNodeMapper; + + /** + * @var NameScopeFactory + */ + private $nameScopeFactory; + public function __construct( PHPStanStaticTypeMapper $phpStanStaticTypeMapper, - NodeNameResolver $nodeNameResolver, PhpParserNodeMapper $phpParserNodeMapper, - PhpDocTypeMapper $phpDocTypeMapper + PhpDocTypeMapper $phpDocTypeMapper, + StringTypeToPhpParserNodeMapper $stringTypeToPhpParserNodeMapper, + NameScopeFactory $nameScopeFactory ) { $this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper; - $this->nodeNameResolver = $nodeNameResolver; $this->phpParserNodeMapper = $phpParserNodeMapper; $this->phpDocTypeMapper = $phpDocTypeMapper; + $this->stringTypeToPhpParserNodeMapper = $stringTypeToPhpParserNodeMapper; + $this->nameScopeFactory = $nameScopeFactory; } public function mapPHPStanTypeToPHPStanPhpDocTypeNode(Type $phpStanType): TypeNode @@ -101,44 +102,11 @@ final class StaticTypeMapper } /** - * @return Identifier|Name|NullableType|null + * @return Identifier|Name|NullableType */ - public function mapStringToPhpParserNode(string $type): ?Node + public function mapStringToPhpParserNode(string $type): Node { - if ($type === 'string') { - return new Identifier('string'); - } - - if ($type === 'int') { - return new Identifier('int'); - } - - if ($type === 'array') { - return new Identifier('array'); - } - - if ($type === 'float') { - return new Identifier('float'); - } - - if (Strings::contains($type, '\\') || ctype_upper($type[0])) { - return new FullyQualified($type); - } - - if (Strings::startsWith($type, '?')) { - $nullableType = ltrim($type, '?'); - - /** @var Identifier|Name $nameNode */ - $nameNode = $this->mapStringToPhpParserNode($nullableType); - - return new NullableType($nameNode); - } - - if ($type === 'void') { - return new Identifier('void'); - } - - throw new NotImplementedException(sprintf('%s for "%s"', __METHOD__, $type)); + return $this->stringTypeToPhpParserNodeMapper->map($type); } public function mapPHPStanPhpDocTypeNodeToPhpDocString(TypeNode $typeNode, Node $node): string @@ -150,48 +118,8 @@ final class StaticTypeMapper public function mapPHPStanPhpDocTypeNodeToPHPStanType(TypeNode $typeNode, Node $node): Type { - $nameScope = $this->createNameScopeFromNode($node); + $nameScope = $this->nameScopeFactory->createNameScopeFromNode($node); return $this->phpDocTypeMapper->mapToPHPStanType($typeNode, $node, $nameScope); } - - /** - * @see https://github.com/phpstan/phpstan-src/blob/8376548f76e2c845ae047e3010e873015b796818/src/Analyser/NameScope.php#L32 - */ - private function createNameScopeFromNode(Node $node): NameScope - { - $namespace = $node->getAttribute(AttributeKey::NAMESPACE_NAME); - - /** @var Use_[] $useNodes */ - $useNodes = (array) $node->getAttribute(AttributeKey::USE_NODES); - - $uses = $this->resolveUseNamesByAlias($useNodes); - $className = $node->getAttribute(AttributeKey::CLASS_NAME); - - return new NameScope($namespace, $uses, $className); - } - - /*** - * @param Use_[] $useNodes - * @return string[] - */ - private function resolveUseNamesByAlias(array $useNodes): array - { - $useNamesByAlias = []; - - foreach ($useNodes as $useNode) { - foreach ($useNode->uses as $useUse) { - /** @var UseUse $useUse */ - $aliasName = $useUse->getAlias()->name; - $useName = $this->nodeNameResolver->getName($useUse->name); - if (! is_string($useName)) { - throw new ShouldNotHappenException(); - } - - $useNamesByAlias[$aliasName] = $useName; - } - } - - return $useNamesByAlias; - } } diff --git a/packages/type-declaration/src/PhpDocParser/ParamPhpDocNodeFactory.php b/packages/type-declaration/src/PhpDocParser/ParamPhpDocNodeFactory.php index ad7534edb79..d39e4a6439e 100644 --- a/packages/type-declaration/src/PhpDocParser/ParamPhpDocNodeFactory.php +++ b/packages/type-declaration/src/PhpDocParser/ParamPhpDocNodeFactory.php @@ -8,7 +8,7 @@ use PhpParser\Node\Param; use PHPStan\Type\Type; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareParamTagValueNode; use Rector\NodeNameResolver\NodeNameResolver; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; final class ParamPhpDocNodeFactory { diff --git a/packages/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php b/packages/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php index 80111efeacd..507e76c7006 100644 --- a/packages/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php +++ b/packages/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php @@ -166,10 +166,6 @@ PHP } $returnTypeNode = $this->staticTypeMapper->mapStringToPhpParserNode($newType); - if ($returnTypeNode === null) { - return; - } - $param->type = $returnTypeNode; } } diff --git a/packages/type-declaration/src/TypeDeclarationToStringConverter.php b/packages/type-declaration/src/TypeDeclarationToStringConverter.php index e0f3e181548..47877b697be 100644 --- a/packages/type-declaration/src/TypeDeclarationToStringConverter.php +++ b/packages/type-declaration/src/TypeDeclarationToStringConverter.php @@ -7,7 +7,7 @@ namespace Rector\TypeDeclaration; use PhpParser\Node\FunctionLike; use PHPStan\Type\MixedType; use PHPStan\Type\Type; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; final class TypeDeclarationToStringConverter { diff --git a/packages/type-declaration/src/TypeInferer/AbstractTypeInferer.php b/packages/type-declaration/src/TypeInferer/AbstractTypeInferer.php index 115b62c837a..ae09333f72d 100644 --- a/packages/type-declaration/src/TypeInferer/AbstractTypeInferer.php +++ b/packages/type-declaration/src/TypeInferer/AbstractTypeInferer.php @@ -8,7 +8,7 @@ use Rector\Core\PhpParser\NodeTraverser\CallableNodeTraverser; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; abstract class AbstractTypeInferer { diff --git a/packages/type-declaration/tests/TypeNormalizerTest.php b/packages/type-declaration/tests/TypeNormalizerTest.php index a358d10e184..8fb0986506a 100644 --- a/packages/type-declaration/tests/TypeNormalizerTest.php +++ b/packages/type-declaration/tests/TypeNormalizerTest.php @@ -11,7 +11,7 @@ use PHPStan\Type\MixedType; use PHPStan\Type\StringType; use PHPStan\Type\UnionType; use Rector\Core\HttpKernel\RectorKernel; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\TypeNormalizer; use Symplify\PackageBuilder\Tests\AbstractKernelTestCase; diff --git a/phpstan.neon b/phpstan.neon index 40a5fef2091..6ae57f6b966 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -221,7 +221,7 @@ parameters: - '#Property PhpParser\\Node\\Stmt\\Expression\:\:\$expr \(PhpParser\\Node\\Expr\) does not accept PhpParser\\Node\\Expr\|null#' - '#Call to an undefined method PHPStan\\Type\\Type\:\:getClassName\(\)#' - - '#Parameter \#1 \$typeNode of method Rector\\NodeTypeResolver\\StaticTypeMapper\:\:mapPHPStanPhpDocTypeNodeToPHPStanType\(\) expects PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode, PHPStan\\PhpDocParser\\Ast\\Node given#' + - '#Parameter \#1 \$typeNode of method Rector\\StaticTypeMapper\\StaticTypeMapper\:\:mapPHPStanPhpDocTypeNodeToPHPStanType\(\) expects PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode, PHPStan\\PhpDocParser\\Ast\\Node given#' - '#Parameter \#1 \$str of function preg_quote expects string, int\|string given#' - '#Parameter \#1 \$node of method Rector\\Core\\PhpParser\\Node\\Commander\\NodeAddingCommander\:\:wrapToExpression\(\) expects PhpParser\\Node\\Expr\|PhpParser\\Node\\Stmt, PhpParser\\Node given#' diff --git a/src/Console/Command/ScreenFileCommand.php b/src/Console/Command/ScreenFileCommand.php index c3cd4b07bab..3d7a03e58ea 100644 --- a/src/Console/Command/ScreenFileCommand.php +++ b/src/Console/Command/ScreenFileCommand.php @@ -25,7 +25,7 @@ use Rector\FileSystemRector\Parser\FileInfoParser; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\NodeTypeResolver; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/PhpParser/Node/NodeFactory.php b/src/PhpParser/Node/NodeFactory.php index 98c8e765095..13c80586e86 100644 --- a/src/PhpParser/Node/NodeFactory.php +++ b/src/PhpParser/Node/NodeFactory.php @@ -33,7 +33,7 @@ use PHPStan\Type\Type; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Core\Exception\NotImplementedException; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; /** * @see \Rector\Core\Tests\PhpParser\Node\NodeFactoryTest diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index da8bdbcedb4..00200c25fd6 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -24,7 +24,7 @@ use Rector\NodeCollector\NodeFinder\FunctionLikeParsedNodesFinder; use Rector\NodeTypeResolver\FileSystem\CurrentFileInfoProvider; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator; -use Rector\NodeTypeResolver\StaticTypeMapper; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\Rector\AbstractRector\AbstractRectorTrait; use Rector\Core\Rector\AbstractRector\NodeCommandersTrait; diff --git a/src/Rector/ClassMethod/AddReturnTypeDeclarationRector.php b/src/Rector/ClassMethod/AddReturnTypeDeclarationRector.php index 8bb9b505276..77e3b46fa05 100644 --- a/src/Rector/ClassMethod/AddReturnTypeDeclarationRector.php +++ b/src/Rector/ClassMethod/AddReturnTypeDeclarationRector.php @@ -111,10 +111,6 @@ PHP } $returnTypeNode = $this->staticTypeMapper->mapStringToPhpParserNode($newType); - if ($returnTypeNode === null) { - return; - } - $classMethod->returnType = $returnTypeNode; } }