You are here

private function HelpController::checkHelp in Security Review 8

Returns a check-specific help page.

Parameters

string $namespace: The namespace of the check.

string $title: The name of the check.

Return value

array The check's help page.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException If the check is not found.

1 call to HelpController::checkHelp()
HelpController::index in src/Controller/HelpController.php
Serves as an entry point for the help pages.

File

src/Controller/HelpController.php, line 147

Class

HelpController
The class of the Help pages' controller.

Namespace

Drupal\security_review\Controller

Code

private function checkHelp($namespace, $title) {

  // Get the requested check.
  $check = $this->checklist
    ->getCheck($namespace, $title);

  // If the check doesn't exist, throw 404.
  if ($check == NULL) {
    throw new NotFoundHttpException();
  }

  // Print the help page.
  $output = [];
  $output[] = $check
    ->help();

  // If the check is skipped print the skip message, else print the
  // evaluation.
  if ($check
    ->isSkipped()) {
    if ($check
      ->skippedBy() != NULL) {
      $user_object = $check
        ->skippedBy();
      $user = $user_object
        ->toLink()
        ->toString();
    }
    else {
      $user = 'Anonymous';
    }
    $skip_message = $this
      ->t('Check marked for skipping on @date by @user', [
      '@date' => $this->dateFormatter
        ->format($check
        ->skippedOn()),
      '@user' => $user,
    ]);
    $output[] = [
      '#type' => 'markup',
      '#markup' => "<p>{$skip_message}</p>",
    ];
  }
  else {

    // Evaluate last result, if any.
    $last_result = $check
      ->lastResult(TRUE);
    if ($last_result instanceof CheckResult) {

      // Separator.
      $output[] = [
        '#type' => 'markup',
        '#markup' => '<div />',
      ];

      // Evaluation page.
      $output[] = $check
        ->evaluate($last_result);
    }
  }

  // Return the completed page.
  return $output;
}