From 30da34e6d3e480f5dca1fc5a030f50cb18003463 Mon Sep 17 00:00:00 2001 From: Carlos Granados Date: Thu, 20 Mar 2025 21:38:13 +0100 Subject: [PATCH] Fix MultiDirnameRector --- .../Fixture/fixture.php.inc | 20 ----------------- .../MultiDirnameRector/Fixture/skip.php.inc | 22 +++++++++++++++++++ .../Rector/FuncCall/MultiDirnameRector.php | 4 +++- 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/skip.php.inc diff --git a/rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/fixture.php.inc b/rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/fixture.php.inc index cd65e502deb..3799a0aa042 100644 --- a/rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/fixture.php.inc +++ b/rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/fixture.php.inc @@ -7,16 +7,6 @@ function multiDirname() dirname(dirname($path)); new dirname(dirname(dirname($path))); - - -// untouched - dirname(dirname($path, $level)); - - dirname("foo/" . dirname($path)); - - dirname(dirname($path) . $foo); - - foo\dirname(dirname($path)); } ?> @@ -30,16 +20,6 @@ function multiDirname() dirname($path, 2); new dirname(dirname($path, 2)); - - -// untouched - dirname(dirname($path, $level)); - - dirname("foo/" . dirname($path)); - - dirname(dirname($path) . $foo); - - foo\dirname(dirname($path)); } ?> diff --git a/rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/skip.php.inc b/rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/skip.php.inc new file mode 100644 index 00000000000..57d0da0c4d3 --- /dev/null +++ b/rules-tests/Php70/Rector/FuncCall/MultiDirnameRector/Fixture/skip.php.inc @@ -0,0 +1,22 @@ + diff --git a/rules/Php70/Rector/FuncCall/MultiDirnameRector.php b/rules/Php70/Rector/FuncCall/MultiDirnameRector.php index aa53225bbb9..49a2f37a9b1 100644 --- a/rules/Php70/Rector/FuncCall/MultiDirnameRector.php +++ b/rules/Php70/Rector/FuncCall/MultiDirnameRector.php @@ -56,12 +56,14 @@ public function refactor(Node $node): ?Node $activeFuncCallNode = $node; $lastFuncCallNode = $node; + $shouldUpdate = false; while (($activeFuncCallNode = $this->matchNestedDirnameFuncCall($activeFuncCallNode)) instanceof FuncCall) { $lastFuncCallNode = $activeFuncCallNode; + $shouldUpdate = true; } // nothing to improve - if ($this->shouldSkip()) { + if (! $shouldUpdate || $this->shouldSkip()) { return null; }