@param Node[]|array<Node[]> $nodes
@param string               $type

@return Node[]
435301
public function findNodesOfType(array $nodes, string $type): array
    {
        $collectedNodes = [];

        foreach ($nodes as $node) {
            if (is_array($node)) {
                $collectedNodes = array_merge(
                    $this->findNodesOfType($node, $type),
                    $collectedNodes
                );
            } elseif ($node instanceof Node) {
                if (is_a($node, $type, true)) {
                    $collectedNodes[] = $node;
                }

                $collectedNodes = array_merge(
                    $this->findNodesOfType(
                        AstHelper::getSubNodes($node),
                        $type
                    ),
                    $collectedNodes
                );
            }
        }

        return $collectedNodes;
    }
1341888
public function getNodesTree($nodes, $parentId)
    {
        return collect($nodes)->filter(function ($value) use ($parentId) {
            if (isset($value['parent_id'])) {
                if ($value['parent_id'] == $parentId) {
                    return true;
                }

                return false;
            }

            return true;
        })->mapWithKeys(function ($value, $key) use ($nodes) {
            $data = [
                'id'    => (string) $value['id'],
                'label' => $value['label'],
            ];

            if (isset($value['parent_id'])) {
                $children = $this->getNodesTree($nodes, $value['id']);
                if ($children->isNotEmpty()) {
                    $data['children'] = $children;
                }
            }

            return [
                $key => $data,
            ];
        })->values();
    }
169673
public function isTypeAndChainCalls(Node $node, string $type, array $methods): bool
    {
        if (! $node instanceof MethodCall) {
            return false;
        }

        // node chaining is in reverse order than code
        $methods = array_reverse($methods);

        foreach ($methods as $method) {
            $activeMethodName = $this->nameResolver->resolve($node);
            if ($activeMethodName !== $method) {
                return false;
            }

            $node = $node->var;
            if ($node instanceof MethodCall) {
                continue;
            }
        }

        $variableTypes = $this->nodeTypeResolver->resolve($node);

        return in_array($type, $variableTypes, true);
    }
1302146
public function beforeTraverse(array $nodes)
    {
        $keyedNodes = [];

        foreach ($nodes as $node) {
            $hashFunc = $node->getType().'Hash';

            if ( ! method_exists($this, $hashFunc)) {
                $keyedNodes[] = $node;

                continue;
            }

            $keyedNodes[$this->$hashFunc($node)] = $node;
        }

        return $keyedNodes;
    }
1220385
protected static function getNodes(DOMDocument $dom, $type)
	{
		$nodes  = [];
		$prefix = ($type === 'attribute') ? '@' : '';
		$xpath  = new DOMXPath($dom);

		// Get natural nodes
		foreach ($xpath->query('//' . $prefix . '*') as $node)
		{
			$nodes[] = [$node, $node->nodeName];
		}

		// Get XSL-generated nodes
		foreach ($xpath->query('//xsl:' . $type) as $node)
		{
			$nodes[] = [$node, $node->getAttribute('name')];
		}

		// Get xsl:copy-of nodes
		foreach ($xpath->query('//xsl:copy-of') as $node)
		{
			if (preg_match('/^' . $prefix . '(\\w+)$/', $node->getAttribute('select'), $m))
			{
				$nodes[] = [$node, $m[1]];
			}
		}

		return $nodes;
	}
104918
private function createPropertiesFromTypes(array $types): array
    {
        $properties = [];

        foreach ($types as $type) {
            $propertyName = $this->propertyNaming->fqnToVariableName($type);
            $property = $this->builderFactory->property($propertyName)
                ->makePrivate()
                ->getNode();

            // add doc block
            $this->docBlockManipulator->addVarTag($property, '\\' . $type);
            $properties[] = $property;
        }

        return $properties;
    }
1284263
protected static function getFlattenedSuperTypes(NodeType $nodeType) : array
    {
        $flattenedSuperTypes = [];
        foreach ($nodeType->declaredSuperTypes as $superTypeName => $superType) {
            if ($superType !== null) {
                $flattenedSuperTypes += static::getFlattenedSuperTypes($superType);
                $flattenedSuperTypes[$superTypeName] = $superType;
            }
        }

        foreach ($nodeType->declaredSuperTypes as $superTypeName => $superType) {
            if ($superType === null) {
                unset($flattenedSuperTypes[$superTypeName]);
            }
        }

        return $flattenedSuperTypes;
    }
1041254
public function setNodes(ArrayCollection $nodes)
    {
        $finalNodes = array();

        foreach ($nodes as $node) {
            if ($this->checkChildNode($node)) {
                $node->setParent($this);
                $finalNodes[] = $node;
            }
        }

        $this->nodes = $finalNodes;

        return $this;
    }
130834
protected function buildSelectOptions(array $nodes = [], $parentId = 0, $prefix = '')
    {
        $prefix = $prefix ?: str_repeat('&nbsp;', 6);

        $options = [];

        if (empty($nodes)) {
            $nodes = $this->allNodes();
        }

        foreach ($nodes as $node) {
            $node[$this->titleColumn] = $prefix.'&nbsp;'.$node[$this->titleColumn];
            if ($node[$this->parentColumn] == $parentId) {
                $children = $this->buildSelectOptions($nodes, $node[$this->getKeyName()], $prefix.$prefix);

                $options[$node[$this->getKeyName()]] = $node[$this->titleColumn];

                if ($children) {
                    $options += $children;
                }
            }
        }

        return $options;
    }
739070
public function getHasChildren( $type = null )
	{
		if ( is_null( $this->domNode ) ) return false;
		$hasAnyChildren = $this->domNode->hasChildNodes();
		if ( ! $hasAnyChildren || is_null( $type ) ) return $hasAnyChildren;

		$clone = $this->CloneInstance();
		return $clone->MoveToChild( $type );
	}
1109775
protected function convertArrayOfNodesToArrayOfNodeIdentifiersWithPrefix($nodes, $prefix)
    {
        if ($nodes === null) {
            $nodes = [];
        }

        if (!is_array($nodes) && ($nodes instanceof NodeInterface || $nodes instanceof TraversableNodeInterface)) {
            $nodes = [$nodes];
        }

        if (!is_array($nodes) && !$nodes instanceof \Traversable) {
            throw new Exception(sprintf('FlowQuery result, Array or Traversable expected by this helper, given: "%s".', gettype($nodes)), 1437169992);
        }

        $prefixedNodeIdentifiers = [];
        foreach ($nodes as $node) {
            if ($node instanceof NodeInterface) {
                /* @var $node NodeInterface */
                $prefixedNodeIdentifiers[] = $prefix . '_' . $this->renderWorkspaceTagForContextNode($node->getContext()->getWorkspace()->getName()) . '_' . $node->getIdentifier();
            } elseif ($node instanceof TraversableNodeInterface) {
                /* @var $node TraversableNodeInterface */
                $prefixedNodeIdentifiers[] = $prefix . '_' . $this->renderWorkspaceTagForContextNode((string)$node->getContentStreamIdentifier()) . '_' . $node->getNodeAggregateIdentifier();
            } else {
                throw new Exception(sprintf('One of the elements in array passed to this helper was not a Node, but of type: "%s".', gettype($node)), 1437169991);
            }
        }
        return $prefixedNodeIdentifiers;
    }
344656
protected function getAllSubtypes($type)
    {
        $subTypes = [];

        foreach ($this->superTypeConfiguration as $nodeType => $superTypes) {
            if (in_array($type, $superTypes)) {
                if (isset($this->types[$nodeType])) {
                    $subTypes[] = $nodeType;

                    $nodeTypeSubTypes = $this->getAllSubtypes($nodeType);
                    foreach ($nodeTypeSubTypes as $nodeTypeSubType) {
                        if (!in_array($nodeTypeSubType, $subTypes)) {
                            $subTypes[] = $nodeTypeSubType;
                        }
                    }
                }
            }
        }

        return $subTypes;
    }
728431
public function getCreatableTypes(array $roles, ResourceNode $node)
    {
        $creationRights = $this->rightsRepo->findCreationRights($roles, $node);

        return array_map(function (array $type) {
            return $type['name'];
        }, $creationRights);
    }
918498
public function buildTree($type, array $data)
    {
        $node = $this->resolver->resolve($type, $data);

        $fieldMap = $this->knowledge->compareFields($type, $data);


        $this->filler->fillNode($node, $fieldMap);

        return $node;
    }
419310
private function _getTreeNodesIds($nodes)
    {
        $result = [];

        foreach ($nodes as $node) {
            $result[] = $node->id;
        }

        return $result;
    }
254996
private function replaceGroupUseStatements(array $nodes): array
    {
        foreach ($nodes as $node) {
            if (false === ($node instanceof Namespace_)) {
                continue;
            }

            /** @var Namespace_ $node */
            $statements = $node->stmts;

            $newStatements = [];

            foreach ($statements as $statement) {
                if ($statement instanceof GroupUse) {
                    $uses_ = $this->createUses_($statement);

                    array_splice($newStatements, count($newStatements), 0, $uses_);
                } else {
                    $newStatements[] = $statement;
                }
            }

            $node->stmts = $newStatements;
        }

        return $nodes;
    }
314283
public function hasType(Node $node = null, $type) {
        if (!isset($node))
            return false;
        $type = $this->expand($type);
        $typesFromNode = $node->getType();
        if (!isset($typesFromNode))
            return false;
        if (is_array($typesFromNode)) {
            foreach ($typesFromNode as $t)
                if (is_a($t, 'ML\JsonLD\Node')
                    && $t->getId() == $type)
                return true;
        } else
        if (is_a($typesFromNode, 'ML\JsonLD\Node')
                && $typesFromNode->getId() == $type)
            return true;
        else
            return false;
        
        return false;
    }