Phan\Language\UnionType::fromStringInContext PHP Method

fromStringInContext() public static method

public static fromStringInContext ( string $type_string, Context $context ) : UnionType
$type_string string A '|' delimited string representing a type in the form 'int|string|null|ClassName'.
$context Context The context in which the type string was found
return UnionType
    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)))));
    }

Usage Example

Esempio n. 1
0
 /**
  * @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);
 }
All Usage Examples Of Phan\Language\UnionType::fromStringInContext