Script::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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