From 40b38aeb8891b7439ef8563e8e530584303a098b Mon Sep 17 00:00:00 2001 From: geni_jaho Date: Sun, 11 Aug 2024 23:24:04 +0200 Subject: [PATCH] Handle Carbon setTestNow with no arguments --- .../CarbonSetTestNowToTravelToRector.php | 11 ++++++- .../Fixture/with_no_arguments.php.inc | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/Rector/StaticCall/CarbonSetTestNowToTravelToRector/Fixture/with_no_arguments.php.inc diff --git a/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php b/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php index 2284c165..02fd6a46 100644 --- a/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php +++ b/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php @@ -3,6 +3,7 @@ namespace RectorLaravel\Rector\StaticCall; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; @@ -87,7 +88,15 @@ public function refactorWithScope(Node $node, Scope $scope): ?MethodCall return null; } - return $this->nodeFactory->createMethodCall(new Variable('this'), 'travelTo', $node->args); + $args = $node->args === [] + ? [new Arg($this->nodeFactory->createNull())] + : $node->args; + + return $this->nodeFactory->createMethodCall( + new Variable('this'), + 'travelTo', + $args, + ); } private function isCarbon(Node $node): bool diff --git a/tests/Rector/StaticCall/CarbonSetTestNowToTravelToRector/Fixture/with_no_arguments.php.inc b/tests/Rector/StaticCall/CarbonSetTestNowToTravelToRector/Fixture/with_no_arguments.php.inc new file mode 100644 index 00000000..66936bd7 --- /dev/null +++ b/tests/Rector/StaticCall/CarbonSetTestNowToTravelToRector/Fixture/with_no_arguments.php.inc @@ -0,0 +1,33 @@ + +----- +travelTo(null); + } +} + +?>