Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -111,6 +112,12 @@ public function refactor(Node $node): ?Node
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function refactor(Node $node): ?Node
}

// 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);
Expand Down
2 changes: 0 additions & 2 deletions packages/RemovingStatic/src/UniqueObjectOrServiceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Rector\RemovingStatic;

use PhpParser\Node\Stmt\Class_;

final class UniqueObjectOrServiceDetector
{
public function isUniqueObject(): bool
Expand Down