Skip to content

Commit

Permalink
[Carbon] Skip first class callable on DateFuncCallToCarbonRector (#6776)
Browse files Browse the repository at this point in the history
* [Carbon] Skip first class callable on DateFuncCallToCarbonRector

* [Carbon] Skip first class callable on DateFuncCallToCarbonRector
  • Loading branch information
samsonasik authored Mar 10, 2025
1 parent f6c9982 commit a2b010d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DateWithStrtotimeExample
}
}

?>
-----
<?php

Expand All @@ -22,3 +23,5 @@ class DateWithStrtotimeExample
$formatted = \Carbon\Carbon::parse('2025-02-21')->format('d.m.Y');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SimpleDateExample
}
}

?>
-----
<?php

Expand All @@ -22,3 +23,5 @@ class SimpleDateExample
$date = \Carbon\Carbon::now()->format('Y-m-d');
}
}

?>
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()
{
$twoSecondsAgo = time(...) - 2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class StrtotimeExample
}
}

?>
-----
<?php

Expand All @@ -22,3 +23,5 @@ class StrtotimeExample
$timestamp = \Carbon\Carbon::parse('2025-02-20')->getTimestamp();
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TimeCalculationExample
}
}

?>
-----
<?php

Expand All @@ -30,3 +31,5 @@ class TimeCalculationExample
$twoWeeksAgo = \Carbon\Carbon::now()->subWeeks(2)->getTimestamp();
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function refactor(Node $node): ?Node
{
if ($node instanceof Minus) {
$left = $node->left;
if ($left instanceof FuncCall && $this->isName($left->name, 'time')) {
if ($left instanceof FuncCall && ! $left->isFirstClassCallable() && $this->isName($left->name, 'time')) {
$timeUnit = $this->detectTimeUnit($node->right);
if ($timeUnit !== null) {
return $this->createCarbonSubtract($timeUnit);
Expand Down

0 comments on commit a2b010d

Please sign in to comment.