mirror of
https://github.com/rectorphp/rector.git
synced 2024-09-06 15:41:59 +00:00
[Laravel] Fix MinutesToSecondsInCacheRector DateTimeInterface argument
This commit is contained in:
parent
83087684e1
commit
92bed77b05
@ -9,6 +9,7 @@ use PhpParser\Node\Expr\BinaryOp\Mul;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PHPStan\Type\Constant\ConstantIntegerType;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
@ -111,6 +112,12 @@ CODE_SAMPLE
|
||||
private function processArgumentPosition(Expr $expr, int $argumentPosition): Expr
|
||||
{
|
||||
$oldValue = $expr->args[$argumentPosition]->value;
|
||||
if (! $oldValue instanceof LNumber) {
|
||||
if (! $this->getStaticType($oldValue) instanceof ConstantIntegerType) {
|
||||
return $expr;
|
||||
}
|
||||
}
|
||||
|
||||
$newArgumentValue = new Mul($oldValue, new LNumber(60));
|
||||
|
||||
$expr->args[$argumentPosition] = new Arg($newArgumentValue);
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Laravel\Tests\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class SkipCall
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
\Illuminate\Support\Facades\Cache::put('key', 'value', new DateTime());
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ final class MinutesToSecondsInCacheRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc']);
|
||||
$this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc', __DIR__ . '/Fixture/skip_call.php.inc']);
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
|
@ -174,7 +174,7 @@ CODE_SAMPLE
|
||||
}
|
||||
|
||||
// is this an object? create factory for it next to this :)
|
||||
if ($this->uniqueObjectOrServiceDetector->isUniqueObject($node)) {
|
||||
if ($this->uniqueObjectOrServiceDetector->isUniqueObject()) {
|
||||
$factoryClass = $this->uniqueObjectFactoryFactory->createFactoryClass($node, $staticTypesInClass);
|
||||
|
||||
$this->factoryClassPrinter->printFactoryForClass($factoryClass, $node);
|
||||
|
@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\RemovingStatic;
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
||||
final class UniqueObjectOrServiceDetector
|
||||
{
|
||||
public function isUniqueObject(): bool
|
||||
|
Loading…
Reference in New Issue
Block a user