docBlockFactory = $docBlockFactory; } public function beforeTraverse(array $nodes) { $this->namespace = ''; $this->aliases = []; } public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Namespace_) { $this->namespace = (string)$node->name; } else if ($node instanceof Node\Stmt\UseUse) { $this->aliases[(string)$node->name] = $node->alias; } $docComment = $node->getDocComment(); if ($docComment === null) { return; } $context = new Context($this->namespace, $this->aliases); try { $docBlock = $this->docBlockFactory->create($docComment->getText(), $context); $node->setAttribute('docBlock', $docBlock); } catch (Exception $e) { $this->errors[] = new PhpParser\Error($e->getMessage(), [ 'startFilePos' => $docComment->getFilePos(), 'endFilePos' => $docComment->getFilePos() + strlen($docComment->getText()), 'startLine' => $docComment->getLine(), 'endLine' => $docComment->getLine() + preg_match_all('/[\\n\\r]/', $docComment->getText()) + 1 ]); } } public function leaveNode(Node $node) { if ($node instanceof Node\Stmt\Namespace_) { $this->namespace = ''; $this->aliases = []; } } }