You are here

protected function MaxAgeCheck::valueTranslatable in Purge 8.3

Return a user-facing string that represents the given max_age value.

Parameters

int $max_age: The max_age setting to format.

Return value

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

1 call to MaxAgeCheck::valueTranslatable()
MaxAgeCheck::run in src/Plugin/Purge/DiagnosticCheck/MaxAgeCheck.php
Perform the check and determine the severity level.

File

src/Plugin/Purge/DiagnosticCheck/MaxAgeCheck.php, line 98

Class

MaxAgeCheck
Tests if the TTL of your site is in a good shape.

Namespace

Drupal\purge\Plugin\Purge\DiagnosticCheck

Code

protected function valueTranslatable($max_age) {
  if ($max_age === 0) {
    return $this
      ->t('no caching');
  }
  elseif ($max_age === 60) {
    return $this
      ->t('1 minute');
  }
  elseif ($max_age < 3600) {
    return $this
      ->t('@num minutes', [
      '@num' => round($max_age / 60),
    ]);
  }
  elseif ($max_age === 3600) {
    return $this
      ->t('1 hour');
  }
  elseif ($max_age < 86400) {
    return $this
      ->t('@num hours', [
      '@num' => round($max_age / 3600, 1),
    ]);
  }
  elseif ($max_age === 86400) {
    return $this
      ->t('1 day');
  }
  elseif ($max_age < 604800) {
    return $this
      ->t('@num days', [
      '@num' => round($max_age / 86400, 1),
    ]);
  }
  elseif ($max_age === 604800) {
    return $this
      ->t('1 week');
  }
  elseif ($max_age < 2764800) {
    return $this
      ->t('@num weeks', [
      '@num' => round($max_age / 604800, 1),
    ]);
  }
  elseif ($max_age === 2764800) {
    return $this
      ->t('1 month');
  }
  elseif ($max_age < 31536000) {
    return $this
      ->t('@num months', [
      '@num' => round($max_age / 2764800, 1),
    ]);
  }
  elseif ($max_age === 31536000) {
    return $this
      ->t('1 year');
  }
  return $this
    ->t('more than 1 year');
}