You are here

protected function ContrivedController::handCount in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/testing_example/src/Controller/ContrivedController.php \Drupal\testing_example\Controller\ContrivedController::handCount()

Generate a message based on how many hands are needed to count the sum.

Parameters

int $first: First parameter.

int $second: Second parameter.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup The translated message.

1 call to ContrivedController::handCount()
ContrivedController::displayAddedNumbers in testing_example/src/Controller/ContrivedController.php
A controller method which displays a sum in terms of hands.

File

testing_example/src/Controller/ContrivedController.php, line 64

Class

ContrivedController
A highly-contrived controller class used to demonstrate unit testing.

Namespace

Drupal\testing_example\Controller

Code

protected function handCount($first, $second) {
  $sum = abs($this
    ->add((int) $first, (int) $second));
  if ($sum <= 5) {
    $message = $this
      ->t('I can count these on one hand.');
  }
  elseif ($sum <= 10) {
    $message = $this
      ->t('I need two hands to count these.');
  }
  else {
    $message = $this
      ->t("That's just too many numbers to count.");
  }
  return $message;
}