/** * Walk the tree and register comments in the corresponding collections. * * @param array $nodes * @param Comment $parent */ protected function walk(&$nodes, $parent = null) { $collection = $parent instanceof Comment ? $parent->children() : $this; foreach ($nodes as $entry) { $node = $entry['node']; $children =& $entry['children']; $node->parent($parent); $collection->set($node->id(), $node); if (!empty($children)) { $this->walk($children, $node); } } }