src/DefinitionResolver.php
public function createDefinitionFromNode(Node $node, string $fqn = null): Definition
    {
        $def = new Definition;
        $def->fqn = $fqn;

        // Determines whether the suggestion will show after "new"
        $def->canBeInstantiated = (
            $node instanceof Node\Statement\ClassDeclaration &&
            // check whether it is not an abstract class
            ($node->abstractOrFinalModifier === null || $node->abstractOrFinalModifier->kind !== PhpParser\TokenKind::AbstractKeyword)
        );

        // Interfaces, classes, traits, namespaces, functions, and global const elements
        $def->isMember = !(
            $node instanceof PhpParser\ClassLike ||

            ($node instanceof Node\Statement\NamespaceDefinition && $node->name !== null) ||

            $node instanceof Node\Statement\FunctionDeclaration ||

            ($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
        );

        // Definition is affected by global namespace fallback if it is a global constant or a global function
        $def->roamed = (
            $fqn !== null
            && strpos($fqn, '\\') === false
            && (
                ($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
                || $node instanceof Node\Statement\FunctionDeclaration
            )
        );

        // Static methods and static property declarations
        $def->isStatic = (
            ($node instanceof Node\MethodDeclaration && $node->isStatic()) ||

            (($propertyDeclaration = ParserHelpers\tryGetPropertyDeclaration($node)) !== null
            && $propertyDeclaration->isStatic())
        );

        if ($node instanceof Node\Statement\ClassDeclaration &&
            // TODO - this should be better represented in the parser API
            $node->classBaseClause !== null && $node->classBaseClause->baseClass !== null) {
            $def->extends = [(string)$node->classBaseClause->baseClass->getResolvedName()];
        } elseif (
            $node instanceof Node\Statement\InterfaceDeclaration &&
            // TODO - this should be better represented in the parser API
            $node->interfaceBaseClause !== null && $node->interfaceBaseClause->interfaceNameList !== null
        ) {
            $def->extends = [];
            foreach ($node->interfaceBaseClause->interfaceNameList->getValues() as $n) {
                $def->extends[] = (string)$n->getResolvedName();
            }
        }

        $def->symbolInformation = SymbolInformationFactory::fromNode($node, $fqn);

        if ($def->symbolInformation !== null) {
            $def->type = $this->getTypeFromNode($node);
            $def->declarationLine = $this->getDeclarationLineFromNode($node);
            $def->documentation = $this->getDocumentationFromNode($node);
        }

        if ($node instanceof FunctionLike) {
            $def->signatureInformation = $this->signatureInformationFactory->create($node);
        }

        return $def;
    }
public function createDefinitionFromNode(Node $node, string $fqn = null): Definition
    {
        $def = new Definition;
        $def->fqn = $fqn;

        // Determines whether the suggestion will show after "new"
        $def->canBeInstantiated = (
            $node instanceof Node\Statement\ClassDeclaration &&
            // check whether it is not an abstract class
            ($node->abstractOrFinalModifier === null || $node->abstractOrFinalModifier->kind !== PhpParser\TokenKind::AbstractKeyword)
        );

        // Interfaces, classes, traits, namespaces, functions, and global const elements
        $def->isMember = !(
            $node instanceof PhpParser\ClassLike ||

            ($node instanceof Node\Statement\NamespaceDefinition && $node->name !== null) ||

            $node instanceof Node\Statement\FunctionDeclaration ||

            ($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
        );

        // Definition is affected by global namespace fallback if it is a global constant or a global function
        $def->roamed = (
            $fqn !== null
            && strpos($fqn, '\\') === false
            && (
                ($node instanceof Node\ConstElement && $node->parent->parent instanceof Node\Statement\ConstDeclaration)
                || $node instanceof Node\Statement\FunctionDeclaration
            )
        );

        // Static methods and static property declarations
        $def->isStatic = (
            ($node instanceof Node\MethodDeclaration && $node->isStatic()) ||

            (($propertyDeclaration = ParserHelpers\tryGetPropertyDeclaration($node)) !== null
            && $propertyDeclaration->isStatic())
        );

        if ($node instanceof Node\Statement\ClassDeclaration &&
            // TODO - this should be better represented in the parser API
            $node->classBaseClause !== null && $node->classBaseClause->baseClass !== null) {
            $def->extends = [(string)$node->classBaseClause->baseClass->getResolvedName()];
        } elseif (
            $node instanceof Node\Statement\InterfaceDeclaration &&
            // TODO - this should be better represented in the parser API
            $node->interfaceBaseClause !== null && $node->interfaceBaseClause->interfaceNameList !== null
        ) {
            $def->extends = [];
            foreach ($node->interfaceBaseClause->interfaceNameList->getValues() as $n) {
                $def->extends[] = (string)$n->getResolvedName();
            }
        }

        $def->symbolInformation = SymbolInformationFactory::fromNode($node, $fqn);

        if ($def->symbolInformation !== null) {
            $def->type = $this->getTypeFromNode($node);
            $def->declarationLine = $this->getDeclarationLineFromNode($node);
            $def->documentation = $this->getDocumentationFromNode($node);
        }

        if ($node instanceof FunctionLike) {
            $def->signatureInformation = $this->signatureInformationFactory->create($node);
        }

        return $def;
    }
public function createDefinitionFromNode ( Node $ node , string $ fqn = null ) : Definition { $ def = new Definition ; $ def -> fqn = $ fqn ; // Determines whether the suggestion will show after "new" $ def -> canBeInstantiated = ( $ node instanceof Node \ Statement \ ClassDeclaration && // check whether it is not an abstract class ( $ node -> abstractOrFinalModifier === null || $ node -> abstractOrFinalModifier -> kind !== PhpParser \ TokenKind :: AbstractKeyword ) ) ; // Interfaces, classes, traits, namespaces, functions, and global const elements $ def -> isMember = ! ( $ node instanceof PhpParser \ ClassLike || ( $ node instanceof Node \ Statement \ NamespaceDefinition && $ node -> name !== null ) || $ node instanceof Node \ Statement \ FunctionDeclaration || ( $ node instanceof Node \ ConstElement && $ node -> parent -> parent instanceof Node \ Statement \ ConstDeclaration ) ) ; // Definition is affected by global namespace fallback if it is a global constant or a global function $ def -> roamed = ( $ fqn !== null && strpos ( $ fqn , '\\' ) === false && ( ( $ node instanceof Node \ ConstElement && $ node -> parent -> parent instanceof Node \ Statement \ ConstDeclaration ) || $ node instanceof Node \ Statement \ FunctionDeclaration ) ) ; // Static methods and static property declarations $ def -> isStatic = ( ( $ node instanceof Node \ MethodDeclaration && $ node -> isStatic ( ) ) || ( ( $ propertyDeclaration = ParserHelpers \ tryGetPropertyDeclaration ( $ node ) ) !== null && $ propertyDeclaration -> isStatic ( ) ) ) ; if ( $ node instanceof Node \ Statement \ ClassDeclaration && // TODO - this should be better represented in the parser API $ node -> classBaseClause !== null && $ node -> classBaseClause -> baseClass !== null ) { $ def -> extends = [ ( string ) $ node -> classBaseClause -> baseClass -> getResolvedName ( ) ] ; } elseif ( $ node instanceof Node \ Statement \ InterfaceDeclaration && // TODO - this should be better represented in the parser API $ node -> interfaceBaseClause !== null && $ node -> interfaceBaseClause -> interfaceNameList !== null ) { $ def -> extends = [ ] ; foreach ( $ node -> interfaceBaseClause -> interfaceNameList -> getValues ( ) as $ n ) { $ def -> extends [ ] = ( string ) $ n -> getResolvedName ( ) ; } } $ def -> symbolInformation = SymbolInformationFactory :: fromNode ( $ node , $ fqn ) ; if ( $ def -> symbolInformation !== null ) { $ def -> type = $ this -> getTypeFromNode ( $ node ) ; $ def -> declarationLine = $ this -> getDeclarationLineFromNode ( $ node ) ; $ def -> documentation = $ this -> getDocumentationFromNode ( $ node ) ; } if ( $ node instanceof FunctionLike ) { $ def -> signatureInformation = $ this -> signatureInformationFactory -> create ( $ node ) ; } return $ def ; }
Create a Definition for a definition node

@param Node $node
@param string $fqn
@return Definition
Create a Definition for a definition node