Skip to content

Commit

Permalink
Handle Carbon setTestNow with no arguments (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho authored Aug 11, 2024
1 parent 8d39c5b commit d57fa8b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace RectorLaravel\Tests\Rector\StaticCall\CarbonSetTestNowToTravelToRector\Fixture;

use Illuminate\Foundation\Testing\TestCase;
use Carbon\Carbon;

class SomeTest extends TestCase
{
public function test()
{
Carbon::setTestNow();
}
}

?>
-----
<?php

namespace RectorLaravel\Tests\Rector\StaticCall\CarbonSetTestNowToTravelToRector\Fixture;

use Illuminate\Foundation\Testing\TestCase;
use Carbon\Carbon;

class SomeTest extends TestCase
{
public function test()
{
$this->travelTo(null);
}
}

?>

0 comments on commit d57fa8b

Please sign in to comment.