Skip to content
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

Carbon use parse method #6183

Merged
merged 47 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
66b7122
Implement time manipulation on date now
florisbosch Jul 23, 2024
9e8270a
Add link to regex for checks
florisbosch Jul 23, 2024
ad7d644
Use Carbon:parse function to convert datetime to carbon to prevent al…
florisbosch Jul 24, 2024
01ce513
Update code examples
florisbosch Jul 24, 2024
2f12c76
Change tests to check for parse static call
florisbosch Jul 24, 2024
bec8b4a
Add today as method call and fix tests
florisbosch Jul 24, 2024
6d6ee55
Change the tests to parse method
florisbosch Jul 24, 2024
21761fc
Update function return types
florisbosch Jul 24, 2024
1025863
Rewrite Carbon Call Factory to combine regex and fallback to parse
florisbosch Jul 25, 2024
9156f01
Add tests for tomorrow and yesterday
florisbosch Jul 25, 2024
da231c4
Test for fallback to parse
florisbosch Jul 25, 2024
97240df
Fix correct strings utils
florisbosch Jul 25, 2024
bf39bf0
Create const for regex
florisbosch Jul 25, 2024
36042a3
Fallback if unit or operator not set
florisbosch Jul 25, 2024
8b07eeb
Add text for date manipulation
florisbosch Jul 25, 2024
447a355
Remove month test this is combined
florisbosch Jul 25, 2024
5e42997
Change classname
florisbosch Jul 25, 2024
23d15cb
Fix most of possible cases for carbon
florisbosch Jul 30, 2024
15f1a57
Fix some static errors
florisbosch Jul 30, 2024
7f7c356
When set time always add all args
florisbosch Jul 30, 2024
29dedcd
Use correct var for identifier name
florisbosch Jul 30, 2024
f9e753e
Add method call for set date
florisbosch Jul 30, 2024
e01a229
Add some extra tests
florisbosch Jul 30, 2024
54ced4a
Fix tests
florisbosch Jul 30, 2024
835fd30
Correct test with time
florisbosch Jul 30, 2024
89fb135
do correct time checks
florisbosch Jul 30, 2024
1f81529
Make sure property exists
florisbosch Jul 30, 2024
fabef5e
Change checks
florisbosch Jul 30, 2024
1cbd625
Refactor use of reference
florisbosch Jul 30, 2024
299b988
Rebuild the carboncall
florisbosch Jul 30, 2024
45fca3e
Check correct instances
florisbosch Jul 30, 2024
509da98
Check size of callstack
florisbosch Jul 30, 2024
81aefa0
Check correct instance
florisbosch Jul 30, 2024
ddaea41
Add count check
florisbosch Jul 30, 2024
ebc864e
change check for rebuild
florisbosch Jul 30, 2024
c10edeb
Skip checks
florisbosch Jul 30, 2024
46a10f2
Check for empty callstack
florisbosch Jul 30, 2024
b33e107
Move rebuild to separate function
florisbosch Jul 30, 2024
276f2da
Fix time when set to 00:00
florisbosch Jul 30, 2024
75e818b
Add full datetime method
florisbosch Jul 30, 2024
a45ba9d
Add test for full date
florisbosch Jul 30, 2024
7660871
Add change to config
florisbosch Jul 31, 2024
a090a03
remove setDate & setTime functions
florisbosch Jul 31, 2024
976fa1d
Add test for date where no string args
florisbosch Jul 31, 2024
15d4581
Configure rule config for test
florisbosch Jul 31, 2024
63587ac
Revert classname changes
florisbosch Jul 31, 2024
e98b963
Update config/set/datetime-to-carbon.php
florisbosch Jul 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/set/datetime-to-carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Rector\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector;
use Rector\Carbon\Rector\New_\DateTimeInstanceToCarbonRector;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
florisbosch marked this conversation as resolved.
Show resolved Hide resolved

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNowAddSub
{
public function run()
{
$addSeconds = new \DateTime('+5 seconds');
$addMinutes = new \DateTime('+5 minutes');
$addHours = new \DateTime('+5 hours');
$addDays = new \DateTime('+5 days');
$addWeeks = new \DateTime('+5 weeks');
$addMonths = new \DateTime('+5 months');
$addYears = new \DateTime('+5 years');

$subSeconds = new \DateTime('-5 seconds');
$subMinuts = new \DateTime('-5 minutes');
$subHours = new \DateTime('-5 hours');
$subDays = new \DateTime('-5 days');
$subWeeks = new \DateTime('-5 weeks');
$subMonths = new \DateTime('-5 months');
$subYears = new \DateTime('-5 years');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNowAddSub
{
public function run()
{
$addSeconds = \Carbon\Carbon::now()->addSeconds(5);
$addMinutes = \Carbon\Carbon::now()->addMinutes(5);
$addHours = \Carbon\Carbon::now()->addHours(5);
$addDays = \Carbon\Carbon::now()->addDays(5);
$addWeeks = \Carbon\Carbon::now()->addWeeks(5);
$addMonths = \Carbon\Carbon::now()->addMonths(5);
$addYears = \Carbon\Carbon::now()->addYears(5);

$subSeconds = \Carbon\Carbon::now()->subSeconds(5);
$subMinuts = \Carbon\Carbon::now()->subMinutes(5);
$subHours = \Carbon\Carbon::now()->subHours(5);
$subDays = \Carbon\Carbon::now()->subDays(5);
$subWeeks = \Carbon\Carbon::now()->subWeeks(5);
$subMonths = \Carbon\Carbon::now()->subMonths(5);
$subYears = \Carbon\Carbon::now()->subYears(5);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeParse
{
public function run()
{
$date = new \DateTime('next week');
$exactDate = new \DateTime('2024-07-25');
$textualDate = new \DateTime('2 days ago');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeParse
{
public function run()
{
$date = \Carbon\Carbon::parse('next week');
$exactDate = \Carbon\Carbon::parse('2024-07-25');
$textualDate = \Carbon\Carbon::parse('2 days ago');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithMonths
final class DateTimeToday
{
public function run()
{
$date = new \DateTime('+ 2 months');
$date = new \DateTime('today');
}
}

Expand All @@ -16,11 +16,11 @@ final class DateTimeWithMonths

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithMonths
final class DateTimeToday
{
public function run()
{
$date = \Carbon\Carbon::now()->addMonths(2);
$date = \Carbon\Carbon::today();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNow
final class DateTimeTomorrow
{
public function run()
{
$date = new \DateTime('now');
$date = new \DateTime('tomorrow');
}
}

Expand All @@ -16,11 +16,11 @@ final class DateTimeNow

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNow
final class DateTimeTomorrow
{
public function run()
{
$date = \Carbon\Carbon::now();
$date = \Carbon\Carbon::tomorrow();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithDateTime
{
public function run()
{
$date = new \DateTime('2024-07-30');
$time = new \DateTime('11:12:13');
$datetime = new \DateTime('2024-07-30 11:12:13');

$tomorrowTime = new \DateTime('tomorrow 12:00');
$yesterdayTime = new \DateTime('yesterday 12:00');

$dateNoon = new \DateTime('2024-07-30 noon');
$restStringToParse = new \DateTime('tomorrow noon');

$fullDate = new \DateTime('2024-07-30T11:12:13.000Z');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithDateTime
{
public function run()
{
$date = \Carbon\Carbon::parse('2024-07-30');
$time = \Carbon\Carbon::parse('11:12:13');
$datetime = \Carbon\Carbon::parse('2024-07-30 11:12:13');

$tomorrowTime = \Carbon\Carbon::parse('12:00 tomorrow');
$yesterdayTime = \Carbon\Carbon::parse('12:00 yesterday');

$dateNoon = \Carbon\Carbon::parse('2024-07-30 noon');
$restStringToParse = \Carbon\Carbon::parse('noon tomorrow');

$fullDate = \Carbon\Carbon::parse('2024-07-30T11:12:13.000Z');
}
}

?>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeYesterday
{
public function run()
{
$date = new \DateTime('yesterday');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeYesterday
{
public function run()
{
$date = \Carbon\Carbon::yesterday();
}
}

?>
Loading