Completed
Push — master ( b28dd3...cc924e )
by Robbie
03:15
created

ChecIOExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 24
rs 10
c 0
b 0
f 0
1
<?php
2
3
class ChecIOExtension extends SiteTreeExtension
4
{
5
    /**
6
     * Loads the third party javascript during Controller->init()
7
     */
8
    public function contentcontrollerInit()
9
    {
10
        if ($jsPath = ChecIOShortcode::config()->get('third-party-js')) {
11
            Requirements::javascript($jsPath);
12
        }
13
    }
14
15
    /**
16
     * Tries to fetch the inline chec.io JS from cache, failing which it gets it from the URL.
17
     * Should your theme clear requirements, placing this before the closing body tag ensures
18
     * that it always gets loaded.
19
     * @return string
20
     */
21
    public function getChecIOJs()
22
    {
23
        if ($jsPath = ChecIOShortcode::config()->get('third-party-js')) {
24
            return sprintf('<script type="text/javascript" src="%s"></script>', $jsPath);
25
        }
26
        return '';
27
    }
28
}
29