Script   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 3
c 4
b 1
f 2
lcom 0
cbo 2
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 8 2
1
<?php
2
/**
3
 * This file is part of phpab/phpab-module. (https://github.com/phpab/phpab-module)
4
 *
5
 * @link https://github.com/phpab/phpab-module for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab-module/master/LICENSE MIT
8
 */
9
10
namespace PhpAbModule\View\Helper;
11
12
use PhpAb\Analytics\Renderer\AbstractGoogleAnalytics;
13
use PhpAb\Analytics\Renderer\JavascriptRendererInterface;
14
use PhpAb\Analytics\Renderer\RendererInterface;
15
use Zend\View\Helper\AbstractHelper;
16
17
/**
18
 * A view helper that can be used to render a script for analytics.
19
 */
20
class Script extends AbstractHelper
21
{
22
    /**
23
     * @var RendererInterface
24
     */
25
    private $renderer;
26
27
    /**
28
     * Initializes a new instance of this class.
29
     *
30
     * @param RendererInterface $renderer The analytics to render a script for.
31
     */
32
    public function __construct(RendererInterface $renderer)
33
    {
34
        $this->renderer = $renderer;
35
    }
36
37
    /**
38
     * Generates the script that is needed to make phpab work.
39
     *
40
     * @return string
41
     */
42
    public function __invoke()
43
    {
44
        if ($this->renderer instanceof JavascriptRendererInterface) {
45
            return $this->renderer->getScript();
46
        }
47
48
        return '';
49
    }
50
}
51