Completed
Push — master ( 0c3733...9b1319 )
by Vladimir
02:41
created

BaseUrlFunction::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace allejo\stakx\Twig;
4
5
use allejo\stakx\Object\FrontMatterObject;
6
use Twig_Environment;
7
8
class BaseUrlFunction
9
{
10
    public function __invoke (Twig_Environment $env, $assetPath)
11
    {
12
        $globals = $env->getGlobals();
13
14
        if ($assetPath instanceof FrontMatterObject)
15
        {
16
            $assetPath = $assetPath->getPermalink();
17
        }
18
19
        // @TODO 1.0.0 Remove support for 'base' as it's been deprecated
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
20
        $base = (array_key_exists('base', $globals['site'])) ? $globals['site']['base'] : $globals['site']['baseurl'];
21
22
        $baseURL = (empty($base)) ? '/' : '/' . trim($base, '/') . '/';
23
        $url     = ltrim($assetPath, '/');
24
25
        return ($baseURL . $url);
26
    }
27
28 1
    public static function get ()
29
    {
30 1
        return new \Twig_SimpleFunction('url', new self(), array(
31
            'needs_environment' => true
32 1
        ));
33
    }
34
}