public function convertRepositoryToArray(
        RepositoryInterface $repository,
        $requiredOnly = false,
        RepositoryInterface $upgradeList = null
    ) {
        $requires = $requiredOnly ? $this->rootPackage->getRequires() : false;
        $packages = new JsonArray();
        /** @var \Composer\Package\PackageInterface $package */
        foreach ($repository->getPackages() as $package) {
            $name = $package->getPrettyName();
            $esc  = $packages->escape($name);
            if (false === $requires || (isset($requires[$name]))) {
                $upgradePkg = null;
                if ($upgradeList) {
                    $upgradePkg = $upgradeList->findPackage($name, '*');
                }
                $packages->set(
                    $esc,
                    $this->convertPackageToArray($package, $upgradePkg)->getData()
                );
            }
        }

        return $packages;
    }