@param array $nodes

@return array
169340
public function generateTree($nodes)
    {
        $superRoot = count(array_filter($nodes, function (ReadNodeInterface $node) {
            return '-' == $node->getParentId();
        }))? '-': 'root';

        $list = array();
        $list[$superRoot] = array();
        foreach ($nodes as $node) {
            if ($superRoot !== $node->getParentId() && $this->parentInList($node->getParentId(), $nodes)) {
                $list[$node->getParentId()][] = $node;
                continue;
            }
            $list[$superRoot][] = $node;
        }

        $tree = $this->createTree($list[$superRoot], $list);

        return $tree;
    }
928717
private function getTopNodeByScore(array $nodes): ?Element {
        $topNode = null;
        $topNodeScore = 0;

        foreach ($nodes as $node) {
            $score = $this->getScore($node);

            if ($score > $topNodeScore) {
                $topNode = $node;
                $topNodeScore = $score;
            }

            if ($topNode === false) {
                $topNode = $node;
            }
        }

        if ($topNode && $this->getScore($topNode) < 20) {
            return null;
        }

        return $topNode;
    }
957729
protected function wrapOptions(array $nodes)
	{
		$ret = array();

		foreach ( $nodes as $node_element ) {
			/** @var SelectOption $option */
			$option = SelectOption::fromNodeElement($node_element, $this->getPageFactory());
			$ret[] = $option->setSelect($this);
		}

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

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

        return $result;
    }
532376
public function addNodes(array $nodes): self
    {
        foreach ($nodes as $node) {
            $this->addNode($node);
        }

        return $this;
    }
872138
public function getPropertiesArray(NodeInterface $node)
    {
        $properties = [];
        foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) {
            if ($propertyName[0] === '_' && $propertyName[1] === '_') {
                // skip fully-private properties
                continue;
            }

            $properties[$propertyName] = $this->getProperty($node, $propertyName);
        }

        return $properties;
    }
960349
protected function convertNodes(Array $nodes, $em) {
    // our test project (this) is defined to have only de as i18n but dont get confused, these are english wordings
    $navigationNodes = array();

    foreach ($nodes as $node) {
      $node = (object) $node;
      $navigationNode = $this->createNode(array('de'=>$node->title));
      $navigationNode->setContext($this->context);
      $navigationNode->generateSlugs();

      $page = $this->createPage($navigationNode->getSlug('de'));
      $page->setActive(TRUE);
      $em->persist($page);

      $navigationNode->setPage($page);

      $navigationNodes[$navigationNode->getTitle('de')] = $navigationNode;
    }

    foreach ($nodes as $node) {
      $node = (object) $node;

      if (isset($node->parent)) {
        $navigationNodes[$node->title]->setParent($navigationNodes[$node->parent]);
      }
    }

    return $navigationNodes;
  }
684656
public function expandResources(array $nodes)
    {
        $dirs = [];
        $ress = [];
        $toAppend = [];

        foreach ($nodes as $node) {
            $resourceTypeName = $node->getResourceType()->getName();
            ('directory' === $resourceTypeName) ? $dirs[] = $node : $ress[] = $node;
        }

        foreach ($dirs as $dir) {
            $children = $this->getDescendants($dir);

            foreach ($children as $child) {
                if ($child->isActive() &&
                    'directory' !== $child->getResourceType()->getName()) {
                    $toAppend[] = $child;
                }
            }
        }

        $merge = array_merge($toAppend, $ress);

        return $merge;
    }
1331937
private function buildArrayFromNode(SimpleXMLElement $node): array
    {
        $array = [];
        foreach ($node->children() as $child) {
            if ((string) $child !== '') {
                $array[] = (string) $child;
            }
        }

        return $array;
    }
30393
protected function createNodes($nodes)
    {
        // $parent is the array of parent nodes.
        $parent = [];

        foreach ($nodes as $load_record) {
            $match = preg_match('/^\*+/', $load_record, $matches);

            // If there is no match then we have hit a top level category.
            // Add this to the $result array and reset the $parent array.
            if ($match === 0) {
                $node_name = trim($load_record);
                $root_node = Category::create([
                    'name'          => $node_name,
                    'description'   => $node_name,
                ]);

                $parent = [
                    0   => $root_node,
                ];
                continue;
            }

            // If there is a match then check how many levels deep we are.
            $levels = strlen($matches[0]);

            // Grab the node name
            $node_name = trim(substr($load_record, $levels));

            // Grab the current node at the level of the parent.
            /** @var Category $current */
            $current = $parent[$levels - 1];

            // Add this node as a child of the parent.
            $child_node = $current->children()->create([
                'name' => $node_name
            ]);

            // Update the description, just for fun
            $child_node->description = $child_node->path;
            $child_node->save();

            // Store this node name as a potential future parent.
            $parent[$levels] = $child_node;
        }
    }
391663
protected function nodeToArray($node)
    {
        $output = array();
        switch ($node->nodeType) {
            case XML_CDATA_SECTION_NODE:
            case XML_TEXT_NODE:
                $output = trim($node->textContent);
                break;
            case XML_ELEMENT_NODE:
                for ($i = 0, $m = $node->childNodes->length; $i < $m; $i++) {
                    $child = $node->childNodes->item($i);
                    $value = $this->nodeToArray($child);
                    if (isset($child->tagName)) {
                        $tag = $child->tagName;
                        if (!isset($output[$tag])) {
                            $output[$tag] = array();
                        }
                        $output[$tag][] = $value;
                    } elseif ($value || $value === '0') {
                        $output = (string) $value;
                    }
                }

                // Edge case of a node containing a text node, which also has
                // attributes. this way we'll retain text and attributes for
                // this node.
                if (is_string($output) && $node->attributes->length) {
                    $output = array('@text' => $output);
                }

                if (is_array($output)) {
                    if ($node->attributes->length) {
                        $attributes = array();
                        foreach ($node->attributes as $attrName => $attrNode) {
                            $attributes[$attrName] = (string) $attrNode->value;
                        }
                        $output['@attributes'] = $attributes;
                    }
                    foreach ($output as $tag => $value) {
                        if (is_array($value) && count($value) == 1 && $tag != '@attributes') {
                            $output[$tag] = $value[0];
                        }
                    }
                }
                break;
        }

        return $output;
    }
970958
public static function getRootPageIdsFromSites(array $sites): array
    {
        $rootPageIds = [];
        foreach ($sites as $site) {
            $rootPageIds[] = (int)$site->getRootPageId();
        }

        return $rootPageIds;
    }
242157
protected function getQueryNodes(AbstractNode $node): array
    {
        $methodPostfix = $node->findChildrenOfType('MethodPostfix');
        $classOrInterfaceReference = $node->findChildrenOfType('ClassOrInterfaceReference');

        return array_merge($methodPostfix, $classOrInterfaceReference);
    }
1173785
private function createSubCrawler($nodes)
    {
        $crawler = new static($nodes, $this->uri, $this->baseHref);
        $crawler->isHtml = $this->isHtml;
        $crawler->document = $this->document;
        $crawler->namespaces = $this->namespaces;
        $crawler->html5Parser = $this->html5Parser;

        return $crawler;
    }
731976
private function getUris($nodes)
    {
        $uris = [];

        if ($nodes instanceof core_kernel_classes_Resource) {
            $uris[] = $nodes->getUri();
        }
        if(is_array($nodes)){

            //legacy format
            if (isset($nodes['attributes']['data-uri'])) {
                $uris[] = $nodes['attributes']['data-uri'];
            }
            if (isset($nodes['uri'])) {
                $uris[] = $nodes['uri'];
            }

            $treeKeys = array_keys($nodes);
            if (isset($treeKeys[0]) && is_int($treeKeys[0])) {
                foreach ($nodes as $node) {
                    $uris = array_merge($uris, $this->getUris($node));

                }
            }

            if (isset($nodes['children'])) {
                $uris = array_merge($uris, $this->getUris($nodes['children']));
            }
        }

        return $uris;
    }
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;
    }
676688
private function getNodeIndex( $node )
	{
		for( $i=0; $i<$this->count(); $i++ )
			if( $this->nodes[$i] == $node )
				return $i;
		return NULL;
	}