You are here

public function MarkdownBenchmarkAverages::build in Markdown 3.0.x

1 call to MarkdownBenchmarkAverages::build()
MarkdownBenchmarkAverages::render in src/MarkdownBenchmarkAverages.php
Renders the object as a string.

File

src/MarkdownBenchmarkAverages.php, line 76

Class

MarkdownBenchmarkAverages
Class MarkdownBenchmarkAverages.

Namespace

Drupal\markdown

Code

public function build($type = 'total') {
  if (!$this
    ->hasBenchmarks()) {
    $build = MarkdownBenchmark::invalid();
    $title = $this
      ->t('No available benchmark tests.');
  }
  else {
    $build = $this
      ->getAverage($type);
    $iterations = $this
      ->getIterationCount() > 1 ? new FormattableMarkup('(@count<em>𝒙</em>) ', [
      '@count' => $this
        ->getIterationCount(),
    ]) : '';
    $variables = [
      '@iterations' => $iterations,
    ];
    if ($type !== 'all') {
      $variables += [
        '@parsed' => $this
          ->getAverage('parsed', TRUE),
        '@rendered' => $this
          ->getAverage('rendered', TRUE),
        '@total' => $this
          ->getAverage('total', TRUE),
      ];
    }
    switch ($type) {
      case 'all':
        $title = $this
          ->t('@iterationsParsed / Rendered / Total', $variables);
        break;
      case 'parsed':
        $title = $this
          ->t('@iterationsParsed (rendered @rendered, total @total)', $variables);
        break;
      case 'rendered':
        $title = $this
          ->t('@iterationsRendered (parsed @parsed, total @total)', $variables);
        break;

      // Total.
      default:
        $title = $this
          ->t('@iterationsTotal (parsed @parsed, rendered @rendered)', $variables);
        break;
    }
  }
  $build['#attributes']['data-toggle'] = 'tooltip';
  $build['#attributes']['data-placement'] = 'bottom';
  $build['#attributes']['title'] = $title;
  return $build;
}