當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Context::getMethodInScope方法代碼示例

本文整理匯總了PHP中Phan\Language\Context::getMethodInScope方法的典型用法代碼示例。如果您正苦於以下問題:PHP Context::getMethodInScope方法的具體用法?PHP Context::getMethodInScope怎麽用?PHP Context::getMethodInScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phan\Language\Context的用法示例。


在下文中一共展示了Context::getMethodInScope方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: visitFuncDecl

 /**
  * Visit a node with kind `\ast\AST_FUNC_DECL`
  *
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitFuncDecl(Decl $node) : Context
 {
     $method = $this->context->getMethodInScope($this->code_base);
     $return_type = $method->getUnionType();
     if (!$return_type->isEmpty() && !$method->getHasReturn() && !$return_type->hasType(VoidType::instance()) && !$return_type->hasType(NullType::instance())) {
         Issue::emit(Issue::TypeMissingReturn, $this->context->getFile(), $node->lineno ?? 0, $method->getFQSEN(), (string) $return_type);
     }
     return $this->context;
 }
開發者ID:black-silence,項目名稱:phan,代碼行數:19,代碼來源:PostOrderAnalysisVisitor.php

示例2: visitMethod

 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitMethod(Decl $node) : Context
 {
     $method = $this->context->getMethodInScope($this->code_base);
     $return_type = $method->getUnionType();
     $has_interface_class = false;
     if ($method->getFQSEN() instanceof FullyQualifiedMethodName) {
         try {
             $class = $method->getDefiningClass($this->code_base);
             $has_interface_class = $class->isInterface();
         } catch (\Exception $exception) {
         }
     }
     if (!$method->isAbstract() && !$has_interface_class && !$return_type->isEmpty() && !$method->getHasReturn() && !$return_type->hasType(VoidType::instance()) && !$return_type->hasType(NullType::instance())) {
         Log::err(Log::ETYPE, "Method {$method->getFQSEN()} is declared to return {$return_type} but has no return value", $this->context->getFile(), $node->lineno);
     }
     return $this->context;
 }
開發者ID:gitter-badger,項目名稱:phan,代碼行數:25,代碼來源:PostOrderAnalysisVisitor.php

示例3: visitMethod

 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitMethod(Decl $node) : Context
 {
     $method = $this->context->getMethodInScope($this->code_base);
     $return_type = $method->getUnionType();
     $has_interface_class = false;
     if ($method->getFQSEN() instanceof FullyQualifiedMethodName) {
         try {
             $class = $method->getDefiningClass($this->code_base);
             $has_interface_class = $class->isInterface();
         } catch (\Exception $exception) {
         }
     }
     if (!$method->isAbstract() && !$has_interface_class && !$return_type->isEmpty() && !$method->getHasReturn() && !$return_type->hasType(VoidType::instance()) && !$return_type->hasType(NullType::instance())) {
         Issue::emit(Issue::TypeMissingReturn, $this->context->getFile(), $node->lineno ?? 0, $method->getFQSEN(), (string) $return_type);
     }
     return $this->context;
 }
開發者ID:actank,項目名稱:phan,代碼行數:25,代碼來源:PostOrderAnalysisVisitor.php

示例4: visitReturn

 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitReturn(Node $node) : Context
 {
     // Don't check return types in traits
     if ($this->context->isInClassScope()) {
         $clazz = $this->context->getClassInScope($this->code_base);
         if ($clazz->isTrait()) {
             return $this->context;
         }
     }
     // Make sure we're actually returning from a method.
     if (!$this->context->isMethodScope() && !$this->context->isClosureScope()) {
         return $this->context;
     }
     // Get the method/function/closure we're in
     $method = null;
     if ($this->context->isClosureScope()) {
         $method = $this->context->getClosureInScope($this->code_base);
     } else {
         if ($this->context->isMethodScope()) {
             $method = $this->context->getMethodInScope($this->code_base);
         } else {
             assert(false, "We're supposed to be in either method or closure scope.");
         }
     }
     // Figure out what we intend to return
     $method_return_type = $method->getUnionType();
     // Figure out what is actually being returned
     $expression_type = UnionType::fromNode($this->context, $this->code_base, $node->children['expr']);
     // If there is no declared type, see if we can deduce
     // what it should be based on the return type
     if ($method_return_type->isEmpty() || $method->isReturnTypeUndefined()) {
         $method->setIsReturnTypeUndefined(true);
         // Set the inferred type of the method based
         // on what we're returning
         $method->getUnionType()->addUnionType($expression_type);
         // No point in comparing this type to the
         // type we just set
         return $this->context;
     }
     if (!$method->isReturnTypeUndefined() && !$expression_type->canCastToExpandedUnionType($method_return_type, $this->code_base)) {
         Log::err(Log::ETYPE, "return {$expression_type} but {$method->getName()}() is declared to return {$method_return_type}", $this->context->getFile(), $node->lineno);
     }
     return $this->context;
 }
開發者ID:jazzdan,項目名稱:phan,代碼行數:52,代碼來源:BreadthFirstVisitor.php


注:本文中的Phan\Language\Context::getMethodInScope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。