function ContrivedController::handCount

Same name in other branches
  1. 8.x-1.x testing_example/src/Controller/ContrivedController.php \Drupal\testing_example\Controller\ContrivedController::handCount()
  2. 4.0.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 modules/testing_example/src/Controller/ContrivedController.php
A controller method which displays a sum in terms of hands.

File

modules/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;
}