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> */ public function getNodeTypes() : array { return [MethodCall::class]; } /** * @param MethodCall $node */ public function refactor(Node $node) : ?Node { foreach ($this->methodCallsToStaticCalls as $methodCallToStaticCall) { if (!$this->isName($node->name, $methodCallToStaticCall->getOldMethod())) { continue; } if (!$this->isObjectType($node->var, $methodCallToStaticCall->getOldObjectType())) { continue; } return $this->nodeFactory->createStaticCall($methodCallToStaticCall->getNewClass(), $methodCallToStaticCall->getNewMethod(), $node->args); } return null; } /** * @param mixed[] $configuration */ public function configure(array $configuration) : void { Assert::allIsAOf($configuration, MethodCallToStaticCall::class); $this->methodCallsToStaticCalls = $configuration; } }