ChecExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A contentcontrollerInit() 0 4 2
A getChecJavaScript() 0 6 2
1
<?php
2
3
namespace Robbie\SilverstripeChec;
4
5
use SilverStripe\CMS\Model\SiteTreeExtension;
6
use SilverStripe\View\Requirements;
7
8
class ChecExtension extends SiteTreeExtension
9
{
10
    /**
11
     * Loads the third party JavaScript during Controller->init()
12
     */
13
    public function contentcontrollerInit(): void
14
    {
15
        if ($jsPath = ChecShortcode::config()->get('javascript_url')) {
16
            Requirements::javascript($jsPath);
17
        }
18
    }
19
20
    /**
21
     * Tries to fetch the inline Chec JS from cache, failing which it gets it from the URL.
22
     * Should your theme clear requirements, placing this before the closing body tag ensures
23
     * that it always gets loaded.
24
     *
25
     * @return string
26
     */
27
    public function getChecJavaScript(): string
28
    {
29
        if ($jsPath = ChecShortcode::config()->get('javascript_url')) {
30
            return sprintf('<script type="text/javascript" src="%s"></script>', $jsPath);
31
        }
32
        return '';
33
    }
34
}
35