protected function createTree(array $segments) : array
    {
        $nodes = array_map(function (TextSegment $segment) {
            $text = new TextNode($segment->getText());

            // Wrap text node in each tag from the innermost to the outermost.
            $tags = array_reverse($segment->getTags());
            return array_reduce($tags, function (Node $child, Tag $tag) {
                return new TagNode($tag, [$child]);
            }, $text);
        }, $segments);

        return $this->optimizeTree($nodes);
    }
protected function createTree(array $segments) : array
    {
        $nodes = array_map(function (TextSegment $segment) {
            $text = new TextNode($segment->getText());

            // Wrap text node in each tag from the innermost to the outermost.
            $tags = array_reverse($segment->getTags());
            return array_reduce($tags, function (Node $child, Tag $tag) {
                return new TagNode($tag, [$child]);
            }, $text);
        }, $segments);

        return $this->optimizeTree($nodes);
    }
protected function createTree ( array $ segments ) : array { $ nodes = array_map ( function ( TextSegment $ segment ) { $ text = new TextNode ( $ segment -> getText ( ) ) ; // Wrap text node in each tag from the innermost to the outermost. $ tags = array_reverse ( $ segment -> getTags ( ) ) ; return array_reduce ( $ tags , function ( Node $ child , Tag $ tag ) { return new TagNode ( $ tag , [ $ child ] ) ; } , $ text ) ; } , $ segments ) ; return $ this -> optimizeTree ( $ nodes ) ; }
Converts array of text segments to the tree of nodes.

@param TextSegment[] $segments

@return Node[]
Converts array of text segments to the tree of nodes .