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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

37 changes: 8 additions & 29 deletions rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@

use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
use Rector\RuleDoc\RuleDefinition;
use Rector\Transform\ValueObject\FuncCallToStaticCall;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToStaticCallRector\FuncCallToStaticCallRectorTest
* @deprecated This rule is deprecated, as too niche, never used and needs project context. Write a custom rule for the exact project case instead.
*/
final class FuncCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface
final class FuncCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
{
/**
* @var array<string, FuncCallToStaticCall[]>
*/
private array $funcCallsToStaticCallsByOldFunc = [];

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Turn defined function call to static method call', [
Expand All @@ -47,33 +43,16 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$funcName = $this->getName($node);
if ($funcName === null) {
return null;
}

foreach ($this->funcCallsToStaticCallsByOldFunc[strtolower($funcName)] ?? [] as $funcCallToStaticCall) {
return $this->nodeFactory->createStaticCall(
$funcCallToStaticCall->getNewClassName(),
$funcCallToStaticCall->getNewMethodName(),
$node->args
);
}

return null;
throw new ShouldNotHappenException(sprintf(
'"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead',
self::class
));
}

/**
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
Assert::allIsAOf($configuration, FuncCallToStaticCall::class);

// bucket by lowercased old function name (function names are case-insensitive)
$this->funcCallsToStaticCallsByOldFunc = [];
foreach ($configuration as $funcCallToStaticCall) {
$this->funcCallsToStaticCallsByOldFunc[strtolower($funcCallToStaticCall->getOldFuncName())][] = $funcCallToStaticCall;
}
}
}
3 changes: 3 additions & 0 deletions rules/Transform/ValueObject/FuncCallToStaticCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Rector\Validation\RectorAssert;

/**
* @api used in deprecated FuncCallToStaticCallRector configs
*/
final readonly class FuncCallToStaticCall
{
public function __construct(
Expand Down
Loading