You are here

public function SiteAuditCheckStatusSystem::calculateScore in Site Audit 8.2

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

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

Overrides SiteAuditCheckAbstract::calculateScore

File

Check/Status/System.php, line 140
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 . '/core/includes/install.inc';
  drupal_load_updates();

  // Check run-time requirements and status information.
  $this->registry['requirements'] = \Drupal::moduleHandler()
    ->invokeAll('requirements', array(
    'runtime',
  ));
  usort($this->registry['requirements'], function ($a, $b) {
    if (!isset($a['weight'])) {
      if (!isset($b['weight'])) {
        return strcmp($a['title'], $b['title']);
      }
      return -$b['weight'];
    }
    return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
  });
  $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;
}