From 267b6cc081d4fa3123ed7a4407c3e48188dd9b35 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 12 Aug 2024 15:02:53 +0000 Subject: [PATCH] Updated Rector to commit 24fb5874905da56065ef38d9cfe9bff77cb04cac https://github.com/rectorphp/rector-src/commit/24fb5874905da56065ef38d9cfe9bff77cb04cac [TypeDeclaration] Skip isset and empty with index on param variable on StrictArrayParamDimFetchRector (#6227) --- .../StrictArrayParamDimFetchRector.php | 19 ++++++++++++++++--- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php b/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php index d96939c6e37..170d94e7dad 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php @@ -14,6 +14,7 @@ use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Empty_; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Expr\Isset_; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\FunctionLike; @@ -112,11 +113,11 @@ private function isParamAccessedArrayDimFetch(Param $param, $functionLike) : boo } $paramName = $this->getName($param); $isParamAccessedArrayDimFetch = \false; - $this->traverseNodesWithCallable($functionLike->stmts, function (Node $node) use($paramName, &$isParamAccessedArrayDimFetch) : ?int { + $this->traverseNodesWithCallable($functionLike->stmts, function (Node $node) use($param, $paramName, &$isParamAccessedArrayDimFetch) : ?int { if ($node instanceof Class_ || $node instanceof FunctionLike) { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } - if ($this->shouldStop($node, $paramName)) { + if ($this->shouldStop($node, $param, $paramName)) { // force set to false to avoid too early replaced $isParamAccessedArrayDimFetch = \false; return NodeTraverser::STOP_TRAVERSAL; @@ -162,9 +163,21 @@ private function isEchoed(Node $node, string $paramName) : bool } return \false; } - private function shouldStop(Node $node, string $paramName) : bool + private function shouldStop(Node $node, Param $param, string $paramName) : bool { $nodeToCheck = null; + if (!$param->default instanceof Expr) { + if ($node instanceof Isset_) { + foreach ($node->vars as $var) { + if ($var instanceof ArrayDimFetch && $var->var instanceof Variable && $var->var->name === $paramName) { + return \true; + } + } + } + if ($node instanceof Empty_ && $node->expr instanceof ArrayDimFetch && $node->expr->var instanceof Variable && $node->expr->var->name === $paramName) { + return \true; + } + } if ($node instanceof FuncCall && !$node->isFirstClassCallable() && $this->isNames($node, ['is_array', 'is_string', 'is_int', 'is_bool', 'is_float'])) { $firstArg = $node->getArgs()[0]; $nodeToCheck = $firstArg->value; diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 16b32a5ac50..258eea8553c 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 = '67238d841a46b5fecc9ef204ffef4ba773e82cb9'; + public const PACKAGE_VERSION = '24fb5874905da56065ef38d9cfe9bff77cb04cac'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-08-08 13:51:11'; + public const RELEASE_DATE = '2024-08-12 22:00:07'; /** * @var int */