You are here

public function SiteAuditCheckStatusSystem::calculateScore in Site Audit 7

Same name and namespace in other branches
  1. 8.2 Check/Status/System.php \SiteAuditCheckStatusSystem::calculateScore()

Implements \SiteAudit\Check\Abstract\calculateScore().

Overrides SiteAuditCheckAbstract::calculateScore

File

Check/Status/System.php, line 149
Contains \SiteAudit\Check\Status\System.

Class

SiteAuditCheckStatusSystem
Class SiteAuditCheckStatusSystem.

Code

public function calculateScore() {

  // See system/system.admin.inc function system_status().
  // Load .install files.
  include_once DRUPAL_ROOT . '/includes/install.inc';
  drupal_load_updates();

  // Check run-time requirements and status information.
  $this->registry['requirements'] = module_invoke_all('requirements', 'runtime');
  usort($this->registry['requirements'], '_system_sort_requirements');
  $this->percentOverride = 0;
  $requirements_with_severity = array();
  foreach ($this->registry['requirements'] as $key => $value) {
    if (isset($value['severity'])) {
      $requirements_with_severity[$key] = $value;
    }
  }
  $score_each = 100 / count($requirements_with_severity);
  $worst_severity = REQUIREMENT_INFO;
  foreach ($this->registry['requirements'] as $requirement) {
    if (isset($requirement['severity'])) {
      if ($requirement['severity'] > $worst_severity) {
        $worst_severity = $requirement['severity'];
      }
      if ($requirement['severity'] == REQUIREMENT_WARNING) {
        $this->percentOverride += $score_each / 2;
      }
      elseif ($requirement['severity'] != REQUIREMENT_ERROR) {
        $this->percentOverride += $score_each;
      }
    }
  }
  $this->percentOverride = round($this->percentOverride);
  if ($this->percentOverride > 80) {
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
  }
  elseif ($this->percentOverride > 60) {
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN;
  }
  return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL;
}