public static function fromStringInContext(string $type_string, Context $context) : UnionType { if (empty($type_string)) { return new UnionType(); } // If our scope has a generic type identifier defined on it // that matches the type string, return that UnionType. if ($context->getScope()->hasTemplateType($type_string)) { return $context->getScope()->getTemplateType($type_string)->asUnionType(); } return new UnionType(array_map(function (string $type_name) use($context, $type_string) { assert($type_name !== '', "Type cannot be empty."); return Type::fromStringInContext($type_name, $context); }, array_filter(array_map(function (string $type_name) { return trim($type_name); }, explode('|', $type_string))))); }
/** * @return Func[] * One or more (alternate) methods begotten from * reflection info and internal method data */ public static function functionListFromSignature(CodeBase $code_base, FullyQualifiedFunctionName $fqsen, array $signature) : array { $context = new Context(); $return_type = UnionType::fromStringInContext(array_shift($signature), $context); $func = new Func($context, $fqsen->getName(), $return_type, 0, $fqsen); return self::functionListFromFunction($func, $code_base); }