Phan\AST\ContextNode::getClassConst PHP Method

getClassConst() public method

public getClassConst ( ) : Phan\Language\Element\ClassConstant
return Phan\Language\Element\ClassConstant Get the (non-class) constant associated with this node in this context
    public function getClassConst() : ClassConstant
    {
        assert($this->node->kind === \ast\AST_CLASS_CONST, "Node must be of type \\ast\\AST_CLASS_CONST");
        $constant_name = $this->node->children['const'];
        $class_fqsen = null;
        try {
            $class_list = (new ContextNode($this->code_base, $this->context, $this->node->children['class']))->getClassList();
        } catch (CodeBaseException $exception) {
            throw new IssueException(Issue::fromType(Issue::UndeclaredClassConstant)($this->context->getFile(), $this->node->lineno ?? 0, [$constant_name, $exception->getFQSEN()]));
        }
        foreach ($class_list as $i => $class) {
            $class_fqsen = $class->getFQSEN();
            // Check to see if the class has the constant
            if (!$class->hasConstantWithName($this->code_base, $constant_name)) {
                continue;
            }
            return $class->getConstantWithName($this->code_base, $constant_name);
        }
        // If no class is found, we'll emit the error elsewhere
        if ($class_fqsen) {
            throw new IssueException(Issue::fromType(Issue::UndeclaredConstant)($this->context->getFile(), $this->node->lineno ?? 0, ["{$class_fqsen}::{$constant_name}"]));
        }
        throw new NodeException($this->node, "Can't figure out constant {$constant_name} in node");
    }