> */ public function getNodeTypes() : array { return [Class_::class]; } /** * @param Class_ $node */ public function refactor(Node $node) : ?Class_ { if (!$node->isFinal()) { return null; } $hasChanged = \false; $this->traverseNodesWithCallable($node->stmts, function (Node $subNode) use(&$hasChanged, $node) : ?StaticCall { if (!$subNode instanceof StaticCall) { return null; } if (!$this->isName($subNode->class, ObjectReference::STATIC)) { return null; } // skip dynamic method if (!$subNode->name instanceof Identifier) { return null; } $methodName = (string) $this->getName($subNode->name); $targetClassMethod = $node->getMethod($methodName); // skip call non-existing method from current class to ensure transformation is safe if (!$targetClassMethod instanceof ClassMethod) { return null; } // avoid overlapped change if (!$targetClassMethod->isStatic()) { return null; } $hasChanged = \true; $subNode->class = new Name('self'); return $subNode; }); if ($hasChanged) { return $node; } return null; } }