mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-21 07:52:01 +02:00
Updated Rector to commit f30405751176cf6504a86a8f9e6661c55806b38e
f304057511
Convert time() to Carbon::now()->timestamp (#5901)
This commit is contained in:
parent
fce5bf1293
commit
39908b6b4e
@ -4,9 +4,10 @@ declare (strict_types=1);
|
||||
namespace RectorPrefix202405;
|
||||
|
||||
use Rector\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector;
|
||||
use Rector\Carbon\Rector\FuncCall\TimeFuncCallToCarbonRector;
|
||||
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]);
|
||||
$rectorConfig->rules([DateFuncCallToCarbonRector::class, DateTimeInstanceToCarbonRector::class, DateTimeMethodCallToCarbonRector::class, TimeFuncCallToCarbonRector::class]);
|
||||
};
|
||||
|
@ -20,7 +20,7 @@ final class DateFuncCallToCarbonRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Convert date() function call to Carbon::*()', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition('Convert date() function call to Carbon::now()->format(*)', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
@ -34,7 +34,7 @@ class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$date = \Carbon\Carbon::now()->format('Y-m-d')
|
||||
$date = \Carbon\Carbon::now()->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
|
69
rules/Carbon/Rector/FuncCall/TimeFuncCallToCarbonRector.php
Normal file
69
rules/Carbon/Rector/FuncCall/TimeFuncCallToCarbonRector.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Carbon\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector\DateFuncCallToCarbonRectorTest
|
||||
*/
|
||||
final class TimeFuncCallToCarbonRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Convert time() function call to Carbon::now()->timestamp', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$time = time();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$time = \Carbon\Carbon::now()->timestamp;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [FuncCall::class];
|
||||
}
|
||||
/**
|
||||
* @param FuncCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->isName($node->name, 'time')) {
|
||||
return null;
|
||||
}
|
||||
$firstClassCallable = $node->isFirstClassCallable();
|
||||
if (!$firstClassCallable && \count($node->getArgs()) !== 0) {
|
||||
return null;
|
||||
}
|
||||
// create now and format()
|
||||
$nowStaticCall = new StaticCall(new FullyQualified('Carbon\\Carbon'), 'now');
|
||||
$propertyFetch = new PropertyFetch($nowStaticCall, 'timestamp');
|
||||
if ($firstClassCallable) {
|
||||
return new ArrowFunction(['static' => \true, 'expr' => $propertyFetch]);
|
||||
}
|
||||
return $propertyFetch;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0e5343cb24ce394701c5321eb5976573dd8c0afe';
|
||||
public const PACKAGE_VERSION = 'f30405751176cf6504a86a8f9e6661c55806b38e';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-05-19 17:43:22';
|
||||
public const RELEASE_DATE = '2024-05-20 02:12:01';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1051,6 +1051,7 @@ return array(
|
||||
'Rector\\Caching\\ValueObject\\Storage\\MemoryCacheStorage' => $baseDir . '/src/Caching/ValueObject/Storage/MemoryCacheStorage.php',
|
||||
'Rector\\Carbon\\NodeFactory\\CarbonCallFactory' => $baseDir . '/rules/Carbon/NodeFactory/CarbonCallFactory.php',
|
||||
'Rector\\Carbon\\Rector\\FuncCall\\DateFuncCallToCarbonRector' => $baseDir . '/rules/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector.php',
|
||||
'Rector\\Carbon\\Rector\\FuncCall\\TimeFuncCallToCarbonRector' => $baseDir . '/rules/Carbon/Rector/FuncCall/TimeFuncCallToCarbonRector.php',
|
||||
'Rector\\Carbon\\Rector\\MethodCall\\DateTimeMethodCallToCarbonRector' => $baseDir . '/rules/Carbon/Rector/MethodCall/DateTimeMethodCallToCarbonRector.php',
|
||||
'Rector\\Carbon\\Rector\\New_\\DateTimeInstanceToCarbonRector' => $baseDir . '/rules/Carbon/Rector/New_/DateTimeInstanceToCarbonRector.php',
|
||||
'Rector\\ChangesReporting\\Annotation\\AnnotationExtractor' => $baseDir . '/src/ChangesReporting/Annotation/AnnotationExtractor.php',
|
||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -1270,6 +1270,7 @@ class ComposerStaticInit8f3085135f9c0dec79e149b0c0400440
|
||||
'Rector\\Caching\\ValueObject\\Storage\\MemoryCacheStorage' => __DIR__ . '/../..' . '/src/Caching/ValueObject/Storage/MemoryCacheStorage.php',
|
||||
'Rector\\Carbon\\NodeFactory\\CarbonCallFactory' => __DIR__ . '/../..' . '/rules/Carbon/NodeFactory/CarbonCallFactory.php',
|
||||
'Rector\\Carbon\\Rector\\FuncCall\\DateFuncCallToCarbonRector' => __DIR__ . '/../..' . '/rules/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector.php',
|
||||
'Rector\\Carbon\\Rector\\FuncCall\\TimeFuncCallToCarbonRector' => __DIR__ . '/../..' . '/rules/Carbon/Rector/FuncCall/TimeFuncCallToCarbonRector.php',
|
||||
'Rector\\Carbon\\Rector\\MethodCall\\DateTimeMethodCallToCarbonRector' => __DIR__ . '/../..' . '/rules/Carbon/Rector/MethodCall/DateTimeMethodCallToCarbonRector.php',
|
||||
'Rector\\Carbon\\Rector\\New_\\DateTimeInstanceToCarbonRector' => __DIR__ . '/../..' . '/rules/Carbon/Rector/New_/DateTimeInstanceToCarbonRector.php',
|
||||
'Rector\\ChangesReporting\\Annotation\\AnnotationExtractor' => __DIR__ . '/../..' . '/src/ChangesReporting/Annotation/AnnotationExtractor.php',
|
||||
|
Loading…
x
Reference in New Issue
Block a user