Skip to content

Commit

Permalink
Updated Rector to commit ffce073ffa08eddc334b866ae3bec92afab15e0a
Browse files Browse the repository at this point in the history
rectorphp/rector-src@ffce073 [NodeNestingScope] Remove parent lookup on ContextAnalyzer (#4315)
  • Loading branch information
TomasVotruba committed Jun 22, 2023
1 parent 7378068 commit 53262b6
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 56 deletions.
23 changes: 2 additions & 21 deletions packages/NodeNestingScope/ContextAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,12 @@
namespace Rector\NodeNestingScope;

use PhpParser\Node;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\If_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class ContextAnalyzer
{
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* Nodes that break the scope they way up, e.g. class method
* @var array<class-string<FunctionLike>>
* @api
*/
private const BREAK_NODES = [FunctionLike::class, ClassMethod::class];
public function __construct(BetterNodeFinder $betterNodeFinder)
{
$this->betterNodeFinder = $betterNodeFinder;
}
public function isInLoop(Node $node) : bool
{
return $node->getAttribute(AttributeKey::IS_IN_LOOP) === \true;
Expand All @@ -34,10 +19,6 @@ public function isInLoop(Node $node) : bool
*/
public function isInIf(Node $node) : bool
{
$previousNode = $this->betterNodeFinder->findParentByTypes($node, \array_merge([If_::class], self::BREAK_NODES));
if (!$previousNode instanceof Node) {
return \false;
}
return $previousNode instanceof If_;
return $node->getAttribute(AttributeKey::IS_IN_IF) === \true;
}
}
4 changes: 4 additions & 0 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ final class AttributeKey
* @var string
*/
public const IS_IN_LOOP = 'is_in_loop';
/**
* @var string
*/
public const IS_IN_IF = 'is_in_if';
/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
use PhpParser\Node;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Isset_;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Do_;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\ElseIf_;
use PhpParser\Node\Stmt\For_;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Unset_;
use PhpParser\Node\Stmt\While_;
Expand All @@ -39,15 +41,9 @@ public function enterNode(Node $node) : ?Node
$this->processContextInLoop($node);
return null;
}
if ($node instanceof Isset_) {
foreach ($node->vars as $var) {
$var->setAttribute(AttributeKey::IS_ISSET_VAR, \true);
}
}
if ($node instanceof Unset_) {
foreach ($node->vars as $var) {
$var->setAttribute(AttributeKey::IS_UNSET_VAR, \true);
}
if ($node instanceof Isset_ || $node instanceof Unset_) {
$this->processContextInIssetOrUnset($node);
return null;
}
if ($node instanceof Attribute) {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->args, static function (Node $subNode) {
Expand All @@ -57,15 +53,49 @@ public function enterNode(Node $node) : ?Node
return null;
});
}
if ($node instanceof If_ || $node instanceof Else_ || $node instanceof ElseIf_) {
$this->processContextInIf($node);
return null;
}
return null;
}
/**
* @param \PhpParser\Node\Expr\Isset_|\PhpParser\Node\Stmt\Unset_ $node
*/
private function processContextInIssetOrUnset($node) : void
{
if ($node instanceof Isset_) {
foreach ($node->vars as $var) {
$var->setAttribute(AttributeKey::IS_ISSET_VAR, \true);
}
return;
}
foreach ($node->vars as $var) {
$var->setAttribute(AttributeKey::IS_UNSET_VAR, \true);
}
}
/**
* @param \PhpParser\Node\Stmt\If_|\PhpParser\Node\Stmt\Else_|\PhpParser\Node\Stmt\ElseIf_ $node
*/
private function processContextInIf($node) : void
{
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->stmts, static function (Node $subNode) : ?int {
if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
if ($subNode instanceof Break_) {
$subNode->setAttribute(AttributeKey::IS_IN_IF, \true);
}
return null;
});
}
/**
* @param \PhpParser\Node\Stmt\For_|\PhpParser\Node\Stmt\Foreach_|\PhpParser\Node\Stmt\While_|\PhpParser\Node\Stmt\Do_ $node
*/
private function processContextInLoop($node) : void
{
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->stmts, static function (Node $subNode) : ?int {
if ($subNode instanceof Class_ || $subNode instanceof FunctionLike && !$subNode instanceof ArrowFunction) {
if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
if ($subNode instanceof If_ || $subNode instanceof Break_) {
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '5438c558066953abc6d800e94e7ffbff4215acff';
public const PACKAGE_VERSION = 'ffce073ffa08eddc334b866ae3bec92afab15e0a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-22 16:58:02';
public const RELEASE_DATE = '2023-06-22 18:47:36';
/**
* @var int
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit6d50cdc059557f8a24cbde7c2346ef1c::getLoader();
return ComposerAutoloaderInit44f92a6493fd51f9fba4b92e065bd234::getLoader();
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit6d50cdc059557f8a24cbde7c2346ef1c
class ComposerAutoloaderInit44f92a6493fd51f9fba4b92e065bd234
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit6d50cdc059557f8a24cbde7c2346ef1c', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit44f92a6493fd51f9fba4b92e065bd234', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit6d50cdc059557f8a24cbde7c2346ef1c', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit44f92a6493fd51f9fba4b92e065bd234', 'loadClassLoader'));

require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6d50cdc059557f8a24cbde7c2346ef1c::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit44f92a6493fd51f9fba4b92e065bd234::getInitializer($loader));

$loader->setClassMapAuthoritative(true);
$loader->register(true);

$filesToLoad = \Composer\Autoload\ComposerStaticInit6d50cdc059557f8a24cbde7c2346ef1c::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit44f92a6493fd51f9fba4b92e065bd234::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit6d50cdc059557f8a24cbde7c2346ef1c
class ComposerStaticInit44f92a6493fd51f9fba4b92e065bd234
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -3097,9 +3097,9 @@ class ComposerStaticInit6d50cdc059557f8a24cbde7c2346ef1c
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6d50cdc059557f8a24cbde7c2346ef1c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6d50cdc059557f8a24cbde7c2346ef1c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6d50cdc059557f8a24cbde7c2346ef1c::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit44f92a6493fd51f9fba4b92e065bd234::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit44f92a6493fd51f9fba4b92e065bd234::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit44f92a6493fd51f9fba4b92e065bd234::$classMap;

}, null, ClassLoader::class);
}
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -2049,12 +2049,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "8288f71f10328024e9565abf053cc879a538a22a"
"reference": "6ed90ade37006c36806a4c3e3593f5d7beeab687"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/8288f71f10328024e9565abf053cc879a538a22a",
"reference": "8288f71f10328024e9565abf053cc879a538a22a",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/6ed90ade37006c36806a4c3e3593f5d7beeab687",
"reference": "6ed90ade37006c36806a4c3e3593f5d7beeab687",
"shasum": ""
},
"require": {
Expand Down Expand Up @@ -2083,7 +2083,7 @@
"tomasvotruba\/type-coverage": "^0.1",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-06-20T08:00:14+00:00",
"time": "2023-06-22T11:40:36+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
Loading

0 comments on commit 53262b6

Please sign in to comment.