mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-08 12:20:52 +00:00
Updated Rector to commit 20fce3b76e3e6bbe510b79e11387831854b6cc3d
20fce3b76e
[Parser] Allow resolve next/prev stmt inside ClassLike or Declare_ on BetterNodeFinder (#3905)
This commit is contained in:
parent
c1ef3ac6b3
commit
d3b93de97f
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '974a1bed608c4dedb4190e5fae4760c0d9bdfc72';
|
||||
public const PACKAGE_VERSION = '20fce3b76e3e6bbe510b79e11387831854b6cc3d';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-21 02:20:21';
|
||||
public const RELEASE_DATE = '2023-05-21 06:33:48';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@ use PhpParser\Node\Stmt\Case_;
|
|||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Declare_;
|
||||
use PhpParser\Node\Stmt\Do_;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
use PhpParser\Node\Stmt\For_;
|
||||
|
@ -478,7 +479,14 @@ final class BetterNodeFinder
|
|||
}
|
||||
return null;
|
||||
}
|
||||
private function resolveNeighborNextStmt(StmtsAwareInterface $stmtsAware, Stmt $stmt, int $key) : ?Node
|
||||
private function isAllowedParentNode(?Node $node) : bool
|
||||
{
|
||||
return $node instanceof StmtsAwareInterface || $node instanceof ClassLike || $node instanceof Declare_;
|
||||
}
|
||||
/**
|
||||
* @param \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface|\PhpParser\Node\Stmt\ClassLike|\PhpParser\Node\Stmt\Declare_ $stmtsAware
|
||||
*/
|
||||
private function resolveNeighborNextStmt($stmtsAware, Stmt $stmt, int $key) : ?Node
|
||||
{
|
||||
if (!isset($stmtsAware->stmts[$key - 1])) {
|
||||
return $stmtsAware->stmts[$key + 1] ?? null;
|
||||
|
@ -506,10 +514,11 @@ final class BetterNodeFinder
|
|||
if (!$parentNode instanceof Node) {
|
||||
$nextNode = $this->resolveNextNodeFromFile($newStmts, $node);
|
||||
} elseif ($node instanceof Stmt) {
|
||||
if (!$parentNode instanceof StmtsAwareInterface) {
|
||||
if (!$this->isAllowedParentNode($parentNode)) {
|
||||
return null;
|
||||
}
|
||||
$currentStmtKey = $node->getAttribute(AttributeKey::STMT_KEY);
|
||||
/** @var StmtsAwareInterface|ClassLike|Declare_ $parentNode */
|
||||
$nextNode = $this->resolveNeighborNextStmt($parentNode, $node, $currentStmtKey);
|
||||
} else {
|
||||
$nextNode = $this->resolveNextNodeFromOtherNode($node);
|
||||
|
@ -540,8 +549,9 @@ final class BetterNodeFinder
|
|||
}
|
||||
/**
|
||||
* @param callable(Node $node): bool $filter
|
||||
* @param \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface|\PhpParser\Node\Stmt\ClassLike|\PhpParser\Node\Stmt\Declare_ $stmtsAware
|
||||
*/
|
||||
private function findFirstInTopLevelStmtsAware(StmtsAwareInterface $stmtsAware, callable $filter) : ?Node
|
||||
private function findFirstInTopLevelStmtsAware($stmtsAware, callable $filter) : ?Node
|
||||
{
|
||||
$nodes = [];
|
||||
if ($stmtsAware instanceof Foreach_) {
|
||||
|
@ -623,15 +633,16 @@ final class BetterNodeFinder
|
|||
if ($startTokenPos < 0) {
|
||||
return null;
|
||||
}
|
||||
$nodes = $this->find($currentStmt, static function (Node $subNode) use($startTokenPos) : bool {
|
||||
$nodes = $node instanceof Stmt ? [] : $this->find($currentStmt, static function (Node $subNode) use($startTokenPos) : bool {
|
||||
return $subNode->getEndTokenPos() < $startTokenPos;
|
||||
});
|
||||
if ($nodes === []) {
|
||||
$parentNode = $currentStmt->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$parentNode instanceof StmtsAwareInterface) {
|
||||
if (!$this->isAllowedParentNode($parentNode)) {
|
||||
return null;
|
||||
}
|
||||
$currentStmtKey = $currentStmt->getAttribute(AttributeKey::STMT_KEY);
|
||||
/** @var StmtsAwareInterface|ClassLike|Declare_ $parentNode */
|
||||
return $parentNode->stmts[$currentStmtKey - 1] ?? null;
|
||||
}
|
||||
return \end($nodes);
|
||||
|
@ -651,15 +662,16 @@ final class BetterNodeFinder
|
|||
if ($endTokenPos < 0) {
|
||||
return null;
|
||||
}
|
||||
$nextNode = $this->findFirst($currentStmt, static function (Node $subNode) use($endTokenPos) : bool {
|
||||
$nextNode = $node instanceof Stmt ? null : $this->findFirst($currentStmt, static function (Node $subNode) use($endTokenPos) : bool {
|
||||
return $subNode->getStartTokenPos() > $endTokenPos;
|
||||
});
|
||||
if (!$nextNode instanceof Node) {
|
||||
$parentNode = $currentStmt->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$parentNode instanceof StmtsAwareInterface) {
|
||||
if (!$this->isAllowedParentNode($parentNode)) {
|
||||
return null;
|
||||
}
|
||||
$currentStmtKey = $currentStmt->getAttribute(AttributeKey::STMT_KEY);
|
||||
/** @var StmtsAwareInterface|ClassLike|Declare_ $parentNode */
|
||||
return $this->resolveNeighborNextStmt($parentNode, $currentStmt, $currentStmtKey);
|
||||
}
|
||||
return $nextNode;
|
||||
|
@ -675,10 +687,11 @@ final class BetterNodeFinder
|
|||
if (!$parentNode instanceof Node) {
|
||||
$previousNode = $this->resolvePreviousNodeFromFile($newStmts, $node);
|
||||
} elseif ($node instanceof Stmt) {
|
||||
if (!$parentNode instanceof StmtsAwareInterface) {
|
||||
if (!$this->isAllowedParentNode($parentNode)) {
|
||||
return null;
|
||||
}
|
||||
$currentStmtKey = $node->getAttribute(AttributeKey::STMT_KEY);
|
||||
/** @var StmtsAwareInterface|ClassLike|Declare_ $parentNode */
|
||||
if (!isset($parentNode->stmts[$currentStmtKey - 1])) {
|
||||
return $this->findFirstInTopLevelStmtsAware($parentNode, $filter);
|
||||
}
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInite44a962c84fbcf11b7b8e756d2fada0f::getLoader();
|
||||
return ComposerAutoloaderInit626a9f892288d455ecc1a1e6e9281e36::getLoader();
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInite44a962c84fbcf11b7b8e756d2fada0f
|
||||
class ComposerAutoloaderInit626a9f892288d455ecc1a1e6e9281e36
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInite44a962c84fbcf11b7b8e756d2fada0f
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite44a962c84fbcf11b7b8e756d2fada0f', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit626a9f892288d455ecc1a1e6e9281e36', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite44a962c84fbcf11b7b8e756d2fada0f', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit626a9f892288d455ecc1a1e6e9281e36', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite44a962c84fbcf11b7b8e756d2fada0f::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit626a9f892288d455ecc1a1e6e9281e36::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite44a962c84fbcf11b7b8e756d2fada0f::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit626a9f892288d455ecc1a1e6e9281e36::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite44a962c84fbcf11b7b8e756d2fada0f
|
||||
class ComposerStaticInit626a9f892288d455ecc1a1e6e9281e36
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3115,9 +3115,9 @@ class ComposerStaticInite44a962c84fbcf11b7b8e756d2fada0f
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite44a962c84fbcf11b7b8e756d2fada0f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite44a962c84fbcf11b7b8e756d2fada0f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite44a962c84fbcf11b7b8e756d2fada0f::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit626a9f892288d455ecc1a1e6e9281e36::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit626a9f892288d455ecc1a1e6e9281e36::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit626a9f892288d455ecc1a1e6e9281e36::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user