Phan\Language\Element\FunctionInterface::setHasReturn PHP Method

setHasReturn() public method

public setHasReturn ( boolean $has_return ) : void
$has_return boolean Set to true to mark this method as having a return value (Only through `return`)
return void
    public function setHasReturn(bool $has_return);

Usage Example

示例#1
0
 /**
  * The return type of the given FunctionInterface to a Generator.
  * Emit an Issue if the documented return type is incompatible with that.
  * @return void
  */
 private function setReturnTypeOfGenerator(FunctionInterface $func, Node $node)
 {
     // Currently, there is no way to describe the types passed to
     // a Generator in phpdoc.
     // So, nothing bothers recording the types beyond \Generator.
     $func->setHasReturn(true);
     // Returns \Generator, technically
     $func->setHasYield(true);
     if ($func->getUnionType()->isEmpty()) {
         $func->setIsReturnTypeUndefined(true);
         $func->getUnionType()->addUnionType(Type::fromNamespaceAndName('\\', 'Generator')->asUnionType());
     }
     if (!$func->isReturnTypeUndefined()) {
         $func_return_type = $func->getUnionType();
         if (!$func_return_type->canCastToExpandedUnionType(Type::fromNamespaceAndName('\\', 'Generator')->asUnionType(), $this->code_base)) {
             // At least one of the documented return types must
             // be Generator, Iterable, or Traversable.
             // Check for the issue here instead of in visitReturn/visitYield so that
             // the check is done exactly once.
             $this->emitIssue(Issue::TypeMismatchReturn, $node->lineno ?? 0, '\\Generator', $func->getName(), (string) $func_return_type);
         }
     }
 }