code: protected function generateTree(array $nodes, $parentId)
      {
          if (empty($nodes)) {
              return array();
          }
  
          $nodesRoot = array_filter($nodes, function($node, $key) use ($parentId) {
              $property = 'nodeId';
              if (NodeInterface::ROOT_PARENT_ID === $parentId) {
                  $property = 'parentId';
              }
              if ($parentId !== $node['node'][$property]) {
                  return false;
              }
              return true;
          }, ARRAY_FILTER_USE_BOTH);
  
          $tree = array();
          foreach ($nodesRoot as $nodeRoot) {
              $tree[] = array('node' => $nodeRoot['node'], 'child' => $this->getChildren($nodeRoot['nodeId'], $nodes));
          }
          uasort($tree, array($this, 'sortTree'));
          $tree = array_values($tree);
  
          return $tree;
      }
docs: @param array  $nodes
  @param string $parentId
  
  @return array