Updated Rector to commit 7a86df00a85e32e843cdbc609226ff8259896d90

7a86df00a8 [PHPStanStaticTypeMapper] Make use of toPhpDocNode() on ObjectTypeMapper (#4581)
This commit is contained in:
Tomas Votruba 2023-07-25 09:11:44 +00:00
parent ff02e1a32c
commit 6b34dc7b02
5 changed files with 31 additions and 74 deletions

View File

@ -7,31 +7,22 @@ use RectorPrefix202307\Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeTraverser;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedGenericObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use RectorPrefix202307\Symfony\Contracts\Service\Attribute\Required;
/**
* @implements TypeMapperInterface<ObjectType>
*/
final class ObjectTypeMapper implements TypeMapperInterface
{
/**
* @var \Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper
*/
private $phpStanStaticTypeMapper;
/**
* @return class-string<Type>
*/
@ -44,23 +35,24 @@ final class ObjectTypeMapper implements TypeMapperInterface
*/
public function mapToPHPStanPhpDocTypeNode(Type $type) : TypeNode
{
if ($type instanceof ShortenedObjectType) {
return new IdentifierTypeNode($type->getClassName());
}
if ($type instanceof AliasedObjectType) {
return new IdentifierTypeNode($type->getClassName());
}
if ($type instanceof GenericObjectType) {
return $this->mapGenericObjectType($type);
}
if ($type instanceof NonExistingObjectType) {
// possibly generic type
return new IdentifierTypeNode($type->getClassName());
}
if ($type instanceof FullyQualifiedObjectType && \strncmp($type->getClassName(), '\\', \strlen('\\')) === 0) {
return new IdentifierTypeNode($type->getClassName());
}
return new IdentifierTypeNode('\\' . $type->getClassName());
$type = TypeTraverser::map($type, static function (Type $type, callable $traverse) : Type {
if (!$type instanceof ObjectType) {
return $traverse($type);
}
$typeClass = \get_class($type);
// early native ObjectType check
if ($typeClass === 'PHPStan\\Type\\ObjectType') {
return new ObjectType('\\' . $type->getClassName());
}
if ($type instanceof FullyQualifiedObjectType) {
return new ObjectType('\\' . $type->getClassName());
}
if ($type instanceof GenericObjectType) {
return $traverse(new GenericObjectType('\\' . $type->getClassName(), $type->getTypes()));
}
return $traverse($type);
});
return $type->toPhpDocNode();
}
/**
* @param ObjectType $type
@ -89,39 +81,4 @@ final class ObjectTypeMapper implements TypeMapperInterface
}
return new FullyQualified($type->getClassName());
}
/**
* @required
*/
public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper) : void
{
$this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper;
}
private function mapGenericObjectType(GenericObjectType $genericObjectType) : TypeNode
{
$name = $this->resolveGenericObjectTypeName($genericObjectType);
$identifierTypeNode = new IdentifierTypeNode($name);
$genericTypeNodes = [];
foreach ($genericObjectType->getTypes() as $key => $genericType) {
// mixed type on 1st item in iterator has no value
if ($name === 'Iterator' && $genericType instanceof MixedType && $key === 0) {
continue;
}
$typeNode = $this->phpStanStaticTypeMapper->mapToPHPStanPhpDocTypeNode($genericType);
$genericTypeNodes[] = $typeNode;
}
if ($genericTypeNodes === []) {
return $identifierTypeNode;
}
return new GenericTypeNode($identifierTypeNode, $genericTypeNodes);
}
private function resolveGenericObjectTypeName(GenericObjectType $genericObjectType) : string
{
if ($genericObjectType instanceof FullyQualifiedGenericObjectType) {
return '\\' . $genericObjectType->getClassName();
}
if (\strpos($genericObjectType->getClassName(), '\\') !== \false) {
return '\\' . $genericObjectType->getClassName();
}
return $genericObjectType->getClassName();
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '9d40c275760351a3fc2899466691a0cd3e5b00a3';
public const PACKAGE_VERSION = '7a86df00a85e32e843cdbc609226ff8259896d90';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-07-25 10:00:52';
public const RELEASE_DATE = '2023-07-25 16:06:46';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit51aa4f970396a8aa5f451b784c87605b::getLoader();
return ComposerAutoloaderInit7ee8cb7f34630b13670c02fbdeea7be6::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit51aa4f970396a8aa5f451b784c87605b
class ComposerAutoloaderInit7ee8cb7f34630b13670c02fbdeea7be6
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit51aa4f970396a8aa5f451b784c87605b
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit51aa4f970396a8aa5f451b784c87605b', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit7ee8cb7f34630b13670c02fbdeea7be6', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit51aa4f970396a8aa5f451b784c87605b', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit7ee8cb7f34630b13670c02fbdeea7be6', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit51aa4f970396a8aa5f451b784c87605b::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit7ee8cb7f34630b13670c02fbdeea7be6::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit51aa4f970396a8aa5f451b784c87605b::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit7ee8cb7f34630b13670c02fbdeea7be6::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit51aa4f970396a8aa5f451b784c87605b
class ComposerStaticInit7ee8cb7f34630b13670c02fbdeea7be6
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3022,9 +3022,9 @@ class ComposerStaticInit51aa4f970396a8aa5f451b784c87605b
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit51aa4f970396a8aa5f451b784c87605b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit51aa4f970396a8aa5f451b784c87605b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit51aa4f970396a8aa5f451b784c87605b::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit7ee8cb7f34630b13670c02fbdeea7be6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit7ee8cb7f34630b13670c02fbdeea7be6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit7ee8cb7f34630b13670c02fbdeea7be6::$classMap;
}, null, ClassLoader::class);
}