RollbarPageExtension::getShowRollbar()   B
last analyzed

Complexity

Conditions 9
Paths 5

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 9
eloc 5
c 2
b 0
f 0
nc 5
nop 0
dl 0
loc 10
rs 8.0555
1
<?php
2
3
namespace AntonyThorpe\Rollbar;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Core\Extension;
8
use AntonyThorpe\Rollbar\Rollbar;
9
10
/**
11
 * Extend Page class to provide variables to Rollbar.ss
12
 */
13
class RollbarPageExtension extends Extension
14
{
15
    /**
16
     * Show/no-show of the Rollbar javascript file as set in your config
17
     */
18
    public function getShowRollbar(): bool
19
    {
20
        if (Director::isLive() && Rollbar::config()->show_on_live && Rollbar::config()->show) {
21
            return true;
22
        }
23
24
        if (Director::isDev() && Rollbar::config()->show_on_dev && Rollbar::config()->show) {
25
            return true;
26
        }
27
        return Director::isTest() && Rollbar::config()->show_on_test && Rollbar::config()->show;
28
    }
29
30
    /**
31
     * Provide the site id to the template
32
     */
33
    public function getRollbarClientToken(): string
34
    {
35
        return Rollbar::config()->client_token;
36
    }
37
}
38