/**
  * Execute the command
  *
  * @return  void
  *
  * @since   1.0
  */
 public function execute()
 {
     // Display status
     $this->app->out('Parsing the Composer data.');
     // Get the Composer data
     $helper = new Helper();
     $packages = $helper->parseComposer();
     // Insert the records into the database now
     foreach ($packages as $name => $package) {
         // Check to see if the package is already in the database
         $packageID = $this->db->setQuery($this->db->getQuery(true)->select($this->db->quoteName('id'))->from($this->db->quoteName('#__packages'))->where($this->db->quoteName('package') . ' = ' . $this->db->quote($name))->where($this->db->quoteName('version') . ' = ' . $this->db->quote($package['version'])))->loadResult();
         // If not present, insert it
         if (!$packageID) {
             $this->db->setQuery($this->db->getQuery(true)->insert($this->db->quoteName('#__packages'))->columns(array($this->db->quoteName('package'), $this->db->quoteName('version')))->values($this->db->quote($name) . ', ' . $this->db->quote($package['version'])))->execute();
         }
     }
     // Display status
     $this->app->out('Finished parsing Composer data.');
 }
 /**
  * Fetches the requested data
  *
  * @return  array
  *
  * @since   1.0
  */
 public function getItems()
 {
     // Parse installed.json to get the currently installed packages, should always be the latest version
     $helper = new Helper();
     $packages = $helper->parseComposer();
     $reports = array();
     // Get the package data for each of our packages
     $db = $this->getDb();
     $query = $db->getQuery(true)->select('*')->from($db->quoteName('#__packages'));
     foreach ($packages as $name => $package) {
         $query->where($db->quoteName('package') . ' = ' . $db->quote($name) . ' AND ' . $db->quoteName('version') . ' = ' . $db->quote($package['version']), 'OR');
     }
     $packs = $db->setQuery($query)->loadObjectList();
     // Loop through the packs and get the reports
     foreach ($packs as $pack) {
         $query->clear()->select('*')->from($db->quoteName('#__test_results'))->where($db->quoteName('package_id') . ' = ' . (int) $pack->id)->order('id DESC')->setLimit(1);
         $result = $db->setQuery($query)->loadObject();
         // If we didn't get any data, build a new object
         if (!$result) {
             $result = new \stdClass();
         } else {
             if ($result->total_lines > 0) {
                 $result->lines_percentage = round($result->lines_covered / $result->total_lines * 100, 2);
             } else {
                 $result->lines_percentage = 0;
             }
         }
         $result->displayName = $helper->getPackageDisplayName($pack->package);
         $result->version = $pack->version;
         // For repos with -api appended, handle separately
         if (in_array($pack->package, ['facebook', 'github', 'google', 'linkedin', 'twitter', 'openstreetmap'])) {
             $result->repoName = $pack->package . '-api';
         } else {
             $result->repoName = $pack->package;
         }
         $reports[$pack->package] = $result;
     }
     // Sort the array
     ksort($reports);
     return $reports;
 }
Example #3
0
 /**
  * Sanitize the system file path from the HTML coverage reports
  *
  * @param   string  $package  Package name
  *
  * @return  void
  *
  * @since   1.0
  */
 private function sanitizePaths($package)
 {
     // Display update to console
     $this->app->out('Sanitizing the file paths for the ' . $this->helper->getPackageDisplayName($package) . ' package code coverage report.');
     // Get the files
     $files = new \DirectoryIterator(JPATH_ROOT . '/www/coverage/' . $package);
     /* @type  $file  \DirectoryIterator */
     foreach ($files as $file) {
         // Only process HTML files
         if (!$file->isDot() && $file->getExtension() == 'html') {
             $data = file_get_contents(JPATH_ROOT . '/www/coverage/' . $package . '/' . $file->getFilename());
             // Clean out the path now
             if ($package == 'datetime') {
                 $data = str_replace(dirname(JPATH_ROOT) . '/Joomla-Framework/' . $package, '', $data);
             } else {
                 $data = str_replace(JPATH_ROOT . '/vendor/joomla/' . $package, '', $data);
             }
             // Write the sanitized file back
             file_put_contents(JPATH_ROOT . '/www/coverage/' . $package . '/' . $file->getFilename(), $data);
         }
     }
 }