-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Carbon] Init set to migrate DateTime to Carbon (#5868)
* [Carbon] Init * add fixture * add day count suport * add months * add DateTimeMethodCallToCarbonRector
- Loading branch information
1 parent
5df95d9
commit 575921d
Showing
21 changed files
with
726 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector; | ||
use Rector\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector; | ||
use Rector\Carbon\Rector\New_\DateTimeInstanceToCarbonRector; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
DateFuncCallToCarbonRector::class, | ||
DateTimeInstanceToCarbonRector::class, | ||
DateTimeMethodCallToCarbonRector::class, | ||
]); | ||
}; |
28 changes: 28 additions & 0 deletions
28
...ests/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector/DateFuncCallToCarbonRectorTest.php
This file contains 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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DateFuncCallToCarbonRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
rules-tests/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector/Fixture/some_class.php.inc
This file contains 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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function run() | ||
{ | ||
$date = date('Y-m-d'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::now()->format('Y-m-d'); | ||
} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
rules-tests/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector/config/configured_rule.php
This file contains 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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(DateFuncCallToCarbonRector::class); | ||
}; |
28 changes: 28 additions & 0 deletions
28
...ctor/MethodCall/DateTimeMethodCallToCarbonRector/DateTimeMethodCallToCarbonRectorTest.php
This file contains 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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DateTimeMethodCallToCarbonRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ests/Carbon/Rector/MethodCall/DateTimeMethodCallToCarbonRector/Fixture/some_class.php.inc
This file contains 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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function run() | ||
{ | ||
$date = (new \DateTime('today +20 day'))->format('Y-m-d'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function run() | ||
{ | ||
$date = (\Carbon\Carbon::today()->addDays(20))->format('Y-m-d'); | ||
} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...ests/Carbon/Rector/MethodCall/DateTimeMethodCallToCarbonRector/config/configured_rule.php
This file contains 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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Carbon\Rector\MethodCall\DateTimeMethodCallToCarbonRector; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(DateTimeMethodCallToCarbonRector::class); | ||
}; |
28 changes: 28 additions & 0 deletions
28
.../Carbon/Rector/New_/DateTimeInstanceToCarbonRector/DateTimeInstanceToCarbonRectorTest.php
This file contains 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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DateTimeInstanceToCarbonRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
rules-tests/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_now.php.inc
This file contains 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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeNow | ||
{ | ||
public function run() | ||
{ | ||
$date = new \DateTime('now'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeNow | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::now(); | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
rules-tests/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_today.php.inc
This file contains 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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeWithMonths | ||
{ | ||
public function run() | ||
{ | ||
$date = new \DateTime('+ 2 months'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeWithMonths | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::now()->addMonths(2); | ||
} | ||
} | ||
|
||
?> |
35 changes: 35 additions & 0 deletions
35
...bon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_today_with_5_days.php.inc
This file contains 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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeTodayWith5Days | ||
{ | ||
public function run() | ||
{ | ||
$date = new \DateTime('today + 5 day'); | ||
|
||
$middleDate = new \DateTime('today +7day'); | ||
|
||
$nextDate = new \DateTime('today +10 days'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeTodayWith5Days | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::today()->addDays(5); | ||
|
||
$middleDate = \Carbon\Carbon::today()->addDays(7); | ||
|
||
$nextDate = \Carbon\Carbon::today()->addDays(10); | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...ts/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_with_months.php.inc
This file contains 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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeNow | ||
{ | ||
public function run() | ||
{ | ||
$date = new \DateTime('now'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeNow | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::now(); | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.