Translate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A __construct() 0 3 1
A translate() 0 3 1
1
<?php
2
3
namespace Bone\I18n\View\Extension;
4
5
use Laminas\I18n\Translator\Translator;
6
use League\Plates\Engine;
7
use League\Plates\Extension\ExtensionInterface;
8
use Locale;
9
10
class Translate implements ExtensionInterface
11
{
12
    /** @var Translator $translator */
13
    private $translator;
14
15
    /**
16
     * Translate constructor.
17
     * @param Translator $translator
18
     */
19 4
    public function __construct(Translator $translator)
20
    {
21 4
        $this->translator = $translator;
22 4
    }
23
24
    /**
25
     * @param Engine $engine
26
     */
27 4
    public function register(Engine $engine)
28
    {
29 4
        $engine->registerFunction('t', [$this, 'translate']);
30 4
        $engine->registerFunction('translate', [$this, 'translate']);
31 4
    }
32
33
    /**
34
     * @param string $string
35
     * @param string $domain
36
     * @return string
37
     */
38 1
    public function translate(string $string, string $domain = 'default') : string
39
    {
40 1
        return $this->translator->translate($string, $domain, Locale::getDefault());
41
    }
42
}
43