/**
  * Method collects an extended package data from packagist.org and github.com
  * other services are not supported yet.
  *
  * @return \DevGroup\AdminUtils\response\AjaxResponse|string
  * @throws NotFoundHttpException
  */
 public function actionDetails()
 {
     if (false === Yii::$app->request->isAjax) {
         throw new NotFoundHttpException("Page not found");
     }
     $module = ExtensionsManager::module();
     $packageName = Yii::$app->request->post('packageName');
     $packagist = self::getPackagist();
     $package = $packagist->get($packageName);
     $repository = $package->getRepository();
     $packagistVersions = $package->getVersions();
     $readme = '';
     $versionsData = $dependencies = [];
     if (true === self::isGit($repository)) {
         $repository = preg_replace(['%^.*github.com\\/%', '%\\.git$%'], '', $repository);
         $gitAccessToken = $module->githubAccessToken;
         $gitApiUrl = rtrim($module->githubApiUrl, '/');
         $applicationName = $module->applicationName;
         $headers = ['User-Agent: ' . $applicationName];
         if (false === empty($gitAccessToken)) {
             $headers[] = 'Authorization: token ' . $gitAccessToken;
         }
         $gitReadmeUrl = $gitApiUrl . '/repos/' . $repository . '/readme';
         $gitReleasesUrl = $gitApiUrl . '/repos/' . $repository . '/releases';
         $readmeData = self::doRequest($gitReadmeUrl, $headers);
         $readme = ExtensionDataHelper::humanizeReadme($readmeData);
         $versionsData = Json::decode(self::doRequest($gitReleasesUrl, $headers));
         if (true === empty($versionsData)) {
             $gitTagsUrl = $gitApiUrl . '/repos/' . $repository . '/tags';
             $versionsData = Json::decode(self::doRequest($gitTagsUrl, $headers));
         }
     }
     //ExtensionDataHelper::getVersions() must be invoked before other methods who fetches versioned data
     $versions = ExtensionDataHelper::getVersions($packagistVersions, array_shift($versionsData));
     $jsonUrl = rtrim($module->packagistUrl, '/') . '/packages/' . trim($packageName, '/ ') . '.json';
     $packageJson = self::doRequest($jsonUrl);
     $packageData = Json::decode($packageJson);
     $type = ExtensionDataHelper::getType($packageData);
     return $this->renderResponse('_ext-details', ['readme' => $readme, 'versions' => $versions, 'description' => ExtensionDataHelper::getLocalizedVersionedDataField($packageData, Extension::TYPE_YII, 'description'), 'name' => ExtensionDataHelper::getLocalizedVersionedDataField($packageData, Extension::TYPE_YII, 'name'), 'dependencies' => ['require' => ExtensionDataHelper::getOtherPackageVersionedData($packageData, 'require'), 'require-dev' => ExtensionDataHelper::getOtherPackageVersionedData($packageData, 'require-dev')], 'authors' => ExtensionDataHelper::getOtherPackageVersionedData($packageData, 'authors'), 'license' => ExtensionDataHelper::getOtherPackageVersionedData($packageData, 'license'), 'packageName' => $packageName, 'installed' => array_key_exists($packageName, $module->getExtensions()), 'type' => $type]);
 }
 public function testGetLocalizedVersionedDataFieldExtraPackageField()
 {
     Yii::$app->language = 'zn';
     $description = ExtensionDataHelper::getLocalizedVersionedDataField(Json::decode(file_get_contents(__DIR__ . '/../../data/no-version-package.json')), Extension::TYPE_YII, 'description');
     $expected = 'description';
     $this->assertEquals($expected, $description);
 }