diff --git a/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php b/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php index ef13ae0aec7..b16c5bb4442 100644 --- a/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php +++ b/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php @@ -4,7 +4,6 @@ declare (strict_types=1); namespace Rector\NodeCollector\NodeAnalyzer; use PhpParser\Node\Arg; -use PhpParser\Node\Attribute; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; @@ -88,8 +87,7 @@ final class ArrayCallableMethodMatcher if (!$callerType instanceof TypeWithClassName) { return null; } - $isInAttribute = (bool) $this->betterNodeFinder->findParentType($array, Attribute::class); - if ($isInAttribute) { + if ($array->getAttribute(AttributeKey::IS_ARRAY_IN_ATTRIBUTE) === \true) { return null; } $values = $this->valueResolver->getValue($array); diff --git a/packages/NodeTypeResolver/Node/AttributeKey.php b/packages/NodeTypeResolver/Node/AttributeKey.php index f5127361f9d..d61fc10ff46 100644 --- a/packages/NodeTypeResolver/Node/AttributeKey.php +++ b/packages/NodeTypeResolver/Node/AttributeKey.php @@ -192,4 +192,8 @@ final class AttributeKey * @var string */ public const IS_UNSET_VAR = 'is_unset_var'; + /** + * @var string + */ + public const IS_ARRAY_IN_ATTRIBUTE = 'is_array_in_attribute'; } diff --git a/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php b/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php index 3099f6753f5..56a7325d3ca 100644 --- a/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php +++ b/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php @@ -4,6 +4,8 @@ declare (strict_types=1); namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor; use PhpParser\Node; +use PhpParser\Node\Attribute; +use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\Break_; @@ -33,15 +35,7 @@ final class ContextNodeVisitor extends NodeVisitorAbstract implements ScopeResol public function enterNode(Node $node) : ?Node { if ($node instanceof For_ || $node instanceof Foreach_ || $node instanceof While_ || $node instanceof Do_) { - $this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->stmts, static function (Node $subNode) : ?int { - if ($subNode instanceof Class_ || $subNode instanceof FunctionLike && !$subNode instanceof ArrowFunction) { - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; - } - if ($subNode instanceof If_ || $subNode instanceof Break_) { - $subNode->setAttribute(AttributeKey::IS_IN_LOOP, \true); - } - return null; - }); + $this->processContextInLoop($node); return null; } if ($node instanceof Unset_) { @@ -49,6 +43,29 @@ final class ContextNodeVisitor extends NodeVisitorAbstract implements ScopeResol $var->setAttribute(AttributeKey::IS_UNSET_VAR, \true); } } + if ($node instanceof Attribute) { + $this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->args, static function (Node $subNode) { + if ($subNode instanceof Array_) { + $subNode->setAttribute(AttributeKey::IS_ARRAY_IN_ATTRIBUTE, \true); + } + return null; + }); + } 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) { + return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + } + if ($subNode instanceof If_ || $subNode instanceof Break_) { + $subNode->setAttribute(AttributeKey::IS_IN_LOOP, \true); + } + return null; + }); + } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 9af295747be..f2c827290f1 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '18436f1f44262a6dcc0dcb6d5bb88eb439a53045'; + public const PACKAGE_VERSION = '6f1b98ef3bf17f9b0d8df592e8605479c628b2c8'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-06-18 17:45:05'; + public const RELEASE_DATE = '2023-06-18 20:11:18'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 8923d27e5ad..cf54025f9b3 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitbb2ba2a619778f3c7e218eb9b59b79e3::getLoader(); +return ComposerAutoloaderInitd8580d9b018097d03475b33f8ce21ff9::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 2610e09bdbb..876a7911f81 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitbb2ba2a619778f3c7e218eb9b59b79e3 +class ComposerAutoloaderInitd8580d9b018097d03475b33f8ce21ff9 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInitbb2ba2a619778f3c7e218eb9b59b79e3 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitbb2ba2a619778f3c7e218eb9b59b79e3', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitd8580d9b018097d03475b33f8ce21ff9', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitbb2ba2a619778f3c7e218eb9b59b79e3', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitd8580d9b018097d03475b33f8ce21ff9', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitbb2ba2a619778f3c7e218eb9b59b79e3::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitd8580d9b018097d03475b33f8ce21ff9::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInitbb2ba2a619778f3c7e218eb9b59b79e3::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInitd8580d9b018097d03475b33f8ce21ff9::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 80830d41bff..2acf4ccc8bd 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitbb2ba2a619778f3c7e218eb9b59b79e3 +class ComposerStaticInitd8580d9b018097d03475b33f8ce21ff9 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3095,9 +3095,9 @@ class ComposerStaticInitbb2ba2a619778f3c7e218eb9b59b79e3 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitbb2ba2a619778f3c7e218eb9b59b79e3::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitbb2ba2a619778f3c7e218eb9b59b79e3::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitbb2ba2a619778f3c7e218eb9b59b79e3::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitd8580d9b018097d03475b33f8ce21ff9::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitd8580d9b018097d03475b33f8ce21ff9::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInitd8580d9b018097d03475b33f8ce21ff9::$classMap; }, null, ClassLoader::class); }