Completed
Push — master ( 348af9...23656b )
by Walter
05:14 queued 02:58
created

Script::__invoke()   A

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) {
0 ignored issues
show
Bug introduced by
The class PhpAb\Analytics\Renderer...scriptRendererInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
45
            return $this->renderer->getScript();
46
        }
47
48
        return '';
49
    }
50
}
51