Repository navigation
Expand file tree
/
Copy pathMethodCallToStaticCallRector.php
More file actions
90 lines (79 loc) · 2.46 KB
/
Copy pathMethodCallToStaticCallRector.php
File metadata and controls
90 lines (79 loc) · 2.46 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
namespace Rector\Transform\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
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\MethodCallToStaticCall;
/**
* @deprecated This rule is deprecated, as turning a method call into a static call depends on project context and this generic rule is too niche. Write a custom rule for the exact project case instead.
*/
final class MethodCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change method call to desired static call', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
final class SomeClass
{
private $anotherDependency;
public function __construct(AnotherDependency $anotherDependency)
{
$this->anotherDependency = $anotherDependency;
}
public function loadConfiguration()
{
return $this->anotherDependency->process('value');
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
final class SomeClass
{
private $anotherDependency;
public function __construct(AnotherDependency $anotherDependency)
{
$this->anotherDependency = $anotherDependency;
}
public function loadConfiguration()
{
return StaticCaller::anotherMethod('value');
}
}
CODE_SAMPLE
,
[new MethodCallToStaticCall('AnotherDependency', 'process', 'StaticCaller', 'anotherMethod')]
),
]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf(
'"%s" rule is deprecated, as turning a method call into a static call depends on project context; write a custom rule for the exact project case instead',
self::class
));
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
}
}