public function SiteAuditReportBase::__construct in Site Audit 8.3
Constructor.
Parameters
array $registry: Aggregates data from each individual check.
bool $opt_out: If set, will not perform checks.
Overrides PluginBase::__construct
File
- src/
Plugin/ SiteAuditReportBase.php, line 96
Class
- SiteAuditReportBase
- Base class for Site Audit Report plugins.
Namespace
Drupal\site_audit\PluginCode
public function __construct($configuration, $plugin_id, $plugin_definition) {
$checkManager = \Drupal::service('plugin.manager.site_audit_check');
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->registry = new \stdClass();
$percent_override = NULL;
$checks_to_skip = [];
$checks_to_perform = $this
->getChecksList();
foreach ($checks_to_perform as $key => $check_name) {
if (in_array($key, $checks_to_skip)) {
unset($checks_to_perform[$key]);
}
}
if (empty($checks_to_perform)) {
$this_def = $this
->getPluginDefinition();
// Throw new \RuntimeException(t('No checks are available for report \'@id\'!', ['@id' => $this_def['id']]));.
}
$config = \Drupal::config('site_audit');
foreach ($checks_to_perform as $check_id) {
$opt_out = $config
->get('opt_out.' . $this
->getPluginId() . $check_id) != NULL;
$check = $checkManager
->createInstance($check_id, [
'registry' => $this->registry,
'opt_out' => $opt_out,
'options' => $this->configuration,
]);
// Calculate score.
if ($check
->getScore() != SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO) {
// Mark if there's a major failure.
if ($check
->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL) {
$this->hasFail = TRUE;
}
// Total.
$this->scoreTotal += $check
->getScore();
// Maximum.
$this->scoreMax += SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS;
}
// Allow Report percentage to be overridden.
if ($check
->getPercentOverride()) {
$percent_override = $check
->getPercentOverride();
}
// Store all checks.
$this->checks[$check_id] = $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);
}
}
}