Updated Rector to commit 148dda778c

148dda778c Narrow to FQN (#2168)
This commit is contained in:
Tomas Votruba 2022-04-25 23:28:04 +00:00
parent a71b4168c5
commit 99b901c127
9 changed files with 101 additions and 68 deletions

View File

@ -0,0 +1,13 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\Contract\PHPStan;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ObjectType;
use PHPStan\Type\TypeWithClassName;
interface TypeWithClassTypeSpecifierInterface
{
public function match(\PHPStan\Type\ObjectType $objectType, \PHPStan\Analyser\Scope $scope) : bool;
public function resolveObjectReferenceType(\PHPStan\Type\ObjectType $objectType, \PHPStan\Analyser\Scope $scope) : \PHPStan\Type\TypeWithClassName;
}

View File

@ -9,26 +9,21 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\UseUse;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StaticType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Naming\Naming\UseImportsResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType;
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedGenericObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use Rector\TypeDeclaration\Contract\PHPStan\TypeWithClassTypeSpecifierInterface;
final class ObjectTypeSpecifier
{
/**
@ -41,26 +36,35 @@ final class ObjectTypeSpecifier
* @var \Rector\Naming\Naming\UseImportsResolver
*/
private $useImportsResolver;
public function __construct(\PHPStan\Reflection\ReflectionProvider $reflectionProvider, \Rector\Naming\Naming\UseImportsResolver $useImportsResolver)
/**
* @var TypeWithClassTypeSpecifierInterface[]
* @readonly
*/
private $typeWithClassTypeSpecifiers;
/**
* @param TypeWithClassTypeSpecifierInterface[] $typeWithClassTypeSpecifiers
*/
public function __construct(\PHPStan\Reflection\ReflectionProvider $reflectionProvider, \Rector\Naming\Naming\UseImportsResolver $useImportsResolver, array $typeWithClassTypeSpecifiers)
{
$this->reflectionProvider = $reflectionProvider;
$this->useImportsResolver = $useImportsResolver;
$this->typeWithClassTypeSpecifiers = $typeWithClassTypeSpecifiers;
}
/**
* @param \PHPStan\Analyser\Scope|null $scope
* @return \PHPStan\Type\MixedType|\PHPStan\Type\TypeWithClassName|\PHPStan\Type\UnionType
* @return \PHPStan\Type\MixedType|\PHPStan\Type\TypeWithClassName|\PHPStan\Type\UnionType|\Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType
*/
public function narrowToFullyQualifiedOrAliasedObjectType(\PhpParser\Node $node, \PHPStan\Type\ObjectType $objectType, $scope)
{
$sameNamespacedObjectType = $this->matchSameNamespacedObjectType($node, $objectType);
if ($sameNamespacedObjectType !== null) {
return $sameNamespacedObjectType;
$sameNamespacedFullyQualifiedObjectType = $this->matchSameNamespacedObjectType($node, $objectType);
if ($sameNamespacedFullyQualifiedObjectType !== null) {
return $sameNamespacedFullyQualifiedObjectType;
}
if ($scope instanceof \PHPStan\Analyser\Scope) {
$className = \ltrim($objectType->getClassName(), '\\');
$objectReferenceType = $this->resolveObjectReferenceType($scope, $className);
if ($objectReferenceType instanceof \PHPStan\Type\Type) {
return $objectReferenceType;
foreach ($this->typeWithClassTypeSpecifiers as $typeWithClassTypeSpecifier) {
if ($typeWithClassTypeSpecifier->match($objectType, $scope)) {
return $typeWithClassTypeSpecifier->resolveObjectReferenceType($objectType, $scope);
}
}
}
$uses = $this->useImportsResolver->resolveForNode($node);
@ -79,15 +83,6 @@ final class ObjectTypeSpecifier
return $shortenedObjectType;
}
$className = \ltrim($objectType->getClassName(), '\\');
if (\Rector\Core\Enum\ObjectReference::isValid($className)) {
if (!$scope instanceof \PHPStan\Analyser\Scope) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
$resolvedType = $this->resolveObjectReferenceType($scope, $className);
if ($resolvedType instanceof \PHPStan\Type\Type) {
return $resolvedType;
}
}
if ($this->reflectionProvider->hasClass($className)) {
return new \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType($className);
}
@ -167,7 +162,7 @@ final class ObjectTypeSpecifier
}
return null;
}
private function matchSameNamespacedObjectType(\PhpParser\Node $node, \PHPStan\Type\ObjectType $objectType) : ?\PHPStan\Type\ObjectType
private function matchSameNamespacedObjectType(\PhpParser\Node $node, \PHPStan\Type\ObjectType $objectType) : ?\Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType
{
$scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
if (!$scope instanceof \PHPStan\Analyser\Scope) {
@ -215,28 +210,4 @@ final class ObjectTypeSpecifier
}
return new \Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType($objectType->getClassName(), $useUse->name->toString());
}
/**
* @return \PHPStan\Type\StaticType|\Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType|null
*/
private function resolveObjectReferenceType(\PHPStan\Analyser\Scope $scope, string $classReferenceValue)
{
$classReflection = $scope->getClassReflection();
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
return null;
}
if (\Rector\Core\Enum\ObjectReference::STATIC()->getValue() === $classReferenceValue) {
return new \PHPStan\Type\StaticType($classReflection);
}
if (\Rector\Core\Enum\ObjectReference::SELF()->getValue() === $classReferenceValue) {
return new \Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType($classReferenceValue, null, $classReflection);
}
if (\Rector\Core\Enum\ObjectReference::PARENT()->getValue() === $classReferenceValue) {
$parentClassReflection = $classReflection->getParentClass();
if (!$parentClassReflection instanceof \PHPStan\Reflection\ClassReflection) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
return new \Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType($parentClassReflection);
}
return null;
}
}

View File

@ -0,0 +1,45 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\PHPStan\TypeSpecifier;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StaticType;
use PHPStan\Type\TypeWithClassName;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType;
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
use Rector\TypeDeclaration\Contract\PHPStan\TypeWithClassTypeSpecifierInterface;
final class SelfStaticParentTypeSpecifier implements \Rector\TypeDeclaration\Contract\PHPStan\TypeWithClassTypeSpecifierInterface
{
public function match(\PHPStan\Type\ObjectType $objectType, \PHPStan\Analyser\Scope $scope) : bool
{
$classReflection = $scope->getClassReflection();
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
return \false;
}
return \Rector\Core\Enum\ObjectReference::isValid($objectType->getClassName());
}
public function resolveObjectReferenceType(\PHPStan\Type\ObjectType $objectType, \PHPStan\Analyser\Scope $scope) : \PHPStan\Type\TypeWithClassName
{
$classReflection = $scope->getClassReflection();
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
$classReference = $objectType->getClassName();
if (\Rector\Core\Enum\ObjectReference::STATIC()->getValue() === $classReference) {
return new \PHPStan\Type\StaticType($classReflection);
}
if (\Rector\Core\Enum\ObjectReference::SELF()->getValue() === $classReference) {
return new \Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType($classReference, null, $classReflection);
}
$parentClassReflection = $classReflection->getParentClass();
if (!$parentClassReflection instanceof \PHPStan\Reflection\ClassReflection) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
return new \Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType($parentClassReflection);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '38e1f8a45082086aca4b26b811a1f467f6349f6c';
public const PACKAGE_VERSION = '148dda778c7296a81b2935855b83def5c3385cbf';
/**
* @var string
*/
public const RELEASE_DATE = '2022-04-26 00:04:26';
public const RELEASE_DATE = '2022-04-26 01:19:06';
/**
* @var string
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -3086,6 +3086,7 @@ return array(
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\ConstructorAssignDetector' => $baseDir . '/rules/TypeDeclaration/AlreadyAssignDetector/ConstructorAssignDetector.php',
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\NullTypeAssignDetector' => $baseDir . '/rules/TypeDeclaration/AlreadyAssignDetector/NullTypeAssignDetector.php',
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\PropertyDefaultAssignDetector' => $baseDir . '/rules/TypeDeclaration/AlreadyAssignDetector/PropertyDefaultAssignDetector.php',
'Rector\\TypeDeclaration\\Contract\\PHPStan\\TypeWithClassTypeSpecifierInterface' => $baseDir . '/rules/TypeDeclaration/Contract/PHPStan/TypeWithClassTypeSpecifierInterface.php',
'Rector\\TypeDeclaration\\Contract\\PriorityAwareInterface' => $baseDir . '/rules/TypeDeclaration/Contract/PriorityAwareInterface.php',
'Rector\\TypeDeclaration\\Contract\\TypeInferer\\ParamTypeInfererInterface' => $baseDir . '/rules/TypeDeclaration/Contract/TypeInferer/ParamTypeInfererInterface.php',
'Rector\\TypeDeclaration\\Contract\\TypeInferer\\ReturnTypeInfererInterface' => $baseDir . '/rules/TypeDeclaration/Contract/TypeInferer/ReturnTypeInfererInterface.php',
@ -3107,6 +3108,7 @@ return array(
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\DetailedTypeAnalyzer' => $baseDir . '/rules/TypeDeclaration/NodeTypeAnalyzer/DetailedTypeAnalyzer.php',
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\PropertyTypeDecorator' => $baseDir . '/rules/TypeDeclaration/NodeTypeAnalyzer/PropertyTypeDecorator.php',
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\TraitTypeAnalyzer' => $baseDir . '/rules/TypeDeclaration/NodeTypeAnalyzer/TraitTypeAnalyzer.php',
'Rector\\TypeDeclaration\\PHPStan\\TypeSpecifier\\SelfStaticParentTypeSpecifier' => $baseDir . '/rules/TypeDeclaration/PHPStan/TypeSpecifier/SelfStaticParentTypeSpecifier.php',
'Rector\\TypeDeclaration\\PHPStan\\Type\\ObjectTypeSpecifier' => $baseDir . '/rules/TypeDeclaration/PHPStan/Type/ObjectTypeSpecifier.php',
'Rector\\TypeDeclaration\\PhpDocParser\\NonInformativeReturnTagRemover' => $baseDir . '/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php',
'Rector\\TypeDeclaration\\PhpDocParser\\ParamPhpDocNodeFactory' => $baseDir . '/rules/TypeDeclaration/PhpDocParser/ParamPhpDocNodeFactory.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d
class ComposerAutoloaderInitf49fae9c470dbb7188ccce702cb8ad9c
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitf49fae9c470dbb7188ccce702cb8ad9c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitf49fae9c470dbb7188ccce702cb8ad9c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitf49fae9c470dbb7188ccce702cb8ad9c::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInitf49fae9c470dbb7188ccce702cb8ad9c::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirebcdaeabab37a18d9a0720998e454d54d($fileIdentifier, $file);
composerRequiref49fae9c470dbb7188ccce702cb8ad9c($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d
* @param string $file
* @return void
*/
function composerRequirebcdaeabab37a18d9a0720998e454d54d($fileIdentifier, $file)
function composerRequiref49fae9c470dbb7188ccce702cb8ad9c($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 ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d
class ComposerStaticInitf49fae9c470dbb7188ccce702cb8ad9c
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -3455,6 +3455,7 @@ class ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\ConstructorAssignDetector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/AlreadyAssignDetector/ConstructorAssignDetector.php',
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\NullTypeAssignDetector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/AlreadyAssignDetector/NullTypeAssignDetector.php',
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\PropertyDefaultAssignDetector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/AlreadyAssignDetector/PropertyDefaultAssignDetector.php',
'Rector\\TypeDeclaration\\Contract\\PHPStan\\TypeWithClassTypeSpecifierInterface' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Contract/PHPStan/TypeWithClassTypeSpecifierInterface.php',
'Rector\\TypeDeclaration\\Contract\\PriorityAwareInterface' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Contract/PriorityAwareInterface.php',
'Rector\\TypeDeclaration\\Contract\\TypeInferer\\ParamTypeInfererInterface' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Contract/TypeInferer/ParamTypeInfererInterface.php',
'Rector\\TypeDeclaration\\Contract\\TypeInferer\\ReturnTypeInfererInterface' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Contract/TypeInferer/ReturnTypeInfererInterface.php',
@ -3476,6 +3477,7 @@ class ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\DetailedTypeAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/NodeTypeAnalyzer/DetailedTypeAnalyzer.php',
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\PropertyTypeDecorator' => __DIR__ . '/../..' . '/rules/TypeDeclaration/NodeTypeAnalyzer/PropertyTypeDecorator.php',
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\TraitTypeAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/NodeTypeAnalyzer/TraitTypeAnalyzer.php',
'Rector\\TypeDeclaration\\PHPStan\\TypeSpecifier\\SelfStaticParentTypeSpecifier' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PHPStan/TypeSpecifier/SelfStaticParentTypeSpecifier.php',
'Rector\\TypeDeclaration\\PHPStan\\Type\\ObjectTypeSpecifier' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PHPStan/Type/ObjectTypeSpecifier.php',
'Rector\\TypeDeclaration\\PhpDocParser\\NonInformativeReturnTagRemover' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php',
'Rector\\TypeDeclaration\\PhpDocParser\\ParamPhpDocNodeFactory' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PhpDocParser/ParamPhpDocNodeFactory.php',
@ -3871,9 +3873,9 @@ class ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitbcdaeabab37a18d9a0720998e454d54d::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitf49fae9c470dbb7188ccce702cb8ad9c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf49fae9c470dbb7188ccce702cb8ad9c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf49fae9c470dbb7188ccce702cb8ad9c::$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('RectorPrefix20220425\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d', false) && !interface_exists('ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d', false) && !trait_exists('ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d', false)) {
spl_autoload_call('RectorPrefix20220425\ComposerAutoloaderInitbcdaeabab37a18d9a0720998e454d54d');
if (!class_exists('ComposerAutoloaderInitf49fae9c470dbb7188ccce702cb8ad9c', false) && !interface_exists('ComposerAutoloaderInitf49fae9c470dbb7188ccce702cb8ad9c', false) && !trait_exists('ComposerAutoloaderInitf49fae9c470dbb7188ccce702cb8ad9c', false)) {
spl_autoload_call('RectorPrefix20220425\ComposerAutoloaderInitf49fae9c470dbb7188ccce702cb8ad9c');
}
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('RectorPrefix20220425\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220425\print_node(...func_get_args());
}
}
if (!function_exists('composerRequirebcdaeabab37a18d9a0720998e454d54d')) {
function composerRequirebcdaeabab37a18d9a0720998e454d54d() {
return \RectorPrefix20220425\composerRequirebcdaeabab37a18d9a0720998e454d54d(...func_get_args());
if (!function_exists('composerRequiref49fae9c470dbb7188ccce702cb8ad9c')) {
function composerRequiref49fae9c470dbb7188ccce702cb8ad9c() {
return \RectorPrefix20220425\composerRequiref49fae9c470dbb7188ccce702cb8ad9c(...func_get_args());
}
}
if (!function_exists('scanPath')) {