src/CompletionProvider.php
private function findVariableDefinitionsInNode(Node $node, string $namePrefix = ''): array
    {
        $vars = [];
        // If the child node is a variable assignment, save it

        $isAssignmentToVariable = function ($node) {
            return $node instanceof Node\Expression\AssignmentExpression;
        };

        if ($this->isAssignmentToVariableWithPrefix($node, $namePrefix)) {
            $vars[] = $node->leftOperand;
        } elseif ($node instanceof Node\ForeachKey || $node instanceof Node\ForeachValue) {
            foreach ($node->getDescendantNodes() as $descendantNode) {
                if ($descendantNode instanceof Node\Expression\Variable
                    && ($namePrefix === '' || strpos($descendantNode->getName(), $namePrefix) !== false)
                ) {
                    $vars[] = $descendantNode;
                }
            }
        } else {
            // Get all descendent variables, then filter to ones that start with $namePrefix.
            // Avoiding closure usage in tight loop
            foreach ($node->getDescendantNodes($isAssignmentToVariable) as $descendantNode) {
                if ($this->isAssignmentToVariableWithPrefix($descendantNode, $namePrefix)) {
                    $vars[] = $descendantNode->leftOperand;
                }
            }
        }

        return $vars;
    }
private function findVariableDefinitionsInNode(Node $node, string $namePrefix = ''): array
    {
        $vars = [];
        // If the child node is a variable assignment, save it

        $isAssignmentToVariable = function ($node) {
            return $node instanceof Node\Expression\AssignmentExpression;
        };

        if ($this->isAssignmentToVariableWithPrefix($node, $namePrefix)) {
            $vars[] = $node->leftOperand;
        } elseif ($node instanceof Node\ForeachKey || $node instanceof Node\ForeachValue) {
            foreach ($node->getDescendantNodes() as $descendantNode) {
                if ($descendantNode instanceof Node\Expression\Variable
                    && ($namePrefix === '' || strpos($descendantNode->getName(), $namePrefix) !== false)
                ) {
                    $vars[] = $descendantNode;
                }
            }
        } else {
            // Get all descendent variables, then filter to ones that start with $namePrefix.
            // Avoiding closure usage in tight loop
            foreach ($node->getDescendantNodes($isAssignmentToVariable) as $descendantNode) {
                if ($this->isAssignmentToVariableWithPrefix($descendantNode, $namePrefix)) {
                    $vars[] = $descendantNode->leftOperand;
                }
            }
        }

        return $vars;
    }
private function findVariableDefinitionsInNode ( Node $ node , string $ namePrefix = '' ) : array { $ vars = [ ] ; // If the child node is a variable assignment, save it $ isAssignmentToVariable = function ( $ node ) { return $ node instanceof Node \ Expression \ AssignmentExpression ; } ; if ( $ this -> isAssignmentToVariableWithPrefix ( $ node , $ namePrefix ) ) { $ vars [ ] = $ node -> leftOperand ; } elseif ( $ node instanceof Node \ ForeachKey || $ node instanceof Node \ ForeachValue ) { foreach ( $ node -> getDescendantNodes ( ) as $ descendantNode ) { if ( $ descendantNode instanceof Node \ Expression \ Variable && ( $ namePrefix === '' || strpos ( $ descendantNode -> getName ( ) , $ namePrefix ) !== false ) ) { $ vars [ ] = $ descendantNode ; } } } else { // Get all descendent variables, then filter to ones that start with $namePrefix. // Avoiding closure usage in tight loop foreach ( $ node -> getDescendantNodes ( $ isAssignmentToVariable ) as $ descendantNode ) { if ( $ this -> isAssignmentToVariableWithPrefix ( $ descendantNode , $ namePrefix ) ) { $ vars [ ] = $ descendantNode -> leftOperand ; } } } return $ vars ; }
Searches the subnodes of a node for variable assignments

@param Node $node
@param string $namePrefix Prefix to filter
@return Node\Expression\Variable[]
Searches the subnodes of a node for variable assignments