LocaleLink::locale()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Bone\I18n\View\Extension;
4
5
use League\Plates\Engine;
6
use League\Plates\Extension\ExtensionInterface;
7
use Locale;
8
9
class LocaleLink implements ExtensionInterface
10
{
11
    /** @var bool $enabled */
12
    private $enabled;
13
14
    /**
15
     * LocaleLink constructor.
16
     * @param bool $enabled
17
     */
18 5
    public function __construct(bool $enabled)
19
    {
20 5
        $this->enabled = $enabled;
21 5
    }
22
23
    /**
24
     * @param Engine $engine
25
     */
26 4
    public function register(Engine $engine)
27
    {
28 4
        $engine->registerFunction('l', [$this, 'locale']);
29 4
        $engine->registerFunction('locale', [$this, 'locale']);
30 4
    }
31
32
    /**
33
     * @return string
34
     */
35 1
    public function locale() : string
36
    {
37 1
        return $this->enabled ? '/' . Locale::getDefault() : '';
38
    }
39
}
40