protected function setComment(NodeInterface $node, $comment_text) { if ($this->supportsDocComments($node)) { /** @var \Pharborist\DocCommentTrait $node */ $node->setDocComment(DocCommentNode::create($comment_text)); } else { LineCommentBlockNode::create($comment_text)->insertBefore($node->getStatement()); } }
public function visitLineCommentBlockNode(LineCommentBlockNode $node) { if ($this->indentLevel > 0) { $indent = $this->getIndent(); foreach ($node->children(Filter::isInstanceOf('\\Pharborist\\CommentNode'))->slice(1) as $line_comment) { $prev = $line_comment->previous(); if ($prev instanceof WhitespaceNode) { $prev->setText($indent); } else { $line_comment->before(Token::whitespace($indent)); } } } else { $node->children(Filter::isInstanceOf('\\Pharborist\\WhitespaceNode'))->remove(); } }
private function getSkipNodes($skipped) { $nodes = []; for ($i = 0, $n = count($skipped); $i < $n; $i++) { $token = $skipped[$i]; if ($token instanceof CommentNode && $token->isLineComment()) { $comment = $token; $end = $i; for ($j = $i + 1; $j < $n; $j++) { $token = $skipped[$j]; if ($token instanceof WhitespaceNode && $token->getNewlineCount() === 0) { $j++; $token = $j < $n ? $skipped[$j] : NULL; } if ($token instanceof CommentNode && $token->getCommentType() === $comment->getCommentType()) { $end = $j; } else { break; } } if ($end > $i) { $comment_block = new LineCommentBlockNode(); for ($j = $i; $j <= $end; $j++) { $comment_block->addChild($skipped[$j]); } $i = $end; $nodes[] = $comment_block; } else { $nodes[] = $comment; } } else { $nodes[] = $token; } } return $nodes; }
/** * Builds a FIXME notice using either the text in the plugin definition, * or passed-in text. * * @param string|NULL $text * The FIXME notice's text, with variable placeholders and no translation. * @param array $variables * Optional variables to use in translation. If empty, the FIXME will not * be translated. * @param string|NULL $style * The comment style. Returns a LineCommentBlockNode if this is set to * self::LINE_COMMENT, a DocCommentNode if self::DOC_COMMENT, or the FIXME * as a string if set to anything else. * * @return mixed */ protected function buildFixMe($text = NULL, array $variables = [], $style = self::LINE_COMMENT) { $fixMe = "@FIXME\n" . ($text ?: $this->pluginDefinition['fixme']); if (isset($this->pluginDefinition['documentation'])) { $fixMe .= "\n"; foreach ($this->pluginDefinition['documentation'] as $doc) { $fixMe .= "\n@see "; $fixMe .= isset($doc['url']) ? $doc['url'] : (string) $doc; } } if ($variables) { $fixMe = $this->t($fixMe, $variables); } switch ($style) { case self::LINE_COMMENT: return LineCommentBlockNode::create($fixMe); case self::DOC_COMMENT: return DocCommentNode::create($fixMe); default: return $fixMe; } }