Phan\Language\UnionType::asClassList PHP Method

asClassList() public method

public asClassList ( CodeBase $code_base, Context $context ) : Generator | Clazz[]
$code_base Phan\CodeBase The code base in which to find classes
$context Context The context in which we're resolving this union type.
return Generator | Phan\Language\Element\Clazz[] A list of classes representing the non-native types associated with this UnionType
    public function asClassList(CodeBase $code_base, Context $context)
    {
        // Iterate over each viable class type to see if any
        // have the constant we're looking for
        foreach ($this->nonNativeTypes()->getTypeSet() as $class_type) {
            // Get the class FQSEN
            $class_fqsen = $class_type->asFQSEN();
            if ($class_type->isStaticType()) {
                if (!$context->isInClassScope()) {
                    throw new IssueException(Issue::fromType(Issue::ContextNotObject)($context->getFile(), $context->getLineNumberStart(), [(string) $class_type]));
                }
                (yield $context->getClassInScope($code_base));
            } else {
                // See if the class exists
                if (!$code_base->hasClassWithFQSEN($class_fqsen)) {
                    throw new CodeBaseException($class_fqsen, "Cannot find class {$class_fqsen}");
                }
                (yield $code_base->getClassByFQSEN($class_fqsen));
            }
        }
    }