Updated Rector to commit a9710acede

a9710acede improve alias resolving in namespace-less files (#1085)
This commit is contained in:
Tomas Votruba 2021-10-27 12:31:55 +00:00
parent 0c20321ff6
commit d73a6051ab
8 changed files with 41 additions and 24 deletions

View File

@ -10,6 +10,7 @@ use Rector\Core\Logging\CurrentRectorProvider;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use RectorPrefix20211027\Symfony\Component\Console\Style\SymfonyStyle;
use RectorPrefix20211027\Symplify\Skipper\Skipper\Skipper;
final class PostFileProcessor
{
@ -29,14 +30,19 @@ final class PostFileProcessor
* @var \Rector\Core\Logging\CurrentRectorProvider
*/
private $currentRectorProvider;
/**
* @var \Symfony\Component\Console\Style\SymfonyStyle
*/
private $symfonyStyle;
/**
* @param PostRectorInterface[] $postRectors
*/
public function __construct(\RectorPrefix20211027\Symplify\Skipper\Skipper\Skipper $skipper, \Rector\Core\Provider\CurrentFileProvider $currentFileProvider, \Rector\Core\Logging\CurrentRectorProvider $currentRectorProvider, array $postRectors)
public function __construct(\RectorPrefix20211027\Symplify\Skipper\Skipper\Skipper $skipper, \Rector\Core\Provider\CurrentFileProvider $currentFileProvider, \Rector\Core\Logging\CurrentRectorProvider $currentRectorProvider, \RectorPrefix20211027\Symfony\Component\Console\Style\SymfonyStyle $symfonyStyle, array $postRectors)
{
$this->skipper = $skipper;
$this->currentFileProvider = $currentFileProvider;
$this->currentRectorProvider = $currentRectorProvider;
$this->symfonyStyle = $symfonyStyle;
$this->postRectors = $this->sortByPriority($postRectors);
}
/**
@ -50,6 +56,7 @@ final class PostFileProcessor
continue;
}
$this->currentRectorProvider->changeCurrentRector($postRector);
$this->notifyPostRector($postRector);
$nodeTraverser = new \PhpParser\NodeTraverser();
$nodeTraverser->addVisitor($postRector);
$stmts = $nodeTraverser->traverse($stmts);
@ -81,4 +88,12 @@ final class PostFileProcessor
$smartFileInfo = $file->getSmartFileInfo();
return $this->skipper->shouldSkipElementAndFileInfo($postRector, $smartFileInfo);
}
private function notifyPostRector(\Rector\PostRector\Contract\Rector\PostRectorInterface $postRector) : void
{
if (!$this->symfonyStyle->isVerbose()) {
return;
}
$message = \sprintf(' [%s] %s', 'post rector', \get_class($postRector));
$this->symfonyStyle->writeln($message);
}
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\UseUse;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
@ -31,17 +32,18 @@ final class AliasUsesResolver
$node = $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Stmt\Namespace_::class);
}
if ($node instanceof \PhpParser\Node\Stmt\Namespace_) {
return $this->resolveForNamespace($node);
return $this->resolveFromStmts($node->stmts);
}
return [];
}
/**
* @param Stmt[] $stmts
* @return string[]
*/
private function resolveForNamespace(\PhpParser\Node\Stmt\Namespace_ $namespace) : array
public function resolveFromStmts(array $stmts) : array
{
$aliasedUses = [];
$this->useImportsTraverser->traverserStmts($namespace->stmts, function (\PhpParser\Node\Stmt\UseUse $useUse, string $name) use(&$aliasedUses) : void {
$this->useImportsTraverser->traverserStmts($stmts, function (\PhpParser\Node\Stmt\UseUse $useUse, string $name) use(&$aliasedUses) : void {
if ($useUse->alias === null) {
return;
}

View File

@ -80,7 +80,7 @@ final class NameImporter
if (!$staticType instanceof \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType) {
return null;
}
$this->aliasedUses = $this->aliasUsesResolver->resolveForNode($name);
$this->aliasedUses = $this->aliasUsesResolver->resolveFromStmts($uses);
return $this->importNameAndCollectNewUseStatement($file, $name, $staticType);
}
private function shouldSkipName(\PhpParser\Node\Name $name) : bool

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'aa327fb24b17fabbd9af316899878a59b211f435';
public const PACKAGE_VERSION = 'a9710acede09ef621cc420f674ce3998b07bbca0';
/**
* @var string
*/
public const RELEASE_DATE = '2021-10-27 13:51:25';
public const RELEASE_DATE = '2021-10-27 14:19:09';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211027\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 ComposerAutoloaderInitf30090563667a4fdacb89991079b599a::getLoader();
return ComposerAutoloaderInit0ff9739e6465baf0ce0cfa465881ca0c::getLoader();

View File

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

View File

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