Completed
Push — master ( 7eb310...d5dbfe )
by Nicolaas
01:04
created

InsertGoogleAnalyticsAsHeadTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class GoogleAnalyticsSTE extends SiteTreeExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    /**
7
     *
8
     * @return String
9
     */
10
    private static $main_code;
0 ignored issues
show
Unused Code introduced by
The property $main_code is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
11
12
    /**
13
     *
14
     * @return String
15
     */
16
    private static $site_name;
0 ignored issues
show
Unused Code introduced by
The property $site_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
18
    /**
19
     *
20
     * @return String
21
     */
22
    private static $show_really_annoying_yellow_bar = false;
0 ignored issues
show
Unused Code introduced by
The property $show_really_annoying_yellow_bar is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
24
    public function GAMainIsOn()
0 ignored issues
show
Coding Style introduced by
GAMainIsOn uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
25
    {
26
        return Director::isLive() || isset($_GET['testanalytics']);
27
    }
28
29
    public function GAMainCode()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
30
    {
31
        return Config::inst()->get("GoogleAnalyticsSTE", "main_code");
32
    }
33
34
    public function GAMainSite()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
35
    {
36
        return Config::inst()->get("GoogleAnalyticsSTE", "site_name");
37
    }
38
39
    /**
40
     *
41
     * @return Boolean
42
     */
43
    public function ShowReallyAnnoyingYellowBar()
44
    {
45
        return Config::inst()->get("GoogleAnalyticsSTE", "show_really_annoying_yellow_bar");
46
    }
47
48
    public function InsertGoogleAnalyticsAsHeadTag()
49
    {
50
        Requirements::insertHeadTags($this->owner->renderWith('Analytics'));
51
    }
52
53
54
}
55