diff --git a/config/set/php/php53.yaml b/config/set/php/php53.yaml index a57e8942902f..07622db69fdf 100644 --- a/config/set/php/php53.yaml +++ b/config/set/php/php53.yaml @@ -1,2 +1,3 @@ services: Rector\Php53\Rector\Ternary\TernaryToElvisRector: ~ + Rector\Php53\Rector\FuncCall\DirNameFileConstantToDirConstantRector: ~ diff --git a/packages/Php53/src/Rector/FuncCall/DirNameFileConstantToDirConstantRector.php b/packages/Php53/src/Rector/FuncCall/DirNameFileConstantToDirConstantRector.php new file mode 100644 index 000000000000..30a68f558df5 --- /dev/null +++ b/packages/Php53/src/Rector/FuncCall/DirNameFileConstantToDirConstantRector.php @@ -0,0 +1,71 @@ +isName($node, 'dirname')) { + return null; + } + + if (count($node->args) !== 1) { + return null; + } + + $firstArgValue = $node->args[0]->value; + if (! $firstArgValue instanceof Node\Scalar\MagicConst\File) { + return null; + } + + return new Node\Scalar\MagicConst\Dir(); + } +} diff --git a/packages/Php53/tests/Rector/FuncCall/DirNameFileConstantToDirConstantRector/DirNameFileConstantToDirConstantRectorTest.php b/packages/Php53/tests/Rector/FuncCall/DirNameFileConstantToDirConstantRector/DirNameFileConstantToDirConstantRectorTest.php new file mode 100644 index 000000000000..964a313848c2 --- /dev/null +++ b/packages/Php53/tests/Rector/FuncCall/DirNameFileConstantToDirConstantRector/DirNameFileConstantToDirConstantRectorTest.php @@ -0,0 +1,30 @@ +doTestFile($file); + } + + /** + * @return string[] + */ + public function provideDataForTest(): iterable + { + yield [__DIR__ . '/Fixture/fixture.php.inc']; + } + + protected function getRectorClass(): string + { + return DirNameFileConstantToDirConstantRector::class; + } +} diff --git a/packages/Php53/tests/Rector/FuncCall/DirNameFileConstantToDirConstantRector/Fixture/fixture.php.inc b/packages/Php53/tests/Rector/FuncCall/DirNameFileConstantToDirConstantRector/Fixture/fixture.php.inc new file mode 100644 index 000000000000..1e6a47e47c29 --- /dev/null +++ b/packages/Php53/tests/Rector/FuncCall/DirNameFileConstantToDirConstantRector/Fixture/fixture.php.inc @@ -0,0 +1,27 @@ + +----- +