LocaleLink   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 2
b 0
f 0
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A locale() 0 3 2
A register() 0 4 1
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