CreateCommand::generate()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.009

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 13
cts 14
cp 0.9286
rs 9.1768
c 0
b 0
f 0
cc 5
nc 16
nop 2
crap 5.009
1
<?php
2
3
namespace ByTIC\GoogleAnalytics\Tracking\Renderer\Script\AnalyticsJs;
4
5
use ByTIC\GoogleAnalytics\Tracking\Data\Tracker;
6
use ByTIC\GoogleAnalytics\Tracking\Renderer\Script\AnalyticsJs;
7
8
/**
9
 * Class CreateCommand
10
 * @package ByTIC\GoogleAnalytics\Tracking\Renderer\Script\AnalyticsJs
11
 */
12
class CreateCommand
13
{
14
15
    /**
16
     * @param Tracker $tracker
17
     * @param $functionName
18
     * @return string
19
     */
20 3
    public static function generate($tracker, $functionName = AnalyticsJs::DEFAULT_FUNCTION_NAME)
21
    {
22 3
        $parameters = [];
23
        $params = [
24 3
            'create',
25 3
            $tracker->getTrackingId(),
26 3
            'auto'
27
        ];
28
29 3
        if ($tracker->getAlias()) {
30 2
            $params[] = $tracker->getAlias();
31
        }
32
33 3
        if ($tracker->isAllowLinker()) {
34 1
            $parameters['allowLinker'] = true;
35
        }
36
37 3
        if ($tracker->isAnonymizeIp()) {
38
            $parameters['anonymizeIp'] = true;
39
        }
40
41 3
        if (count($parameters) > 0) {
42 1
            $params[] = $parameters;
43
        }
44
45 3
        return MethodCall::generate($params, $functionName);
46
    }
47
}
48