> */ public function getNodeTypes() : array { return [Class_::class]; } /** * @param Class_ $node */ public function refactor(Node $node) : ?Class_ { if ($node->getConstants() === []) { return null; } $class = $node; $hasChanged = \false; $this->traverseNodesWithCallable($class, function (Node $node) use($class, &$hasChanged) : ?Node { if (!$node instanceof ClassConstFetch) { return null; } if ($this->shouldBeSkipped($class, $node)) { return null; } $hasChanged = \true; $node->class = new Name('self'); return $node; }); if ($hasChanged) { return $node; } return null; } private function isUsingStatic(ClassConstFetch $classConstFetch) : bool { return $this->isName($classConstFetch->class, 'static'); } private function isPrivateConstant(ClassConstFetch $classConstFetch, Class_ $class) : bool { $constantName = $this->getConstantName($classConstFetch); if ($constantName === null) { return \false; } foreach ($class->getConstants() as $classConst) { if (!$this->nodeNameResolver->isName($classConst, $constantName)) { continue; } return $classConst->isPrivate(); } return \false; } private function shouldBeSkipped(Class_ $class, ClassConstFetch $classConstFetch) : bool { if (!$this->isUsingStatic($classConstFetch)) { return \true; } return !$this->isPrivateConstant($classConstFetch, $class); } private function getConstantName(ClassConstFetch $classConstFetch) : ?string { $constantNameIdentifier = $classConstFetch->name; if (!$constantNameIdentifier instanceof Identifier) { return null; } return $constantNameIdentifier->toString(); } }