Completed
Push — dev-master ( f1d44b...511541 )
by Derek Stephen
01:34
created

Translate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 5 1
A translate() 0 4 1
1
<?php
2
3
namespace Bone\Mvc\View\Extension\Plates;
4
5
use League\Plates\Engine;
6
use League\Plates\Extension\ExtensionInterface;
7
use Locale;
8
use Laminas\I18n\Translator\Translator;
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 10
    public function __construct(Translator $translator)
20
    {
21 10
        $this->translator = $translator;
22 10
    }
23
24
    /**
25
     * @param Engine $engine
26
     */
27 9
    public function register(Engine $engine)
28
    {
29 9
        $engine->registerFunction('t', [$this, 'translate']);
30 9
        $engine->registerFunction('translate', [$this, 'translate']);
31 9
    }
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