-
-
Notifications
You must be signed in to change notification settings - Fork 431
[Rector Rule] Replace date, strtotime, and time calls with Carbon equivalents
#6749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
samsonasik
merged 12 commits into
rectorphp:main
from
gollumeo:feat/replace-strtotime-with-carbon
Mar 4, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8997961
feat(carbon): replace strtotime() with Carbon::parse()->timestamp
gollumeo 88dbf4b
style(carbon): use import qualifier instead of calling the whole name…
gollumeo 1ddf249
feat(carbon): transform date/time usage into Carbon calls
gollumeo e73d30d
style: fix coding standards
gollumeo 571f837
Merge branch 'rectorphp:main' into feat/replace-strtotime-with-carbon
gollumeo 45ee380
fix(carbon): fix return type of `calculateProduct` to `float|int|null`
gollumeo c2f510b
Merge branch 'feat/replace-strtotime-with-carbon' of https://github.c…
gollumeo d8e0388
Merge branch 'rectorphp:main' into feat/replace-strtotime-with-carbon
gollumeo a4b6f65
Merge branch 'rectorphp:main' into feat/replace-strtotime-with-carbon
gollumeo 0d245a0
fix(carbon): ensure first-class callable check is done before accessi…
gollumeo 65e3d56
Merge branch 'rectorphp:main' into feat/replace-strtotime-with-carbon
gollumeo cc0396b
refactor(carbon): replace direct timestamp access with getTimestamp()…
gollumeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...sts/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector/Fixture/date_with_strtotime.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class DateWithStrtotimeExample | ||
| { | ||
| public function run() | ||
| { | ||
| $formatted = date('d.m.Y', strtotime('2025-02-21')); | ||
| } | ||
| } | ||
|
|
||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class DateWithStrtotimeExample | ||
| { | ||
| public function run() | ||
| { | ||
| $formatted = \Carbon\Carbon::parse('2025-02-21')->format('d.m.Y'); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
rules-tests/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector/Fixture/simple_date.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class SimpleDateExample | ||
| { | ||
| public function run() | ||
| { | ||
| $date = date('Y-m-d'); | ||
| } | ||
| } | ||
|
|
||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class SimpleDateExample | ||
| { | ||
| public function run() | ||
| { | ||
| $date = \Carbon\Carbon::now()->format('Y-m-d'); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
rules-tests/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector/Fixture/strtotime.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class StrtotimeExample | ||
| { | ||
| public function run() | ||
| { | ||
| $timestamp = strtotime('2025-02-20'); | ||
| } | ||
| } | ||
|
|
||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class StrtotimeExample | ||
| { | ||
| public function run() | ||
| { | ||
| $timestamp = \Carbon\Carbon::parse('2025-02-20')->getTimestamp(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...-tests/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector/Fixture/time_calculation.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class TimeCalculationExample | ||
| { | ||
| public function run() | ||
| { | ||
| $twoSecondsAgo = time() - 2; | ||
| $twoMinutesAgo = time() - (60 * 2); | ||
| $twoHoursAgo = time() - (60 * 60 * 2); | ||
| $twoDaysAgo = time() - (60 * 60 * 24 * 2); | ||
| $twoWeeksAgo = time() - (60 * 60 * 24 * 14); | ||
| } | ||
| } | ||
|
|
||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
|
||
| class TimeCalculationExample | ||
| { | ||
| public function run() | ||
| { | ||
| $twoSecondsAgo = \Carbon\Carbon::now()->subSeconds(2)->getTimestamp(); | ||
| $twoMinutesAgo = \Carbon\Carbon::now()->subMinutes(2)->getTimestamp(); | ||
| $twoHoursAgo = \Carbon\Carbon::now()->subHours(2)->getTimestamp(); | ||
| $twoDaysAgo = \Carbon\Carbon::now()->subDays(2)->getTimestamp(); | ||
| $twoWeeksAgo = \Carbon\Carbon::now()->subWeeks(2)->getTimestamp(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.