Completed
Push — master ( e41e63...2cec7d )
by Mariano
03:44
created

GoogleClassicAnalytics::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of phpab/phpab. (https://github.com/phpab/phpab)
4
 *
5
 * @link https://github.com/phpab/phpab for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab/master/LICENSE.md MIT
8
 */
9
10
namespace PhpAb\Analytics\Renderer\Google;
11
12
/**
13
 * This class will only work for Classic Analytics Experiments ran as External
14
 *
15
 * @package PhpAb
16
 * @see https://developers.google.com/analytics/devguides/collection/gajs/experiments#cxjs-setchosen
17
 */
18
class GoogleClassicAnalytics extends AbstractGoogleAnalytics
19
{
20
    /**
21
     * The map with test identifiers and variation indexes.
22
     *
23
     * @var array
24
     */
25
    private $participations = [];
26
27
    /**
28
     * Initializes a new instance of this class.
29
     *
30
     * @param array $participations
31
     */
32 3
    public function __construct(array $participations)
33
    {
34 3
        $this->participations = $participations;
35 3
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 2
    public function getScript()
41
    {
42 2
        if (empty($this->participations)) {
43 1
            return '';
44
        }
45
46 1
        $script = [];
47
48 1
        $script[] = '<script>';
49
50 1
        foreach ($this->participations as $testIdentifier => $variationIndex) {
51 1
            $script[] = "cxApi.setChosenVariation(" . (int) $variationIndex . ", '" . (string) $testIdentifier . "')";
52 1
        }
53
54 1
        $script[] = '</script>';
55
56 1
        return implode("\n", $script);
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62 1
    public function getParticipations()
63
    {
64
65 1
        return $this->participations;
66
    }
67
}
68