Phan\AST\ContextNode::getOrCreateProperty PHP Method

getOrCreateProperty() public method

public getOrCreateProperty ( string $property_name ) : Phan\Language\Element\Property
$property_name string
return Phan\Language\Element\Property A variable in scope or a new variable
    public function getOrCreateProperty(string $property_name) : Property
    {
        try {
            return $this->getProperty($property_name);
        } catch (IssueException $exception) {
            // Ignore it, because we'll create our own
            // property
        } catch (UnanalyzableException $exception) {
            // Ignore it, because we'll create our own
            // property
        }
        try {
            $class_list = (new ContextNode($this->code_base, $this->context, $this->node->children['expr'] ?? null))->getClassList();
        } catch (CodeBaseException $exception) {
            throw new IssueException(Issue::fromType(Issue::UndeclaredClassReference)($this->context->getFile(), $this->node->lineno ?? 0, [$exception->getFQSEN()]));
        }
        if (empty($class_list)) {
            throw new UnanalyzableException($this->node, "Could not get class name from node");
        }
        $class = array_values($class_list)[0];
        $flags = 0;
        if ($this->node->kind == \ast\AST_STATIC_PROP) {
            $flags |= \ast\flags\MODIFIER_STATIC;
        }
        $property_fqsen = FullyQualifiedPropertyName::make($class->getFQSEN(), $property_name);
        // Otherwise, we'll create it
        $property = new Property($this->context, $property_name, new UnionType(), $flags, $property_fqsen);
        $class->addProperty($this->code_base, $property, new None());
        return $property;
    }