|
23 | 23 | */ |
24 | 24 | abstract class AbstractProxyRector extends AbstractRector |
25 | 25 | { |
26 | | - protected RectorConfig $rectorConfig; |
27 | | - protected \Rector\Rector\AbstractRector $proxyRector; |
| 26 | + // /** @param list<mixed> $arguments */ |
| 27 | + // public function __call(string $name, array $arguments) |
| 28 | + // {return $this->makeProxyRector()->{$name}(...$arguments);} |
28 | 29 |
|
29 | 30 | /** |
30 | | - * @see \Rector\Testing\PHPUnit\AbstractLazyTestCase::getContainer() |
31 | | - * |
32 | 31 | * @throws \Illuminate\Contracts\Container\BindingResolutionException |
| 32 | + * |
| 33 | + * {@inheritDoc} |
33 | 34 | */ |
34 | | - public function __construct() |
| 35 | + final public function getNodeTypes(): array |
35 | 36 | { |
36 | | - $rectorConfig = (new LazyContainerFactory)->create(); |
37 | | - $rectorConfig->boot(); |
38 | | - $this->rectorConfig = $rectorConfig; |
39 | | - $this->proxyRector = clone $rectorConfig->make($this->proxyRectorClass()); |
| 37 | + return $this->makeProxyRector()->getNodeTypes(); |
40 | 38 | } |
41 | 39 |
|
42 | 40 | /** |
43 | | - * @param list<mixed> $arguments |
| 41 | + * {@inheritDoc} |
44 | 42 | * |
45 | | - * @return mixed |
| 43 | + * @throws \Illuminate\Contracts\Container\BindingResolutionException |
46 | 44 | */ |
47 | | - public function __call(string $name, array $arguments) |
| 45 | + final public function refactor(Node $node) |
48 | 46 | { |
49 | | - return $this->proxyRector->{$name}(...$arguments); |
| 47 | + return $this->rawRefactor($node); |
50 | 48 | } |
51 | 49 |
|
52 | 50 | /** |
53 | | - * @throws \ReflectionException |
| 51 | + * @throws \Illuminate\Contracts\Container\BindingResolutionException |
54 | 52 | * |
55 | | - * {@inheritDoc} |
| 53 | + * @return null|list<Node>|NodeVisitor::REMOVE_NODE|\PhpParser\Node |
56 | 54 | */ |
57 | | - final public function getNodeTypes(): array |
| 55 | + protected function rawRefactor(Node $node) |
58 | 56 | { |
59 | | - /** @var \ReflectionClass<\Rector\Rector\AbstractRector> $reflectionClass */ |
60 | | - $reflectionClass = new \ReflectionClass($this->proxyRectorClass()); |
61 | | - |
62 | | - return $reflectionClass->newInstanceWithoutConstructor()->getNodeTypes(); |
| 57 | + return $this->makeProxyRector()->refactor($node); |
63 | 58 | } |
64 | 59 |
|
65 | 60 | /** |
66 | | - * {@inheritDoc} |
| 61 | + * @throws \Illuminate\Contracts\Container\BindingResolutionException |
| 62 | + * |
| 63 | + * @return \Rector\Contract\Rector\ConfigurableRectorInterface&\Rector\Rector\AbstractRector |
67 | 64 | */ |
68 | | - final public function refactor(Node $node) |
| 65 | + protected function makeProxyRector(): \Rector\Rector\AbstractRector |
69 | 66 | { |
70 | | - return $this->applyRefactor($node); |
| 67 | + return $this->makeRectorConfig()->make($this->proxyRectorClass()); |
71 | 68 | } |
72 | 69 |
|
73 | 70 | /** |
74 | | - * @return null|list<Node>|NodeVisitor::REMOVE_NODE|\PhpParser\Node |
| 71 | + * @see \Rector\Testing\PHPUnit\AbstractLazyTestCase::getContainer() |
75 | 72 | */ |
76 | | - protected function applyRefactor(Node $node) |
| 73 | + protected function makeRectorConfig(): RectorConfig |
77 | 74 | { |
78 | | - return $this->proxyRector->refactor($node); |
| 75 | + static $rectorConfig; |
| 76 | + |
| 77 | + if ($rectorConfig instanceof RectorConfig) { |
| 78 | + return $rectorConfig; |
| 79 | + } |
| 80 | + |
| 81 | + $rectorConfig = (new LazyContainerFactory)->create(); |
| 82 | + $rectorConfig->singletonIf($this->proxyRectorClass()); |
| 83 | + $rectorConfig->boot(); |
| 84 | + |
| 85 | + return $rectorConfig; |
79 | 86 | } |
80 | 87 |
|
81 | 88 | /** |
|
0 commit comments