Skip to content

Commit

Permalink
[Carbon] Skip first class callable on DateTimeMethodCallToCarbonRector (
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 18, 2024
1 parent 6ebfa15 commit b2ec1f0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture;

class SkipFirstClassCallable
{
public function run()
{
$date = date(...);
}
}
4 changes: 4 additions & 0 deletions rules/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (count($node->getArgs()) !== 1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($new->isFirstClassCallable()) {
return null;
}

if (count($new->getArgs()) !== 1) {
// @todo handle in separate static call
return null;
Expand Down
4 changes: 4 additions & 0 deletions rules/Carbon/Rector/New_/DateTimeInstanceToCarbonRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

// no arg? ::now()
$carbonFullyQualified = new FullyQualified('Carbon\Carbon');
if ($node->args === []) {
Expand Down

0 comments on commit b2ec1f0

Please sign in to comment.