From 687c0f4252e231b6a7ef877f660f08d81a2d0408 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 3 Oct 2025 12:02:35 +0200 Subject: [PATCH] allow coalesce not on full variable, but dim fetch in StrictArrayParamDimFetchRector --- .../Fixture/direct-coalesce.php.inc | 27 +++++++++++++++++++ ...> skip_coalesce_without_dim_fetch.php.inc} | 2 +- .../StrictArrayParamDimFetchRector.php | 8 ++---- 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/direct-coalesce.php.inc rename rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/{skip_coalesce.php.inc => skip_coalesce_without_dim_fetch.php.inc} (87%) diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/direct-coalesce.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/direct-coalesce.php.inc new file mode 100644 index 00000000000..e2c3d7b3b08 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/direct-coalesce.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_coalesce.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_coalesce_without_dim_fetch.php.inc similarity index 87% rename from rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_coalesce.php.inc rename to rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_coalesce_without_dim_fetch.php.inc index d20e3653beb..05e8f27e94c 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_coalesce.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector/Fixture/skip_coalesce_without_dim_fetch.php.inc @@ -2,7 +2,7 @@ namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture; -final class SkipCoalesce +final class SkipCoalesceWithoutDimFetch { public function run($productOptions) { diff --git a/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php b/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php index 834254697d9..61dfdf1de41 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php @@ -236,7 +236,7 @@ private function shouldStop(Node $node, Param $param, string $paramName): bool $nodeToCheck = $node->var; } - if ($this->isMethodCallOrArrayDimFetch($paramName, $nodeToCheck)) { + if ($this->isMethodCall($paramName, $nodeToCheck)) { return true; } @@ -295,16 +295,12 @@ private function isEmptyOrEchoedOrCasted(Node $node, string $paramName): bool return $node instanceof Array_ && $node->expr instanceof Variable && $this->isName($node->expr, $paramName); } - private function isMethodCallOrArrayDimFetch(string $paramName, ?Node $node): bool + private function isMethodCall(string $paramName, ?Node $node): bool { if ($node instanceof MethodCall) { return $node->var instanceof Variable && $this->isName($node->var, $paramName); } - if ($node instanceof ArrayDimFetch) { - return $node->var instanceof Variable && $this->isName($node->var, $paramName); - } - return false; }