TagProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forTemplate() 0 13 2
A isEnabled() 0 11 5
1
<?php
2
3
namespace SilverStripe\CrazyEgg;
4
5
use SilverStripe\Core\Environment;
6
use SilverStripe\ORM\FieldType\DBHTMLText;
7
use SilverStripe\View\ViewableData;
8
9
class TagProvider extends ViewableData
10
{
11
    /**
12
     * @var bool
13
     */
14
    private static $enabled = true;
0 ignored issues
show
introduced by
The private property $enabled is not used, and could be removed.
Loading history...
15
16
    /**
17
     * @return bool
18
     */
19
    public function isEnabled()
20
    {
21
        if (!Environment::getEnv('CRAZY_EGG_APP_KEY')
22
            || !Environment::getEnv('CRAZY_EGG_APP_SECRET')
23
            || !Environment::getEnv('CRAZY_EGG_ACCOUNT_NUMBER')
24
            || !$this->config()->get('enabled')
25
        ) {
26
            return false;
27
        }
28
29
        return true;
30
    }
31
32
    /**
33
     * @return null|DBHTMLText
34
     */
35
    public function forTemplate()
36
    {
37
        if (!$this->isEnabled()) {
38
            return null;
39
        }
40
41
        $parts = str_split(Environment::getEnv('CRAZY_EGG_ACCOUNT_NUMBER'), 4);
42
        $accountNumber = $parts[0] . '/' . $parts[1];
43
44
        return $this->renderWith(
45
            'CrazyEggScriptTags',
46
            [
47
                'CrazyEggAccountNumber' => $accountNumber,
48
            ]
49
        );
50
    }
51
}
52