Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TrackerService
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 writeLog
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Drupal\visitors\Service;
4
5use Drupal\Core\Database\Connection;
6use Drupal\visitors\VisitorsTrackerInterface;
7
8/**
9 * Tracker for web analytics.
10 */
11class TrackerService implements VisitorsTrackerInterface {
12
13  /**
14   * The database connection.
15   *
16   * @var \Drupal\Core\Database\Connection
17   */
18  protected $database;
19
20  /**
21   * Tracks visits and actions.
22   *
23   * @param \Drupal\Core\Database\Connection $database
24   *   The database connection.
25   */
26  public function __construct(Connection $database) {
27    $this->database = $database;
28  }
29
30  /**
31   * {@inheritdoc}
32   */
33  public function writeLog($fields): int {
34    $id = $this->database->insert('visitors')
35      ->fields($fields)
36      ->execute();
37
38    return $id;
39  }
40
41}