Updated Rector to commit 06ea31c2de864de4af1a4766e46aa683214a71d0

06ea31c2de Fix Rector apply on Source locators (#1053)
This commit is contained in:
Tomas Votruba 2021-10-24 20:38:54 +00:00
parent cef09b47a1
commit 549f59ce92
10 changed files with 48 additions and 67 deletions

View File

@ -7,7 +7,6 @@ use PhpParser\Node;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Dependency\DependencyResolver as PHPStanDependencyResolver;
use PHPStan\File\FileHelper;
use RectorPrefix20211024\Symplify\PackageBuilder\Reflection\PrivatesAccessor;
final class DependencyResolver
{
@ -19,19 +18,14 @@ final class DependencyResolver
* @var PHPStanDependencyResolver
*/
private $phpStanDependencyResolver;
/**
* @var \PHPStan\File\FileHelper
*/
private $fileHelper;
/**
* @var \Symplify\PackageBuilder\Reflection\PrivatesAccessor
*/
private $privatesAccessor;
public function __construct(\PHPStan\Analyser\NodeScopeResolver $nodeScopeResolver, \PHPStan\Dependency\DependencyResolver $phpStanDependencyResolver, \PHPStan\File\FileHelper $fileHelper, \RectorPrefix20211024\Symplify\PackageBuilder\Reflection\PrivatesAccessor $privatesAccessor)
public function __construct(\PHPStan\Analyser\NodeScopeResolver $nodeScopeResolver, \PHPStan\Dependency\DependencyResolver $phpStanDependencyResolver, \RectorPrefix20211024\Symplify\PackageBuilder\Reflection\PrivatesAccessor $privatesAccessor)
{
$this->nodeScopeResolver = $nodeScopeResolver;
$this->phpStanDependencyResolver = $phpStanDependencyResolver;
$this->fileHelper = $fileHelper;
$this->privatesAccessor = $privatesAccessor;
}
/**
@ -40,24 +34,7 @@ final class DependencyResolver
public function resolveDependencies(\PhpParser\Node $node, \PHPStan\Analyser\MutatingScope $mutatingScope) : array
{
$analysedFileAbsolutesPaths = $this->privatesAccessor->getPrivateProperty($this->nodeScopeResolver, 'analysedFiles');
$dependencyFiles = [];
$nodeDependencies = $this->phpStanDependencyResolver->resolveDependencies($node, $mutatingScope);
foreach ($nodeDependencies as $nodeDependency) {
$dependencyFile = $nodeDependency->getFileName();
if (!$dependencyFile) {
continue;
}
$dependencyFile = $this->fileHelper->normalizePath($dependencyFile);
if ($mutatingScope->getFile() === $dependencyFile) {
continue;
}
// only work with files that we've analysed
if (!\in_array($dependencyFile, $analysedFileAbsolutesPaths, \true)) {
continue;
}
$dependencyFiles[] = $dependencyFile;
}
$dependencyFiles = \array_unique($dependencyFiles, \SORT_STRING);
return \array_values($dependencyFiles);
return $nodeDependencies->getFileDependencies($mutatingScope->getFile(), $analysedFileAbsolutesPaths);
}
}

View File

@ -12,9 +12,9 @@ use Rector\NodeTypeResolver\Contract\SourceLocatorProviderInterface;
final class IntermediateSourceLocator implements \PHPStan\BetterReflection\SourceLocator\Type\SourceLocator
{
/**
* @var SourceLocatorProviderInterface[]
* @var \Rector\NodeTypeResolver\Contract\SourceLocatorProviderInterface[]
*/
private $sourceLocatorProviders = [];
private $sourceLocatorProviders;
/**
* @param SourceLocatorProviderInterface[] $sourceLocatorProviders
*/

View File

@ -22,13 +22,13 @@ final class DynamicSourceLocatorProvider implements \Rector\NodeTypeResolver\Con
*/
private $filesByDirectory = [];
/**
* @var FileNodesFetcher
* @var \PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator|null
*/
private $aggregateSourceLocator;
/**
* @var \PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher
*/
private $fileNodesFetcher;
/**
* @var SourceLocator|null
*/
private $cachedSourceLocator;
public function __construct(\PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher $fileNodesFetcher)
{
$this->fileNodesFetcher = $fileNodesFetcher;
@ -51,8 +51,8 @@ final class DynamicSourceLocatorProvider implements \Rector\NodeTypeResolver\Con
{
// do not cache for PHPUnit, as in test every fixture is different
$isPHPUnitRun = \Rector\Testing\PHPUnit\StaticPHPUnitEnvironment::isPHPUnitRun();
if ($this->cachedSourceLocator && $isPHPUnitRun === \false) {
return $this->cachedSourceLocator;
if ($this->aggregateSourceLocator && !$isPHPUnitRun) {
return $this->aggregateSourceLocator;
}
$sourceLocators = [];
foreach ($this->files as $file) {
@ -61,8 +61,8 @@ final class DynamicSourceLocatorProvider implements \Rector\NodeTypeResolver\Con
foreach ($this->filesByDirectory as $files) {
$sourceLocators[] = new \PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocator($this->fileNodesFetcher, $files);
}
$this->cachedSourceLocator = new \PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator($sourceLocators);
return $this->cachedSourceLocator;
$this->aggregateSourceLocator = new \PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator($sourceLocators);
return $this->aggregateSourceLocator;
}
/**
* @param string[] $files

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'a5048195a7fbdf8d6f7ec09e4869e1a9510e55fe';
public const PACKAGE_VERSION = '06ea31c2de864de4af1a4766e46aa683214a71d0';
/**
* @var string
*/
public const RELEASE_DATE = '2021-10-24 14:51:53';
public const RELEASE_DATE = '2021-10-24 20:22:47';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211024\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -46,21 +46,22 @@ final class ParentAttributeSourceLocator implements \PHPStan\BetterReflection\So
}
public function locateIdentifier(\PHPStan\BetterReflection\Reflector\Reflector $reflector, \PHPStan\BetterReflection\Identifier\Identifier $identifier) : ?\PHPStan\BetterReflection\Reflection\Reflection
{
if ($identifier->getName() === 'Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure') {
if ($this->reflectionProvider->hasClass($identifier->getName())) {
$classReflection = $this->reflectionProvider->getClass($identifier->getName());
$class = $this->astResolver->resolveClassFromClassReflection($classReflection, $identifier->getName());
if ($class === null) {
return null;
}
$class->namespacedName = new \PhpParser\Node\Name\FullyQualified($identifier->getName());
$fakeLocatedSource = new \PHPStan\BetterReflection\SourceLocator\Located\LocatedSource('virtual', null);
$classReflector = new \PHPStan\BetterReflection\Reflector\ClassReflector($this);
return \PHPStan\BetterReflection\Reflection\ReflectionClass::createFromNode($classReflector, $class, $fakeLocatedSource, new \PhpParser\Node\Stmt\Namespace_(new \PhpParser\Node\Name('Symfony\\Component\\DependencyInjection\\Attribute')));
if ($identifier->getName() === 'Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure' && $this->reflectionProvider->hasClass($identifier->getName())) {
$classReflection = $this->reflectionProvider->getClass($identifier->getName());
$class = $this->astResolver->resolveClassFromClassReflection($classReflection, $identifier->getName());
if ($class === null) {
return null;
}
$class->namespacedName = new \PhpParser\Node\Name\FullyQualified($identifier->getName());
$fakeLocatedSource = new \PHPStan\BetterReflection\SourceLocator\Located\LocatedSource('virtual', null);
$classReflector = new \PHPStan\BetterReflection\Reflector\ClassReflector($this);
return \PHPStan\BetterReflection\Reflection\ReflectionClass::createFromNode($classReflector, $class, $fakeLocatedSource, new \PhpParser\Node\Stmt\Namespace_(new \PhpParser\Node\Name('Symfony\\Component\\DependencyInjection\\Attribute')));
}
return null;
}
/**
* @return Reflection[]
*/
public function locateIdentifiersByType(\PHPStan\BetterReflection\Reflector\Reflector $reflector, \PHPStan\BetterReflection\Identifier\IdentifierType $identifierType) : array
{
return [];

View File

@ -28,7 +28,7 @@ final class RenamedClassesSourceLocator implements \PHPStan\BetterReflection\Sou
}
public function locateIdentifier(\PHPStan\BetterReflection\Reflector\Reflector $reflector, \PHPStan\BetterReflection\Identifier\Identifier $identifier) : ?\PHPStan\BetterReflection\Reflection\Reflection
{
foreach ($this->renamedClassesDataCollector->getOldToNewClasses() as $oldClass => $newClass) {
foreach ($this->renamedClassesDataCollector->getOldClasses() as $oldClass) {
if ($identifier->getName() !== $oldClass) {
continue;
}
@ -37,6 +37,9 @@ final class RenamedClassesSourceLocator implements \PHPStan\BetterReflection\Sou
}
return null;
}
/**
* @return Reflection[]
*/
public function locateIdentifiersByType(\PHPStan\BetterReflection\Reflector\Reflector $reflector, \PHPStan\BetterReflection\Identifier\IdentifierType $identifierType) : array
{
return [];

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571
class ComposerAutoloaderInitebb129bae51c9d6dfc3fe8a54145f846
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitebb129bae51c9d6dfc3fe8a54145f846', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitebb129bae51c9d6dfc3fe8a54145f846', '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\ComposerStaticInit011b72b8b7474461a0cd4f061bc59571::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitebb129bae51c9d6dfc3fe8a54145f846::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit011b72b8b7474461a0cd4f061bc59571::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitebb129bae51c9d6dfc3fe8a54145f846::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire011b72b8b7474461a0cd4f061bc59571($fileIdentifier, $file);
composerRequireebb129bae51c9d6dfc3fe8a54145f846($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire011b72b8b7474461a0cd4f061bc59571($fileIdentifier, $file)
function composerRequireebb129bae51c9d6dfc3fe8a54145f846($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit011b72b8b7474461a0cd4f061bc59571
class ComposerStaticInitebb129bae51c9d6dfc3fe8a54145f846
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3917,9 +3917,9 @@ class ComposerStaticInit011b72b8b7474461a0cd4f061bc59571
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit011b72b8b7474461a0cd4f061bc59571::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit011b72b8b7474461a0cd4f061bc59571::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit011b72b8b7474461a0cd4f061bc59571::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitebb129bae51c9d6dfc3fe8a54145f846::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitebb129bae51c9d6dfc3fe8a54145f846::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitebb129bae51c9d6dfc3fe8a54145f846::$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('RectorPrefix20211024\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571', false) && !interface_exists('ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571', false) && !trait_exists('ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571', false)) {
spl_autoload_call('RectorPrefix20211024\ComposerAutoloaderInit011b72b8b7474461a0cd4f061bc59571');
if (!class_exists('ComposerAutoloaderInitebb129bae51c9d6dfc3fe8a54145f846', false) && !interface_exists('ComposerAutoloaderInitebb129bae51c9d6dfc3fe8a54145f846', false) && !trait_exists('ComposerAutoloaderInitebb129bae51c9d6dfc3fe8a54145f846', false)) {
spl_autoload_call('RectorPrefix20211024\ComposerAutoloaderInitebb129bae51c9d6dfc3fe8a54145f846');
}
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('RectorPrefix20211024\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -3306,9 +3306,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211024\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire011b72b8b7474461a0cd4f061bc59571')) {
function composerRequire011b72b8b7474461a0cd4f061bc59571() {
return \RectorPrefix20211024\composerRequire011b72b8b7474461a0cd4f061bc59571(...func_get_args());
if (!function_exists('composerRequireebb129bae51c9d6dfc3fe8a54145f846')) {
function composerRequireebb129bae51c9d6dfc3fe8a54145f846() {
return \RectorPrefix20211024\composerRequireebb129bae51c9d6dfc3fe8a54145f846(...func_get_args());
}
}
if (!function_exists('parseArgs')) {