Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
HitDetails
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 create
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 display
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Drupal\visitors\Controller\Report;
4
5use Drupal\Core\Controller\ControllerBase;
6use Drupal\Core\Datetime\DateFormatterInterface;
7use Drupal\visitors\VisitorsReportInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
10/**
11 * Hit Detail Report controller.
12 */
13final class HitDetails extends ControllerBase {
14  /**
15   * The date service.
16   *
17   * @var \Drupal\Core\Datetime\DateFormatterInterface
18   */
19  protected $date;
20
21  /**
22   * The report service.
23   *
24   * @var \Drupal\visitors\VisitorsReportInterface
25   */
26  protected $report;
27
28  /**
29   * {@inheritdoc}
30   */
31  public static function create(ContainerInterface $container): HitDetails {
32    return new self(
33      $container->get('date.formatter'),
34      $container->get('visitors.report')
35    );
36  }
37
38  /**
39   * Constructs a HitDetails object.
40   *
41   * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
42   *   The date service.
43   * @param \Drupal\visitors\VisitorsReportInterface $report_service
44   *   The report service.
45   */
46  public function __construct(DateFormatterInterface $date_formatter, VisitorsReportInterface $report_service) {
47    $this->date = $date_formatter;
48    $this->report = $report_service;
49  }
50
51  /**
52   * Returns a hit details page.
53   *
54   * @return array
55   *   A render array representing the hit details page content.
56   */
57  public function display($hit_id): array {
58    return [
59      'visitors_table' => [
60        '#type' => 'table',
61        '#rows'  => $this->report->hitDetails($hit_id),
62      ],
63    ];
64  }
65
66}