Updated Rector to commit 1fd156bddbfece24ad48f83e2a65fb44ccb5392d

1fd156bddb Convert DateTimeImmutable to CarbonImmutable (#5895)
This commit is contained in:
Tomas Votruba 2024-05-19 02:09:52 +00:00
parent 3f56884569
commit 4cadabfe9a
2 changed files with 20 additions and 9 deletions

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\Carbon\Rector\New_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall;
@ -51,19 +52,29 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isName($node->class, 'DateTime')) {
return null;
if ($this->isName($node->class, 'DateTime')) {
return $this->refactorWithClass($node, 'Carbon\\Carbon');
}
if ($node->isFirstClassCallable()) {
if ($this->isName($node->class, 'DateTimeImmutable')) {
return $this->refactorWithClass($node, 'Carbon\\CarbonImmutable');
}
return null;
}
/**
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|null
*/
public function refactorWithClass(New_ $new, string $className)
{
if ($new->isFirstClassCallable()) {
return null;
}
// no arg? ::now()
$carbonFullyQualified = new FullyQualified('Carbon\\Carbon');
if ($node->args === []) {
$carbonFullyQualified = new FullyQualified($className);
if ($new->args === []) {
return new StaticCall($carbonFullyQualified, new Identifier('now'));
}
if (\count($node->getArgs()) === 1) {
$firstArg = $node->getArgs()[0];
if (\count($new->getArgs()) === 1) {
$firstArg = $new->getArgs()[0];
if ($firstArg->value instanceof String_) {
return $this->carbonCallFactory->createFromDateTimeString($carbonFullyQualified, $firstArg->value);
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'b2ec1f0b413e16760c41707b74c936f7445e13ab';
public const PACKAGE_VERSION = '1fd156bddbfece24ad48f83e2a65fb44ccb5392d';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-05-18 21:45:11';
public const RELEASE_DATE = '2024-05-19 02:06:27';
/**
* @var int
*/