Repository navigation
Expand file tree
/
Copy pathFunctionLikeToFirstClassCallableRector.php
More file actions
69 lines (62 loc) · 2.13 KB
/
Copy pathFunctionLikeToFirstClassCallableRector.php
File metadata and controls
69 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace Rector\CodingStyle\Rector\FunctionLike;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Closure;
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector;
use Rector\CodingStyle\Rector\Closure\ClosureDelegatingCallToFirstClassCallableRector;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @deprecated This rule was split into
* @see ClosureDelegatingCallToFirstClassCallableRector and
* @see ArrowFunctionDelegatingCallToFirstClassCallableRector
*/
final class FunctionLikeToFirstClassCallableRector extends AbstractRector implements MinPhpVersionInterface, DeprecatedInterface
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Converts arrow function and closures to first class callable',
[new CodeSample(
<<<'CODE_SAMPLE'
function ($parameter) {
return Call::to($parameter);
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
Call::to(...);
CODE_SAMPLE
,
)]
);
}
public function getNodeTypes(): array
{
return [ArrowFunction::class, Closure::class];
}
/**
* @param ArrowFunction|Closure $node
*/
public function refactor(Node $node): null|CallLike
{
throw new ShouldNotHappenException(sprintf(
'"%s" rule is deprecated. It was split into "%s" and "%s" rules.',
self::class,
ClosureDelegatingCallToFirstClassCallableRector::class,
ArrowFunctionDelegatingCallToFirstClassCallableRector::class
));
}
public function provideMinPhpVersion(): int
{
return PhpVersionFeature::FIRST_CLASS_CALLABLE_SYNTAX;
}
}