Updated Rector to commit aef093ee8a5a19bb1351345770ac761ae9e0f655

aef093ee8a [Traverser] Remove next attribute in BetterNodeFinder (#3887)
This commit is contained in:
Tomas Votruba 2023-05-19 11:20:36 +00:00
parent b90fc1b7fa
commit 51a6ca5220
6 changed files with 58 additions and 19 deletions

View File

@ -4,13 +4,35 @@ declare (strict_types=1);
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\NodeVisitorAbstract;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
final class StmtKeyNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
/**
* @param Node[] $nodes
* @return Node[]
*/
public function beforeTraverse(array $nodes) : array
{
// count = 1 is essential here as FileWithoutNamespace can merge with other Stmt
if (\count($nodes) === 1) {
$currentNode = \current($nodes);
if ($currentNode instanceof FileWithoutNamespace) {
foreach ($currentNode->stmts as $key => $stmt) {
$stmt->setAttribute(AttributeKey::STMT_KEY, $key);
}
}
return $nodes;
}
foreach ($nodes as $key => $node) {
$node->setAttribute(AttributeKey::STMT_KEY, $key);
}
return $nodes;
}
/**
* @param Node[] $nodes
* @return Node[]
@ -18,9 +40,10 @@ final class StmtKeyNodeVisitor extends NodeVisitorAbstract implements ScopeResol
public function afterTraverse(array $nodes) : array
{
foreach ($nodes as $key => $node) {
if ($node instanceof Stmt) {
$node->setAttribute(AttributeKey::STMT_KEY, $key);
if (!$node instanceof Namespace_) {
return $nodes;
}
$node->setAttribute(AttributeKey::STMT_KEY, $key);
}
return $nodes;
}
@ -29,6 +52,10 @@ final class StmtKeyNodeVisitor extends NodeVisitorAbstract implements ScopeResol
if (!$node instanceof StmtsAwareInterface) {
return null;
}
// covered on beforeTraverse() as top level node handling
if ($node instanceof FileWithoutNamespace) {
return null;
}
if ($node->stmts === null) {
return null;
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '9fff8d32f3c52769e97ba3e358e8c43f143f0f92';
public const PACKAGE_VERSION = 'aef093ee8a5a19bb1351345770ac761ae9e0f655';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-19 08:43:50';
public const RELEASE_DATE = '2023-05-19 18:15:35';
/**
* @var int
*/

View File

@ -478,6 +478,19 @@ final class BetterNodeFinder
}
return null;
}
private function resolveNeighborNextStmt(StmtsAwareInterface $stmtsAware, Stmt $stmt, ?int $key) : ?Node
{
if ($key === null) {
$key = 0;
}
if (!isset($stmtsAware->stmts[$key - 1])) {
return $stmtsAware->stmts[$key + 1] ?? null;
}
if ($stmtsAware->stmts[$key - 1]->getStartTokenPos() !== $stmt->getStartTokenPos()) {
return $stmtsAware->stmts[$key + 1] ?? null;
}
return $stmt;
}
/**
* Only search in next Node/Stmt
*
@ -492,9 +505,8 @@ final class BetterNodeFinder
if (!$parentNode instanceof StmtsAwareInterface) {
return null;
}
// todo: use +1 key once all next node attribute reference and NodeConnectingVisitor removed
// left with add SlimNodeConnectingVisitor for only lookup parent
$nextNode = $node->getAttribute(AttributeKey::NEXT_NODE);
$currentStmtKey = $node->getAttribute(AttributeKey::STMT_KEY);
$nextNode = $this->resolveNeighborNextStmt($parentNode, $node, $currentStmtKey);
} else {
$nextNode = $this->resolveNextNodeFromOtherNode($node);
}
@ -635,7 +647,7 @@ final class BetterNodeFinder
if (!isset($parentNode->stmts[$currentStmtKey - 1])) {
return $this->findFirstInTopLevelStmtsAware($parentNode, $filter);
}
$previousNode = $parentNode->stmts[$currentStmtKey - 1];
$previousNode = $parentNode->stmts[$currentStmtKey - 1] ?? null;
} else {
$previousNode = $this->resolvePreviousNodeFromOtherNode($node);
}

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit3f2d70c7039a59850ffa4eb4f5609c48
class ComposerAutoloaderInitbcc7e257db5496ceaf0dccb1d9cb5ac4
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit3f2d70c7039a59850ffa4eb4f5609c48
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit3f2d70c7039a59850ffa4eb4f5609c48', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitbcc7e257db5496ceaf0dccb1d9cb5ac4', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit3f2d70c7039a59850ffa4eb4f5609c48', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitbcc7e257db5496ceaf0dccb1d9cb5ac4', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit3f2d70c7039a59850ffa4eb4f5609c48::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitbcc7e257db5496ceaf0dccb1d9cb5ac4::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit3f2d70c7039a59850ffa4eb4f5609c48::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitbcc7e257db5496ceaf0dccb1d9cb5ac4::$files;
$requireFile = \Closure::bind(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 ComposerStaticInit3f2d70c7039a59850ffa4eb4f5609c48
class ComposerStaticInitbcc7e257db5496ceaf0dccb1d9cb5ac4
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3114,9 +3114,9 @@ class ComposerStaticInit3f2d70c7039a59850ffa4eb4f5609c48
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit3f2d70c7039a59850ffa4eb4f5609c48::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3f2d70c7039a59850ffa4eb4f5609c48::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3f2d70c7039a59850ffa4eb4f5609c48::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitbcc7e257db5496ceaf0dccb1d9cb5ac4::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitbcc7e257db5496ceaf0dccb1d9cb5ac4::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitbcc7e257db5496ceaf0dccb1d9cb5ac4::$classMap;
}, null, ClassLoader::class);
}