Updated Rector to commit ceccbad0ea397dc66bde0f91a88d5ededbe3bbb6

ceccbad0ea Type improvements (#1065)
This commit is contained in:
Tomas Votruba 2021-10-26 08:04:21 +00:00
parent 04db37fabd
commit c676389932
11 changed files with 75 additions and 70 deletions

View File

@ -135,10 +135,17 @@ final class PhpDocTypeChanger
$param->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PHP_DOC_INFO, $phpDocInfo);
$functionLike = $param->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
$paramVarName = $this->nodeNameResolver->getName($param->var);
if ($functionLike instanceof \PhpParser\Node\Stmt\ClassMethod && $varTag->type instanceof \PHPStan\PhpDocParser\Ast\Type\GenericTypeNode && \is_string($paramVarName)) {
$phpDocInfo = $functionLike->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PHP_DOC_INFO);
$paramType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($varTag, $property);
$this->changeParamType($phpDocInfo, $paramType, $param, $paramVarName);
if (!$functionLike instanceof \PhpParser\Node\Stmt\ClassMethod) {
return;
}
if (!$varTag->type instanceof \PHPStan\PhpDocParser\Ast\Type\GenericTypeNode) {
return;
}
if (!\is_string($paramVarName)) {
return;
}
$phpDocInfo = $functionLike->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PHP_DOC_INFO);
$paramType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($varTag, $property);
$this->changeParamType($phpDocInfo, $paramType, $param, $paramVarName);
}
}

View File

@ -5,11 +5,9 @@ namespace Rector\NodeTypeResolver\DependencyInjection;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeFactory;
use PHPStan\Analyser\TypeSpecifier;
use PHPStan\Dependency\DependencyResolver;
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\ContainerFactory;
use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider;
use PHPStan\ExtensionInstaller\GeneratedConfig;
use PHPStan\File\FileHelper;
use PHPStan\PhpDoc\TypeNodeResolver;
@ -55,13 +53,6 @@ final class PHPStanServicesFactory
{
return $this->container->getByType(\PHPStan\Analyser\NodeScopeResolver::class);
}
/**
* @api
*/
public function createTypeSpecifier() : \PHPStan\Analyser\TypeSpecifier
{
return $this->container->getByType(\PHPStan\Analyser\TypeSpecifier::class);
}
/**
* @api
*/
@ -83,13 +74,6 @@ final class PHPStanServicesFactory
{
return $this->container->getByType(\PHPStan\File\FileHelper::class);
}
/**
* @api
*/
public function createOperatorTypeSpecifyingExtensionRegistryProvider() : \PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider
{
return $this->container->getByType(\PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider::class);
}
/**
* @api
*/

View File

@ -71,6 +71,6 @@ final class TypeHasher
}
return new \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType($type->getFullyQualifiedClass());
});
return $normalizedUnionType->describe(\PHPStan\Type\VerbosityLevel::cache());
return $normalizedUnionType->describe(\PHPStan\Type\VerbosityLevel::precise());
}
}

View File

@ -170,7 +170,7 @@ CODE_SAMPLE
if ($newType instanceof \PHPStan\Type\VoidType) {
return \true;
}
if ($this->advancedArrayAnalyzer->isMoreSpecificArrayTypeOverride($newType, $classMethod, $phpDocInfo)) {
if ($this->advancedArrayAnalyzer->isMoreSpecificArrayTypeOverride($newType, $phpDocInfo)) {
return \true;
}
if ($this->isGenericTypeToMixedTypeOverride($newType, $currentType)) {

View File

@ -11,6 +11,7 @@ use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\VoidType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
@ -55,9 +56,10 @@ final class AdvancedArrayAnalyzer
return \false;
}
$currentReturnType = $phpDocInfo->getReturnType();
return $currentReturnType instanceof \PHPStan\Type\ArrayType;
$arrayTypes = \PHPStan\Type\TypeUtils::getArrays($currentReturnType);
return $arrayTypes !== [];
}
public function isMoreSpecificArrayTypeOverride(\PHPStan\Type\Type $newType, \PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : bool
public function isMoreSpecificArrayTypeOverride(\PHPStan\Type\Type $newType, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : bool
{
if (!$newType instanceof \PHPStan\Type\Constant\ConstantArrayType) {
return \false;

View File

@ -13,6 +13,7 @@ use PhpParser\Node\UnionType as PhpParserUnionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\Core\Configuration\Option;
@ -104,34 +105,13 @@ final class ReturnTypeInferer
public function verifyStaticType(\PHPStan\Type\Type $type, bool $isSupportedStaticReturnType) : ?\PHPStan\Type\Type
{
if ($this->isStaticType($type)) {
if (!$isSupportedStaticReturnType) {
return null;
}
/** @var FullyQualifiedObjectType $type */
return new \PHPStan\Type\ThisType($type->getClassName());
/** @var TypeWithClassName $type */
return $this->resolveStaticType($isSupportedStaticReturnType, $type);
}
if (!$type instanceof \PHPStan\Type\UnionType) {
return $type;
if ($type instanceof \PHPStan\Type\UnionType) {
return $this->resolveUnionStaticTypes($type, $isSupportedStaticReturnType);
}
$returnTypes = $type->getTypes();
$types = [];
$hasStatic = \false;
foreach ($returnTypes as $returnType) {
if ($this->isStaticType($returnType)) {
/** @var FullyQualifiedObjectType $returnType */
$types[] = new \PHPStan\Type\ThisType($returnType->getClassName());
$hasStatic = \true;
continue;
}
$types[] = $returnType;
}
if (!$hasStatic) {
return $type;
}
if (!$isSupportedStaticReturnType) {
return null;
}
return new \PHPStan\Type\UnionType($types);
return $type;
}
private function resolveTypeWithVoidHandling(\PhpParser\Node\FunctionLike $functionLike, \PHPStan\Type\Type $resolvedType) : \PHPStan\Type\Type
{
@ -176,7 +156,7 @@ final class ReturnTypeInferer
}
private function isStaticType(\PHPStan\Type\Type $type) : bool
{
if (!$type instanceof \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType) {
if (!$type instanceof \PHPStan\Type\TypeWithClassName) {
return \false;
}
return $type->getClassName() === \Rector\Core\Enum\ObjectReference::STATIC()->getValue();
@ -193,4 +173,36 @@ final class ReturnTypeInferer
}
return \false;
}
/**
* @return \PHPStan\Type\UnionType|null
*/
private function resolveUnionStaticTypes(\PHPStan\Type\UnionType $unionType, bool $isSupportedStaticReturnType)
{
$returnTypes = $unionType->getTypes();
$types = [];
$hasStatic = \false;
foreach ($returnTypes as $returnType) {
if ($this->isStaticType($returnType)) {
/** @var FullyQualifiedObjectType $returnType */
$types[] = new \PHPStan\Type\ThisType($returnType->getClassName());
$hasStatic = \true;
continue;
}
$types[] = $returnType;
}
if (!$hasStatic) {
return $unionType;
}
if (!$isSupportedStaticReturnType) {
return null;
}
return new \PHPStan\Type\UnionType($types);
}
private function resolveStaticType(bool $isSupportedStaticReturnType, \PHPStan\Type\TypeWithClassName $typeWithClassName) : ?\PHPStan\Type\ThisType
{
if (!$isSupportedStaticReturnType) {
return null;
}
return new \PHPStan\Type\ThisType($typeWithClassName->getClassName());
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '461cb9f38c1677e37d1988592ee18083435c7163';
public const PACKAGE_VERSION = 'ceccbad0ea397dc66bde0f91a88d5ededbe3bbb6';
/**
* @var string
*/
public const RELEASE_DATE = '2021-10-26 02:17:00';
public const RELEASE_DATE = '2021-10-26 09:47:01';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211026\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667::getLoader();
return ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667
class ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6a7575deb01aef0c687b19caf698a667::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit5edd4ad6afff5739353e0c73494d1924::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit6a7575deb01aef0c687b19caf698a667::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit5edd4ad6afff5739353e0c73494d1924::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire6a7575deb01aef0c687b19caf698a667($fileIdentifier, $file);
composerRequire5edd4ad6afff5739353e0c73494d1924($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire6a7575deb01aef0c687b19caf698a667($fileIdentifier, $file)
function composerRequire5edd4ad6afff5739353e0c73494d1924($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit6a7575deb01aef0c687b19caf698a667
class ComposerStaticInit5edd4ad6afff5739353e0c73494d1924
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3887,9 +3887,9 @@ class ComposerStaticInit6a7575deb01aef0c687b19caf698a667
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6a7575deb01aef0c687b19caf698a667::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6a7575deb01aef0c687b19caf698a667::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6a7575deb01aef0c687b19caf698a667::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit5edd4ad6afff5739353e0c73494d1924::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5edd4ad6afff5739353e0c73494d1924::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5edd4ad6afff5739353e0c73494d1924::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211026\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667', false) && !interface_exists('ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667', false) && !trait_exists('ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667', false)) {
spl_autoload_call('RectorPrefix20211026\ComposerAutoloaderInit6a7575deb01aef0c687b19caf698a667');
if (!class_exists('ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924', false) && !interface_exists('ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924', false) && !trait_exists('ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924', false)) {
spl_autoload_call('RectorPrefix20211026\ComposerAutoloaderInit5edd4ad6afff5739353e0c73494d1924');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20211026\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -3306,9 +3306,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211026\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire6a7575deb01aef0c687b19caf698a667')) {
function composerRequire6a7575deb01aef0c687b19caf698a667() {
return \RectorPrefix20211026\composerRequire6a7575deb01aef0c687b19caf698a667(...func_get_args());
if (!function_exists('composerRequire5edd4ad6afff5739353e0c73494d1924')) {
function composerRequire5edd4ad6afff5739353e0c73494d1924() {
return \RectorPrefix20211026\composerRequire5edd4ad6afff5739353e0c73494d1924(...func_get_args());
}
}
if (!function_exists('parseArgs')) {