code: protected function addTree(
          $name,
          $package,
          RepositoryInterface $installedRepo,
          RepositoryInterface $distantRepos,
          array $packagesInTree
      ) {
          $children = array();
          list($package, $versions) = $this->getPackage(
              $installedRepo,
              $distantRepos,
              $name,
              $package->getPrettyConstraint() === 'self.version' ? $package->getConstraint() : $package->getPrettyConstraint()
          );
          if (is_object($package)) {
              $requires = $package->getRequires();
              ksort($requires);
              foreach ($requires as $requireName => $require) {
                  $currentTree = $packagesInTree;
  
                  $treeChildDesc = array(
                      'name' => $requireName,
                      'version' => $require->getPrettyConstraint(),
                  );
  
                  if (!in_array($requireName, $currentTree, true)) {
                      $currentTree[] = $requireName;
                      $deepChildren = $this->addTree($requireName, $require, $installedRepo, $distantRepos, $currentTree);
                      if ($deepChildren) {
                          $treeChildDesc['requires'] = $deepChildren;
                      }
                  }
  
                  $children[] = $treeChildDesc;
              }
          }
  
          return $children;
      }
docs: Display a package tree
  
  @param  string                  $name
  @param  PackageInterface|string $package
  @param  RepositoryInterface     $installedRepo
  @param  RepositoryInterface     $distantRepos
  @param  array                   $packagesInTree
  @return array