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


PHP Context::getClosureInScope方法代码示例

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


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

示例1: 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);
         }
     }
     assert(!empty($method), "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)) {
         Issue::emit(Issue::TypeMismatchReturn, $this->context->getFile(), $node->lineno ?? 0, (string) $expression_type, $method->getName(), (string) $method_return_type);
     }
     if ($method->isReturnTypeUndefined()) {
         // Add the new type to the set of values returned by the
         // method
         $method->getUnionType()->addUnionType($expression_type);
     }
     return $this->context;
 }
开发者ID:actank,项目名称:phan,代码行数:56,代码来源:PostOrderAnalysisVisitor.php

示例2: 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()) {
         // 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 (!$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:ABaldwinHunter,项目名称:phan,代码行数:51,代码来源:BreadthFirstVisitor.php


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