You are here

private function SecurityReviewCommands::formatResults 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 SecurityReviewCommands::formatResults()
SecurityReviewCommands::securityReview in src/Commands/SecurityReviewCommands.php
Run the Security Review checklist.

File

src/Commands/SecurityReviewCommands.php, line 195

Class

SecurityReviewCommands
Class SecurityReviewCommands.

Namespace

Drupal\security_review\Commands

Code

private function formatResults(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;
}