Updated Rector to commit eadd54081521c7d426a8d4249157f6239dd2bc8a

eadd540815 [Core] Remove ParentAttributeSourceLocator (#3257)
This commit is contained in:
Tomas Votruba 2022-12-31 10:11:25 +00:00
parent dbb3bb2510
commit 1ccd0845db
12 changed files with 40 additions and 104 deletions

View File

@ -45,7 +45,6 @@ use PHPStan\Type\TypeCombinator;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Caching\FileSystem\DependencyResolver;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\StaticReflection\SourceLocator\ParentAttributeSourceLocator;
use Rector\Core\StaticReflection\SourceLocator\RenamedClassesSourceLocator;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\Core\Util\StringUtils;
@ -108,17 +107,12 @@ final class PHPStanNodeScopeResolver
* @var \Rector\Core\StaticReflection\SourceLocator\RenamedClassesSourceLocator
*/
private $renamedClassesSourceLocator;
/**
* @readonly
* @var \Rector\Core\StaticReflection\SourceLocator\ParentAttributeSourceLocator
*/
private $parentAttributeSourceLocator;
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(ChangedFilesDetector $changedFilesDetector, DependencyResolver $dependencyResolver, NodeScopeResolver $nodeScopeResolver, ReflectionProvider $reflectionProvider, RemoveDeepChainMethodCallNodeVisitor $removeDeepChainMethodCallNodeVisitor, \Rector\NodeTypeResolver\PHPStan\Scope\ScopeFactory $scopeFactory, PrivatesAccessor $privatesAccessor, RenamedClassesSourceLocator $renamedClassesSourceLocator, ParentAttributeSourceLocator $parentAttributeSourceLocator, NodeNameResolver $nodeNameResolver)
public function __construct(ChangedFilesDetector $changedFilesDetector, DependencyResolver $dependencyResolver, NodeScopeResolver $nodeScopeResolver, ReflectionProvider $reflectionProvider, RemoveDeepChainMethodCallNodeVisitor $removeDeepChainMethodCallNodeVisitor, \Rector\NodeTypeResolver\PHPStan\Scope\ScopeFactory $scopeFactory, PrivatesAccessor $privatesAccessor, RenamedClassesSourceLocator $renamedClassesSourceLocator, NodeNameResolver $nodeNameResolver)
{
$this->changedFilesDetector = $changedFilesDetector;
$this->dependencyResolver = $dependencyResolver;
@ -128,7 +122,6 @@ final class PHPStanNodeScopeResolver
$this->scopeFactory = $scopeFactory;
$this->privatesAccessor = $privatesAccessor;
$this->renamedClassesSourceLocator = $renamedClassesSourceLocator;
$this->parentAttributeSourceLocator = $parentAttributeSourceLocator;
$this->nodeNameResolver = $nodeNameResolver;
$this->decoratePHPStanNodeScopeResolverWithRenamedClassSourceLocator($this->nodeScopeResolver);
}
@ -389,7 +382,7 @@ final class PHPStanNodeScopeResolver
/** @var SourceLocator $sourceLocator */
$sourceLocator = $this->privatesAccessor->getPrivatePropertyOfClass($reflector, 'sourceLocator', SourceLocator::class);
// 2. get Rector locator
$aggregateSourceLocator = new AggregateSourceLocator([$sourceLocator, $this->renamedClassesSourceLocator, $this->parentAttributeSourceLocator]);
$aggregateSourceLocator = new AggregateSourceLocator([$sourceLocator, $this->renamedClassesSourceLocator]);
$this->privatesAccessor->setPrivatePropertyOfClass($reflector, 'sourceLocator', $aggregateSourceLocator, AggregateSourceLocator::class);
}
}

View File

@ -12,6 +12,7 @@ use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use RectorPrefix202212\Spatie\Enum\Enum;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -21,6 +22,9 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class SpatieEnumMethodCallToEnumConstRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @var class-string<Enum>
*/
private const SPATIE_FQN = 'Spatie\\Enum\\Enum';
/**
* @var string[]
@ -107,10 +111,16 @@ CODE_SAMPLE
if (!$this->isObjectType($methodCall->var, new ObjectType(self::SPATIE_FQN))) {
return null;
}
if ($methodName === 'getName' || $methodName === 'label') {
if ($methodName === 'getName') {
return $this->refactorGetterToMethodCall($methodCall, 'name');
}
if ($methodName === 'getValue' || $methodName === 'value') {
if ($methodName === 'label') {
return $this->refactorGetterToMethodCall($methodCall, 'name');
}
if ($methodName === 'getValue') {
return $this->refactorGetterToMethodCall($methodCall, 'value');
}
if ($methodName === 'value') {
return $this->refactorGetterToMethodCall($methodCall, 'value');
}
return null;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '6bd6b3cc85138b0d2b754175fad616d02cea6b72';
public const PACKAGE_VERSION = 'eadd54081521c7d426a8d4249157f6239dd2bc8a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-12-29 14:21:26';
public const RELEASE_DATE = '2022-12-31 11:07:21';
/**
* @var int
*/

View File

@ -1,69 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Core\StaticReflection\SourceLocator;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\BetterReflection\Identifier\Identifier;
use PHPStan\BetterReflection\Identifier\IdentifierType;
use PHPStan\BetterReflection\Reflection\Reflection;
use PHPStan\BetterReflection\Reflection\ReflectionClass;
use PHPStan\BetterReflection\Reflector\ClassReflector;
use PHPStan\BetterReflection\Reflector\Reflector;
use PHPStan\BetterReflection\SourceLocator\Located\LocatedSource;
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\PhpParser\AstResolver;
use RectorPrefix202212\Symfony\Contracts\Service\Attribute\Required;
/**
* This mimics classes that PHPStan fails to find in scope, but actually has an access in static reflection.
* Some weird bug, that crashes on parent classes.
*
* @see https://github.com/rectorphp/rector-src/pull/368/
*/
final class ParentAttributeSourceLocator implements SourceLocator
{
/**
* @var \Rector\Core\PhpParser\AstResolver
*/
private $astResolver;
/**
* @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
/**
* @required
*/
public function autowire(AstResolver $astResolver) : void
{
$this->astResolver = $astResolver;
}
public function locateIdentifier(Reflector $reflector, Identifier $identifier) : ?Reflection
{
$identifierName = $identifier->getName();
if ($identifierName === 'Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure' && $this->reflectionProvider->hasClass($identifierName)) {
$classReflection = $this->reflectionProvider->getClass($identifierName);
$class = $this->astResolver->resolveClassFromClassReflection($classReflection);
if ($class === null) {
return null;
}
$class->namespacedName = new FullyQualified($identifierName);
$fakeLocatedSource = new LocatedSource('virtual', null);
$classReflector = new ClassReflector($this);
return ReflectionClass::createFromNode($classReflector, $class, $fakeLocatedSource, 'Symfony\\Component\\DependencyInjection\\Attribute');
}
return null;
}
/**
* @return array<int, Reflection>
*/
public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType) : array
{
return [];
}
}

2
vendor/autoload.php vendored
View File

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

View File

@ -1496,7 +1496,6 @@ return array(
'Rector\\Core\\Reflection\\ReflectionResolver' => $baseDir . '/src/Reflection/ReflectionResolver.php',
'Rector\\Core\\Reporting\\MissingRectorRulesReporter' => $baseDir . '/src/Reporting/MissingRectorRulesReporter.php',
'Rector\\Core\\StaticReflection\\DynamicSourceLocatorDecorator' => $baseDir . '/src/StaticReflection/DynamicSourceLocatorDecorator.php',
'Rector\\Core\\StaticReflection\\SourceLocator\\ParentAttributeSourceLocator' => $baseDir . '/src/StaticReflection/SourceLocator/ParentAttributeSourceLocator.php',
'Rector\\Core\\StaticReflection\\SourceLocator\\RenamedClassesSourceLocator' => $baseDir . '/src/StaticReflection/SourceLocator/RenamedClassesSourceLocator.php',
'Rector\\Core\\Util\\ArrayParametersMerger' => $baseDir . '/src/Util/ArrayParametersMerger.php',
'Rector\\Core\\Util\\MemoryLimiter' => $baseDir . '/src/Util/MemoryLimiter.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitd14a19d4ef605dbeabaa661781ec11a0
class ComposerAutoloaderIniteecf9682bc8e9d4659a6628a6ec003f2
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitd14a19d4ef605dbeabaa661781ec11a0
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitd14a19d4ef605dbeabaa661781ec11a0', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderIniteecf9682bc8e9d4659a6628a6ec003f2', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitd14a19d4ef605dbeabaa661781ec11a0', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderIniteecf9682bc8e9d4659a6628a6ec003f2', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticIniteecf9682bc8e9d4659a6628a6ec003f2::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticIniteecf9682bc8e9d4659a6628a6ec003f2::$files;
$requireFile = 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 ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0
class ComposerStaticIniteecf9682bc8e9d4659a6628a6ec003f2
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1741,7 +1741,6 @@ class ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0
'Rector\\Core\\Reflection\\ReflectionResolver' => __DIR__ . '/../..' . '/src/Reflection/ReflectionResolver.php',
'Rector\\Core\\Reporting\\MissingRectorRulesReporter' => __DIR__ . '/../..' . '/src/Reporting/MissingRectorRulesReporter.php',
'Rector\\Core\\StaticReflection\\DynamicSourceLocatorDecorator' => __DIR__ . '/../..' . '/src/StaticReflection/DynamicSourceLocatorDecorator.php',
'Rector\\Core\\StaticReflection\\SourceLocator\\ParentAttributeSourceLocator' => __DIR__ . '/../..' . '/src/StaticReflection/SourceLocator/ParentAttributeSourceLocator.php',
'Rector\\Core\\StaticReflection\\SourceLocator\\RenamedClassesSourceLocator' => __DIR__ . '/../..' . '/src/StaticReflection/SourceLocator/RenamedClassesSourceLocator.php',
'Rector\\Core\\Util\\ArrayParametersMerger' => __DIR__ . '/../..' . '/src/Util/ArrayParametersMerger.php',
'Rector\\Core\\Util\\MemoryLimiter' => __DIR__ . '/../..' . '/src/Util/MemoryLimiter.php',
@ -3063,9 +3062,9 @@ class ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd14a19d4ef605dbeabaa661781ec11a0::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticIniteecf9682bc8e9d4659a6628a6ec003f2::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticIniteecf9682bc8e9d4659a6628a6ec003f2::$prefixDirsPsr4;
$loader->classMap = ComposerStaticIniteecf9682bc8e9d4659a6628a6ec003f2::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2122,12 +2122,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "b463377817b8d27fbf97c4d576bea9abf31b8261"
"reference": "5b66a88d36ce062e16317a5baef054679cf4abcc"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/b463377817b8d27fbf97c4d576bea9abf31b8261",
"reference": "b463377817b8d27fbf97c4d576bea9abf31b8261",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/5b66a88d36ce062e16317a5baef054679cf4abcc",
"reference": "5b66a88d36ce062e16317a5baef054679cf4abcc",
"shasum": ""
},
"require": {
@ -2157,7 +2157,7 @@
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2022-12-22T08:18:32+00:00",
"time": "2022-12-30T10:00:03+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d5c39ae'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6cf8d9d'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3b56cf5'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b463377'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d5c39ae'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6cf8d9d'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3b56cf5'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 5b66a88'));
private function __construct()
{
}

View File

@ -24,7 +24,7 @@ return static function (RectorConfig $rectorConfig): void {
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
$rectorConfig->sets([
SymfonySetList::SYMFONY_52,
SymfonySetList::SYMFONY_62,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
]);
@ -39,13 +39,13 @@ return static function (RectorConfig $rectorConfig): void {
Some rules like `StringFormTypeToClassRector` need access to your Symfony container dumped XML. It contains list of form types with their string names, so it can convert them to class references.
How to add it? Check your `/var/cache` directory and find the XML file for your test env. Then add it in `rector.php`:
How to add it? Check your `var/cache/` directory and find the XML file for your test env. Then add it in `rector.php`:
```php
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/<env>/appProjectContainer.xml');
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/test/App_KernelTestDebugContainer.xml');
};
```
@ -70,7 +70,11 @@ The `tests/symfony-container.php` should provide your dependency injection conta
```php
// tests/symfony-container.php
$appKernel = new AppKernel('tests', false);
use App\Kernel;
require __DIR__ . '/bootstrap.php';
$appKernel = new Kernel('test', false);
$appKernel->boot();
return $appKernel->getContainer();