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


PHP Node::getReturnType方法代码示例

本文整理汇总了PHP中PhpParser\Node::getReturnType方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getReturnType方法的具体用法?PHP Node::getReturnType怎么用?PHP Node::getReturnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhpParser\Node的用法示例。


在下文中一共展示了Node::getReturnType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: recordFunctionReturnTypeUsage

 private function recordFunctionReturnTypeUsage(Node $node)
 {
     if ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassMethod) {
         if ($node->getReturnType() instanceof Node\Name) {
             $this->recordUsageOf($node->getReturnType());
         }
         if (is_string($node->getReturnType())) {
             $this->recordUsageOfByString($node->getReturnType());
         }
     }
 }
开发者ID:pamil,项目名称:ComposerRequireChecker,代码行数:11,代码来源:UsedSymbolCollector.php

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