You are here

abstract class SecurityReviewSiteAuditCheckAbstract in Security Review 7

Class SecurityReviewSiteAuditCheckAbstract

Hierarchy

Expanded class hierarchy of SecurityReviewSiteAuditCheckAbstract

File

./security_review.site_audit.inc, line 10
Contains \SiteAudit\Check\Security security_review checks.

View source
abstract class SecurityReviewSiteAuditCheckAbstract extends SiteAuditCheckAbstract {

  /**
   * The implementing module.
   * @var string
   */
  protected $module = 'security_review';

  /**
   * The check in question.
   * @var string
   */
  protected $check;

  /**
   * Implements \SiteAudit\Check\Abstract\getLabel().
   */
  public function getLabel() {
    $checks = security_review_get_checklist();
    return $checks[$this->module][$this->check]['title'];
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getDescription().
   */
  public function getDescription() {
    $checks = security_review_get_checklist();
    return dt('Security Check of @title', array(
      '@title' => $checks[$this->module][$this->check]['title'],
    ));
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultFail().
   */
  public function getResultFail() {
    $ret_val = $this->registry[$this->module][$this->check]['failure'];
    if (isset($this->registry[$this->module][$this->check]['value'])) {
      if (is_array($this->registry[$this->module][$this->check]['value'])) {
        $ret_val .= $this
          ->generateUl($this->registry[$this->module][$this->check]['value'], drush_get_option('html'));
      }
      elseif ($this->registry[$this->module][$this->check]['value']) {
        $ret_val .= ' Additional: "' . $this->registry[$this->module][$this->check]['value'] . '"';
      }
    }
    return $ret_val;
  }

  /**
   * Generates an unordered list or flattened text version of a nested array.
   *
   * @param array $array
   *   Security Review results.
   * @param bool $html
   *   TRUE if the result should be rendered as HTML.
   * @param int $indentation
   *   The number of spaces; defaults to 6.
   *
   * @return string
   *   Formatted result.
   */
  private function generateUl($array, $html = TRUE, $indentation = 6) {
    $result = $html ? '<ul>' : '';
    foreach ($array as $key => $value) {
      $result .= $html ? '<li>' : PHP_EOL . str_repeat(' ', $indentation);
      $result .= $key . ': ';
      if (is_array($value)) {
        $result .= $this
          ->generateUl($value, $html, $indentation + 2);
      }
      elseif (isset($value->name) && $value->name) {
        $result .= $value->name;
      }
      elseif ($value) {
        $result .= $value;
      }
      $result .= $html ? '</li>' : '';
    }
    $result .= $html ? '</ul>' : '';
    return $result;
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultInfo().
   */
  public function getResultInfo() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultPass().
   */
  public function getResultPass() {
    return $this->registry[$this->module][$this->check]['success'];
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultWarn().
   */
  public function getResultWarn() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getAction().
   */
  public function getAction() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\calculateScore().
   */
  public function calculateScore() {
    $checks = security_review_get_checklist();
    $checklist_results = security_review_run(array(
      $this->module => array(
        $checks[$this->module][$this->check],
      ),
    ));
    $this->registry[$this->module][$this->check] = $checklist_results['security_review'][0];
    if (!$this->registry[$this->module][$this->check]['result']) {
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL;
    }
    else {
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SecurityReviewSiteAuditCheckAbstract::$check protected property The check in question. 10
SecurityReviewSiteAuditCheckAbstract::$module protected property The implementing module.
SecurityReviewSiteAuditCheckAbstract::calculateScore public function Implements \SiteAudit\Check\Abstract\calculateScore(). Overrides SiteAuditCheckAbstract::calculateScore
SecurityReviewSiteAuditCheckAbstract::generateUl private function Generates an unordered list or flattened text version of a nested array.
SecurityReviewSiteAuditCheckAbstract::getAction public function Implements \SiteAudit\Check\Abstract\getAction(). Overrides SiteAuditCheckAbstract::getAction
SecurityReviewSiteAuditCheckAbstract::getDescription public function Implements \SiteAudit\Check\Abstract\getDescription(). Overrides SiteAuditCheckAbstract::getDescription
SecurityReviewSiteAuditCheckAbstract::getLabel public function Implements \SiteAudit\Check\Abstract\getLabel(). Overrides SiteAuditCheckAbstract::getLabel
SecurityReviewSiteAuditCheckAbstract::getResultFail public function Implements \SiteAudit\Check\Abstract\getResultFail(). Overrides SiteAuditCheckAbstract::getResultFail 1
SecurityReviewSiteAuditCheckAbstract::getResultInfo public function Implements \SiteAudit\Check\Abstract\getResultInfo(). Overrides SiteAuditCheckAbstract::getResultInfo
SecurityReviewSiteAuditCheckAbstract::getResultPass public function Implements \SiteAudit\Check\Abstract\getResultPass(). Overrides SiteAuditCheckAbstract::getResultPass
SecurityReviewSiteAuditCheckAbstract::getResultWarn public function Implements \SiteAudit\Check\Abstract\getResultWarn(). Overrides SiteAuditCheckAbstract::getResultWarn
SiteAuditCheckAbstract::$abort protected property Indicate that no other checks should be run after this check.
SiteAuditCheckAbstract::$optOut protected property User has opted out of this check in configuration.
SiteAuditCheckAbstract::$percentOverride protected property If set, will override the Report's percentage.
SiteAuditCheckAbstract::$registry protected property Use for passing data between checks within a report.
SiteAuditCheckAbstract::$score protected property Quantifiable number associated with result on a scale of 0 to 2.
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL constant
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO constant
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS constant
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN constant
SiteAuditCheckAbstract::getPercentOverride public function Get the report percent override, if any.
SiteAuditCheckAbstract::getRegistry public function Get the check registry.
SiteAuditCheckAbstract::getRelativePath public function Gives path relative to DRUPAL_ROOT of the path is inside Drupal.
SiteAuditCheckAbstract::getResult public function Determine the result message based on the score.
SiteAuditCheckAbstract::getScore public function Get a quantifiable number representing a check result; lazy initialization.
SiteAuditCheckAbstract::getScoreCssClass public function Get the CSS class associated with a score.
SiteAuditCheckAbstract::getScoreDrushLevel public function Get the Drush message level associated with a score.
SiteAuditCheckAbstract::getScoreLabel public function Get a human readable label for a score.
SiteAuditCheckAbstract::renderAction public function Display action items for a user to perform.
SiteAuditCheckAbstract::shouldAbort public function Determine whether the check failed so badly that the report must stop.
SiteAuditCheckAbstract::__construct public function Constructor.