[Laravel] Fix MinutesToSecondsInCacheRector DateTimeInterface argument

This commit is contained in:
Tomas Votruba 2019-04-26 00:33:19 +02:00
parent 83087684e1
commit 92bed77b05
5 changed files with 22 additions and 4 deletions

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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

View File

@ -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);

View File

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Rector\RemovingStatic;
use PhpParser\Node\Stmt\Class_;
final class UniqueObjectOrServiceDetector
{
public function isUniqueObject(): bool