本文整理汇总了PHP中PhpParser\Node::getDocComment方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getDocComment方法的具体用法?PHP Node::getDocComment怎么用?PHP Node::getDocComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node
的用法示例。
在下文中一共展示了Node::getDocComment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enterNode
function enterNode(\PhpParser\Node $node)
{
if ($node instanceof \PhpParser\Node\Stmt\Namespace_) {
$this->addNamespace(array('namespace' => $node->name->toString(), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\Use_) {
foreach ($node->uses as $use) {
$this->addUse(array('name' => $use->name, 'alias' => $use->alias));
}
}
if ($node instanceof \PhpParser\Node\Stmt\Class_) {
$this->addClass(array('name' => $node->name, 'extends' => $node->extends, 'implements' => $node->implements, 'abstract' => $node->isAbstract(), 'final' => $node->isFinal(), 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\Interface_) {
$this->addInterface(array('name' => $node->name, 'extends' => $node->extends, 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\ClassMethod) {
$this->addClassMethod(array('byRef' => $node->byRef, 'name' => $node->name, 'params' => $node->params, 'returnType' => $node->returnType, 'public' => $node->isPublic(), 'protected' => $node->isProtected(), 'private' => $node->isPrivate(), 'abstract' => $node->isAbstract(), 'final' => $node->isFinal(), 'static' => $node->isStatic(), 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\Property) {
$this->last_property = $node;
}
if ($node instanceof \PhpParser\Node\Stmt\PropertyProperty) {
$this->addClassProperty(array('name' => $node->name, 'default' => $node->default, 'public' => $this->last_property->isPublic(), 'protected' => $this->last_property->isProtected(), 'private' => $this->last_property->isPrivate(), 'static' => $this->last_property->isStatic(), 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
// $this->logger->info(get_class($node));
}
示例2: enterNode
/**
* Check all nodes
*
* @param Node $node
* @return void
**/
public function enterNode(Node $node)
{
// Skip nodes without comments.
if (!$node->hasAttribute("comments")) {
return;
}
// Check if annotations should be preserved. Only nodes with actual
// doc comment blocks are processed.
$comments = [];
if ($this->preserveAnnotations) {
$docComment = $node->getDocComment();
if ($docComment) {
$text = $docComment->getText();
// Check if it is a doc comment.
if (strpos($text, "/**") !== false) {
$text = $this->stripComment($text);
if ($text) {
$comments = [new Comment($text)];
}
}
}
}
// Remove (or set) comments.
$node->setAttribute("comments", $comments);
return $node;
}
示例3: leaveNode
public function leaveNode(Node $node)
{
if ($node instanceof Node\Stmt\UseUse) {
$this->uses['@' . $node->alias] = '@' . $node->name->toString();
}
if ($comment = $node->getDocComment()) {
$text = $comment->getText();
$text = str_replace(array_keys($this->uses), array_values($this->uses), $text);
$comment->setText($text);
}
}
示例4: getDocComment
/**
* @param \PhpParser\Node $node
* @return string|null
*/
public static function getDocComment(Node $node)
{
$phpDoc = $node->getDocComment();
$phpDocText = null;
if ($phpDoc !== null) {
return $phpDoc->getText();
}
$comments = $node->getAttribute('comments');
if ($comments === null) {
return null;
}
return $comments[count($comments) - 1]->getText();
}
示例5: getDocCommentForNode
/**
* @param Node $node
* @return null|string
*/
private function getDocCommentForNode(Node $node)
{
// check if there is a doc comment for the ID argument
// ->trans(/** @Desc("FOO") */ 'my.id')
if (null !== ($comment = $node->args[0]->getDocComment())) {
return $comment->getText();
}
// this may be placed somewhere up in the hierarchy,
// -> /** @Desc("FOO") */ trans('my.id')
// /** @Desc("FOO") */ ->trans('my.id')
// /** @Desc("FOO") */ $translator->trans('my.id')
if (null !== ($comment = $node->getDocComment())) {
return $comment->getText();
} elseif (null !== $this->previousNode && $this->previousNode->getDocComment() !== null) {
$comment = $this->previousNode->getDocComment();
return is_object($comment) ? $comment->getText() : $comment;
}
return null;
}
示例6: createDocComment
/**
* @param Node $node
*
* @return RefComment|null
*/
private function createDocComment(Node $node)
{
$docComment = $node->getDocComment();
if (!$docComment) {
return null;
}
$ref = new RefComment();
$ref->text = $docComment->getText();
$ref->startLine = $docComment->getLine();
$ref->endLine = $node->getLine() - 1;
return $ref;
}
示例7: mapAttributes
private function mapAttributes(Node $expr)
{
return array_merge(["filename" => $this->fileName, "doccomment" => $expr->getDocComment()], $expr->getAttributes());
}
示例8: repairComments
private function repairComments(Node $node)
{
$comment = $node->getDocComment();
if ($comment && !empty($this->classStack)) {
$regex = "(@(param|return|var|type)\\s+(\\S+))i";
$comment->setText(preg_replace_callback($regex, function ($match) {
$type = $match[2];
$type = preg_replace('((?<=^|\\|)((?i:self)|\\$this)(?=\\[|$|\\|))', end($this->classStack), $type);
return '@' . $match[1] . ' ' . $type;
}, $comment->getText()));
}
}
示例9: enterNode
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Namespace_) {
$this->namespace = implode('\\', $node->name->parts);
return;
}
if ($node instanceof Node\Stmt\Class_) {
$name = '' === $this->namespace ? $node->name : $this->namespace . '\\' . $node->name;
if (!class_exists($name)) {
return;
}
$ref = new \ReflectionClass($name);
if (!$ref->isSubclassOf('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException') && $ref->name !== 'Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException') {
return;
}
if (!$ref->hasMethod('getMessageKey')) {
return;
}
$this->inAuthException = true;
return;
}
if (!$this->inAuthException) {
return;
}
if ($node instanceof Node\Stmt\ClassMethod) {
if ('getmessagekey' === strtolower($node->name)) {
$this->inGetMessageKey = true;
}
return;
}
if (!$this->inGetMessageKey) {
return;
}
if (!$node instanceof Node\Stmt\Return_) {
return;
}
$ignore = false;
$desc = $meaning = null;
if ($docComment = $node->getDocComment()) {
foreach ($this->docParser->parse($docComment->getText(), 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
if ($annot instanceof Ignore) {
$ignore = true;
} else {
if ($annot instanceof Desc) {
$desc = $annot->text;
} else {
if ($annot instanceof Meaning) {
$meaning = $annot->text;
}
}
}
}
}
if (!$node->expr instanceof Node\Scalar\String_) {
if ($ignore) {
return;
}
$message = sprintf('Could not extract id from return value, expected scalar string but got %s (in %s on line %d).', get_class($node->expr), $this->file, $node->expr->getLine());
if ($this->logger) {
$this->logger->error($message);
return;
}
throw new RuntimeException($message);
}
$message = Message::create($node->expr->value, $this->domain)->setDesc($desc)->setMeaning($meaning)->addSource(new FileSource((string) $this->file, $node->expr->getLine()));
$this->catalogue->add($message);
}
示例10: leaveNode
public function leaveNode(Node $node)
{
/*if ($node instanceof Node\Name) {
return new Node\Name($node->toString('_'));
}*/
if ($node instanceof Stmt\Class_ || $node instanceof Stmt\Interface_ || $node instanceof Stmt\Trait_ || $node instanceof Stmt\Function_) {
$item = [];
$itemName = $node->namespacedName->toString();
$item['name'] = $this->ensureUtf8($itemName);
$comment = $node->getDocComment();
if ($comment) {
$item['phpDoc'] = $this->ensureUtf8($node->getDocComment()->getText());
}
$item['packageName'] = $this->package['packageName'];
$item['packageVersion'] = $this->package['packageVersion'];
$item['fileName'] = $this->fileName;
unset($this->uses[$itemName]);
$item['uses'] = array_keys($this->uses);
if ($node instanceof Stmt\Class_) {
$item['type'] = ItemDao::TYPE_CLASS;
$inherits = [];
if ($node->extends) {
$inherits[] = $this->ensureUtf8($node->extends->toString());
}
foreach ($node->implements as $implement) {
$inherits[] = $this->ensureUtf8($implement->toString());
}
$item['inherits'] = $inherits;
} elseif ($node instanceof Stmt\Interface_) {
$item['type'] = ItemDao::TYPE_INTERFACE;
$inherits = [];
foreach ($node->extends as $extend) {
$inherits[] = $this->ensureUtf8($extend->toString());
}
$item['inherits'] = $inherits;
} elseif ($node instanceof Stmt\Trait_) {
$item['type'] = ItemDao::TYPE_TRAIT;
} elseif ($node instanceof Stmt\Function_) {
$item['type'] = ItemDao::TYPE_FUNCTION;
}
$this->itemDao->save($item);
/*} elseif ($node instanceof Node\Name) {
$this->uses[$node->toString()] = true;*/
} elseif ($node instanceof Stmt\Const_) {
foreach ($node->consts as $const) {
$this->uses[$const->namespacedName->toString()] = true;
}
} elseif ($node instanceof Expr\StaticCall || $node instanceof Expr\StaticPropertyFetch || $node instanceof Expr\ClassConstFetch || $node instanceof Expr\New_ || $node instanceof Expr\Instanceof_) {
if ($node->class instanceof Name) {
$className = $node->class->toString();
$lowerClassName = strtolower($className);
if ($lowerClassName != "self" && $lowerClassName != "parent" && $lowerClassName != "parent") {
$this->uses[$className] = true;
}
}
} elseif ($node instanceof Stmt\Catch_) {
$this->uses[$node->type->toString()] = true;
} elseif ($node instanceof Stmt\TraitUse) {
foreach ($node->traits as $trait) {
$this->uses[$trait->toString()] = true;
}
} elseif ($node instanceof Node\Param && $node->type instanceof Name) {
$this->uses[$node->type->toString()] = true;
}
}
示例11: getDeprecatedDocComment
/**
* @param Node $node
*
* @return null|string
*/
protected function getDeprecatedDocComment(Node $node)
{
try {
$docBlock = new DocBlock((string) $node->getDocComment());
/** @var DocBlock\Tag\DeprecatedTag[] $deprecatedTag */
$deprecatedTag = $docBlock->getTagsByName('deprecated');
if (0 === count($deprecatedTag)) {
return;
}
$comment = $deprecatedTag[0]->getContent();
return preg_replace('/[[:blank:]]+/', ' ', $comment);
} catch (\Exception $e) {
return;
}
}
示例12: createTag
/**
* Create a new tag and add it to the tags list.
*
* @param string $type
* @param string $name
* @return Tag
*/
public function createTag($type, $name, Node $node)
{
return $this->tags[] = new Tag($name, $type, Tag::DEFINITION, $node->getAttribute('startLine'), $node->getAttribute('endLine'), $node->getAttribute('startFilePos'), $node->getAttribute('endFilePos'), $node->getDocComment());
}
示例13: it_doesnt_modify_non_class_method_nodes
public function it_doesnt_modify_non_class_method_nodes(Node $node)
{
$node->getDocComment()->shouldNotBeCalled();
$this->leaveNode($node);
}
示例14: enterNode
public function enterNode(PhpParser\Node $node)
{
if (stripos($node->getDocComment(), '@codeCoverageIgnore') !== FALSE) {
return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
}
}
示例15: enterNode
/**
* Called when entering a node.
*
* Return value semantics:
* * null: $node stays as-is
* * otherwise: $node is set to the return value
*
* @param Node $node
*
* @return null|Node
*/
public function enterNode(Node $node)
{
if ($node instanceof Namespace_) {
$this->namespace = '\\' . $node->name;
$this->namespaceLine = $node->getLine();
} elseif ($node instanceof Use_) {
$use_count = 0;
foreach ($node->uses as $use) {
if ($use instanceof UseUse) {
if (!$this->resolver->isValid("\\{$use->name}")) {
$this->result->error(ErrorType::UNABLE_TO_RESOLVE_USE, $use->getLine(), "Use '\\{$use->name}' could not be resolved");
}
if (isset($this->aliases[$use->alias])) {
$line = $this->aliases[$use->alias]->getNode()->getLine();
$this->result->error(ErrorType::DUPLICATE_ALIAS, $use->getLine(), "Alias '{$use->alias}' is already in use on line {$line}");
}
$this->aliases[$use->alias] = new UseTracker($use->alias, (string) $use->name, $use);
$this->useStatements[] = $use;
} else {
// I don't know if this error can ever be generated, as it should be a parse error...
$this->result->error(ErrorType::MALFORMED_USE, $use->getLine(), "Malformed use statement");
return;
}
$use_count++;
}
if ($use_count > 1) {
$this->result->error(ErrorType::MULTI_STATEMENT_USE, $node->getLine(), "Multiple uses in one statement is discouraged");
}
} else {
if ($node instanceof New_) {
$this->validateMethodAccess($node->getLine(), $node->class, '__construct');
}
if ($node instanceof StaticCall) {
if ($node->name !== '__construct') {
$this->validateMethodExists($node->getLine(), $node->class, $node->name);
}
$this->validateMethodAccess($node->getLine(), $node->class, $node->name);
}
if (isset($node->class) && $node->class instanceof Name) {
$this->resolveType($node->getLine(), $node->class);
}
if (isset($node->traits)) {
foreach ($node->traits as $trait) {
$this->resolveType($node->getLine(), $trait);
}
}
if (isset($node->implements)) {
foreach ($node->implements as $implements) {
$this->resolveType($node->getLine(), $implements);
}
}
if (isset($node->extends)) {
if ($node->extends instanceof Name) {
$this->resolveType($node->getLine(), $node->extends);
} else {
foreach ($node->extends as $extends) {
$this->resolveType($node->getLine(), $extends);
}
}
}
if (isset($node->type) && $node->type instanceof Name) {
$this->resolveType($node->getLine(), $node->type);
}
if ($node instanceof ClassMethod && $node->getReturnType() instanceof Name) {
$this->resolveType($node->getLine(), $node->getReturnType());
}
if ($node instanceof ClassMethod or $node instanceof Function_ or $node instanceof Property or $node instanceof Class_ or $node instanceof Variable) {
/** @var $docblock Doc */
if ($docblock = $node->getDocComment()) {
$annotations = $this->annotationParser->parseString($docblock->getText());
foreach ($annotations as $annotation) {
if ($annotation instanceof DoctrineAnnotation) {
$this->resolveDoctrineComment($docblock->getLine() - 1, $annotation);
} elseif ($annotation instanceof NonDoctrineAnnotation) {
$this->resolveNonDoctrineComment($docblock->getLine() - 1, $annotation);
}
}
}
}
if ($node instanceof Catch_) {
foreach ($node->types as $type) {
$this->resolveType($node->getLine(), $type);
}
}
// eclipse can only handle inline type hints in a normal comment block
if ($node instanceof Variable) {
$comments = $node->getAttribute('comments');
if (is_array($comments)) {
$phpVariableRegex = '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*';
//.........这里部分代码省略.........