You are here

public function SiteAuditReportAbstract::__construct in Site Audit 7

Same name and namespace in other branches
  1. 8.2 Report/Abstract.php \SiteAuditReportAbstract::__construct()

Constructor; loads and executes checks based on the name of this report.

1 call to SiteAuditReportAbstract::__construct()
SiteAuditReportInsights::__construct in Report/Insights.php
Override parent constructor to provide argument support.
1 method overrides SiteAuditReportAbstract::__construct()
SiteAuditReportInsights::__construct in Report/Insights.php
Override parent constructor to provide argument support.

File

Report/Abstract.php, line 67
Contains \SiteAudit\Report\Abstract.

Class

SiteAuditReportAbstract
Class SiteAuditReportAbstract.

Code

public function __construct() {
  global $conf;
  $base_class_name = 'SiteAuditCheck' . $this
    ->getReportName();
  $percent_override = NULL;
  $checks_to_skip = array();
  if (drush_get_option('skip')) {
    $checks_to_skip = explode(',', drush_get_option('skip'));
  }
  $checks_to_perform = $this
    ->getCheckNames();
  foreach ($checks_to_perform as $key => $check_name) {
    if (in_array($this
      ->getReportName() . $check_name, $checks_to_skip)) {
      unset($checks_to_perform[$key]);
    }
  }
  if (empty($checks_to_perform)) {

    // No message for audit_all.
    $command = drush_parse_command();
    if ($command['command'] == 'audit_all') {
      return FALSE;
    }
    return drush_set_error('SITE_AUDIT_NO_CHECKS', dt('No checks are available!'));
  }
  foreach ($checks_to_perform as $check_name) {
    $class_name = $base_class_name . $check_name;
    $check = new $class_name($this->registry, isset($conf['site_audit']['opt_out'][$this
      ->getReportName() . $check_name]));

    // Calculate score.
    if ($check
      ->getScore() != SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO) {

      // Mark if there's a major failure.
      if ($check
        ->getScore() == SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL) {
        $this->hasFail = TRUE;
      }

      // Total.
      $this->scoreTotal += $check
        ->getScore();

      // Maximum.
      $this->scoreMax += SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
    }

    // Allow Report percentage to be overridden.
    if ($check
      ->getPercentOverride()) {
      $percent_override = $check
        ->getPercentOverride();
    }

    // Combine registry.
    $this->registry = array_merge($this->registry, $check
      ->getRegistry());

    // Store all checks.
    $this->checks[$class_name] = $check;

    // Abort the loop if the check says to bail.
    if ($check
      ->shouldAbort()) {
      break;
    }
  }
  if ($percent_override) {
    $this->percent = $percent_override;
  }
  else {
    if ($this->scoreMax != 0) {
      $this->percent = round($this->scoreTotal / $this->scoreMax * 100);
    }
    else {
      $this->percent = SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
    }
  }
}