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);
         }
     }
 }
Example #2
0
 /**
  * @return array
  * Get a map from column name to row values for
  * this instance
  */
 public function toRow() : array
 {
     return ['scope_name' => $this->primaryKeyValue(), 'fqsen' => (string) $this->method->getFQSEN(), 'name' => (string) $this->method->getName(), 'type' => (string) $this->method->getUnionType(), 'flags' => $this->method->getFlags(), 'context' => base64_encode(serialize($this->method->getContext())), 'is_deprecated' => $this->method->isDeprecated(), 'number_of_required_parameters' => $this->method->getNumberOfRequiredParameters(), 'number_of_optional_parameters' => $this->method->getNumberOfOptionalParameters()];
 }