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.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@
namespace Rector\CodeQuality\Rector\FuncCall;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use Rector\Php74\NodeAnalyzer\ClosureArrowFunctionAnalyzer;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\CodeSample;
use Rector\RuleDoc\RuleDefinition;

/**
* @see \Rector\Tests\CodeQuality\Rector\FuncCall\CallUserFuncWithArrowFunctionToInlineRector\CallUserFuncWithArrowFunctionToInlineRectorTest
* @deprecated This rule is deprecated, as it handles a niche call_user_func() with arrow function case that is not part of the PHP upgrade path.
*/
final class CallUserFuncWithArrowFunctionToInlineRector extends AbstractRector
final class CallUserFuncWithArrowFunctionToInlineRector extends AbstractRector implements DeprecatedInterface
{
public function __construct(
private readonly ClosureArrowFunctionAnalyzer $closureArrowFunctionAnalyzer
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Refactor `call_user_func()` with arrow function to direct call', [
Expand Down Expand Up @@ -65,37 +58,9 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->isFirstClassCallable()) {
return null;
}

if (! $this->isName($node, 'call_user_func')) {
return null;
}

if (count($node->args) !== 1) {
return null;
}

// change the node
if (! isset($node->getArgs()[0])) {
return null;
}

$firstArg = $node->args[0];
if (! $firstArg instanceof Arg) {
return null;
}

$firstArgValue = $firstArg->value;
if ($firstArgValue instanceof ArrowFunction) {
return $firstArgValue->expr;
}

if ($firstArgValue instanceof Closure) {
return $this->closureArrowFunctionAnalyzer->matchArrowFunctionExpr($firstArgValue);
}

return null;
throw new ShouldNotHappenException(sprintf(
'"%s" rule is deprecated, as it handles a niche call_user_func() with arrow function case that is not part of the PHP upgrade path',
self::class
));
}
}
2 changes: 0 additions & 2 deletions src/Config/Level/CodeQualityLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector;
use Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToCoalescingRector;
use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector;
use Rector\CodeQuality\Rector\FuncCall\CallUserFuncWithArrowFunctionToInlineRector;
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\FuncCall\InlineIsAInstanceOfRector;
Expand Down Expand Up @@ -159,7 +158,6 @@ final class CodeQualityLevel
TernaryFalseExpressionToIfRector::class,
SwitchTrueToMatchRector::class,
SimplifyIfNullableReturnRector::class,
CallUserFuncWithArrowFunctionToInlineRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
InlineArrayReturnAssignRector::class,
RemoveAlwaysElseRector::class,
Expand Down
Loading