当前位置: 首页>>代码示例>>PHP>>正文


PHP Node::getDocComment方法代码示例

本文整理汇总了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));
 }
开发者ID:soundasleep,项目名称:phpdoc2,代码行数:27,代码来源:Parser.php

示例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;
 }
开发者ID:basilfx,项目名称:php-obfuscator,代码行数:32,代码来源:RemoveComments.php

示例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);
     }
 }
开发者ID:mamuz,项目名称:squeezer,代码行数:11,代码来源:Converter.php

示例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();
 }
开发者ID:phpstan,项目名称:phpstan,代码行数:17,代码来源:CommentHelper.php

示例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;
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:23,代码来源:TranslatableExceptionsFileVisitor.php

示例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;
 }
开发者ID:christianblos,项目名称:codedocs,代码行数:17,代码来源:RefVisitor.php

示例7: mapAttributes

 private function mapAttributes(Node $expr)
 {
     return array_merge(["filename" => $this->fileName, "doccomment" => $expr->getDocComment()], $expr->getAttributes());
 }
开发者ID:ircmaxell,项目名称:php-cfg,代码行数:4,代码来源:Parser.php

示例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()));
     }
 }
开发者ID:ircmaxell,项目名称:php-cfg,代码行数:12,代码来源:MagicStringResolver.php

示例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);
 }
开发者ID:smacp,项目名称:JMSTranslationBundle,代码行数:67,代码来源:AuthenticationMessagesExtractor.php

示例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;
     }
 }
开发者ID:stof,项目名称:packanalyst,代码行数:65,代码来源:StoreInDbNodeVisitor.php

示例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;
     }
 }
开发者ID:HugoSantiagoBecerraAdan,项目名称:deprecation-detector,代码行数:20,代码来源:FindDeprecatedTagsVisitor.php

示例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());
 }
开发者ID:hexmode,项目名称:phptags,代码行数:11,代码来源:DefinitionVisitor.php

示例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);
 }
开发者ID:digitalkaoz,项目名称:typehint-to-docblock,代码行数:5,代码来源:ToDocBlockVisitorSpec.php

示例14: enterNode

 public function enterNode(PhpParser\Node $node)
 {
     if (stripos($node->getDocComment(), '@codeCoverageIgnore') !== FALSE) {
         return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
     }
 }
开发者ID:edsonmedina,项目名称:php_testability,代码行数:6,代码来源:CodeCoverageIgnoreVisitor.php

示例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]*';
//.........这里部分代码省略.........
开发者ID:vektah,项目名称:bugfree-dangerzone,代码行数:101,代码来源:NameValidator.php


注:本文中的PhpParser\Node::getDocComment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。