From fb76f96f22aae6a5efa1b48353b116125e9c78e5 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 5 Oct 2025 15:26:29 +0200 Subject: [PATCH] allow empty in StrictArrayParamDimFetchRector to make rule more practical --- .../Fixture/empty_index.php.inc | 35 +++++++++++++++++++ .../Fixture/skip_empty_index.php.inc | 11 ------ .../StrictArrayParamDimFetchRector.php | 12 ++----- 3 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/empty_index.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_empty_index.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/empty_index.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/empty_index.php.inc new file mode 100644 index 00000000000..95a6ca143ac --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/empty_index.php.inc @@ -0,0 +1,35 @@ + +----- + diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_empty_index.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_empty_index.php.inc deleted file mode 100644 index fbfc2b5405e..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_empty_index.php.inc +++ /dev/null @@ -1,11 +0,0 @@ -traverseNodesWithCallable($functionLike->stmts, function (Node $node) use ( - $param, $paramName, &$isParamAccessedArrayDimFetch, ): int|null { @@ -140,7 +139,7 @@ private function isParamAccessedArrayDimFetch(Param $param, ClassMethod|Function return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } - if ($this->shouldStop($node, $param, $paramName)) { + if ($this->shouldStop($node, $paramName)) { // force set to false to avoid too early replaced $isParamAccessedArrayDimFetch = false; return NodeVisitor::STOP_TRAVERSAL; @@ -209,16 +208,11 @@ private function isEchoed(Node $node, string $paramName): bool return false; } - private function shouldStop(Node $node, Param $param, string $paramName): bool + private function shouldStop(Node $node, string $paramName): bool { $nodeToCheck = null; - if (! $param->default instanceof Expr && ($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() + 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;