You are here

function _security_review_drush_format_results in Security Review 8

Helper function to compile Security Review results.

Parameters

\Drupal\security_review\CheckResult[] $results: An array of CheckResults.

bool $short_titles: Whether to use short message (check title) or full check success or failure message.

bool $show_findings: Whether to print failed check results.

Return value

array The results of the security review checks.

1 call to _security_review_drush_format_results()
security_review_drush in ./security_review.drush.inc
Runs a checklist and displays results.

File

./security_review.drush.inc, line 201
Drush commands for Security Review module.

Code

function _security_review_drush_format_results(array $results, $short_titles = FALSE, $show_findings = FALSE) {
  $output = [];
  foreach ($results as $result) {
    if ($result instanceof CheckResult) {
      if (!$result
        ->isVisible()) {

        // Continue with the next check.
        continue;
      }
      $check = $result
        ->check();
      $message = $short_titles ? $check
        ->getTitle() : $result
        ->resultMessage();
      $status = 'notice';

      // Set log level according to check result.
      switch ($result
        ->result()) {
        case CheckResult::SUCCESS:
          $status = 'success';
          break;
        case CheckResult::FAIL:
          $status = 'failed';
          break;
        case CheckResult::WARN:
          $status = 'warning';
          break;
        case CheckResult::INFO:
          $status = 'info';
          break;
      }

      // Attach findings.
      if ($show_findings) {
        $findings = trim($result
          ->check()
          ->evaluatePlain($result));
        if ($findings != '') {
          $message .= "\n" . $findings;
        }
      }
      $output[$check
        ->id()] = [
        'message' => (string) $message,
        'status' => $status,
        'findings' => $result
          ->findings(),
      ];
    }
  }
  return $output;
}