nodeNameResolver = $nodeNameResolver; $this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser; $this->propertyFetchAnalyzer = $propertyFetchAnalyzer; $this->constantNaming = $constantNaming; $this->nodeFactory = $nodeFactory; } public function replace(\PhpParser\Node\Stmt\Class_ $class, \PhpParser\Node\Stmt\Property $property) : void { $propertyProperty = $property->props[0]; $propertyName = $this->nodeNameResolver->getName($property); $constantName = $this->constantNaming->createFromProperty($propertyProperty); $this->simpleCallableNodeTraverser->traverseNodesWithCallable($class, function (\PhpParser\Node $node) use($propertyName, $constantName) : ?ClassConstFetch { if (!$this->propertyFetchAnalyzer->isLocalPropertyFetch($node)) { return null; } /** @var PropertyFetch|StaticPropertyFetch $node */ if (!$this->nodeNameResolver->isName($node->name, $propertyName)) { return null; } // replace with constant fetch return $this->nodeFactory->createSelfFetchConstant($constantName, $node); }); } }