Completed
Push — master ( 753e69...36642f )
by Derek Stephen
02:06 queued 13s
created

Translate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 55.56%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A translate() 0 4 1
A register() 0 5 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 Zend\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 1
    public function __construct(Translator $translator)
20
    {
21 1
        $this->translator = $translator;
22 1
    }
23
24
    /**
25
     * @param Engine $engine
26
     */
27
    public function register(Engine $engine)
28
    {
29
        $engine->registerFunction('t', [$this, 'translate']);
30
        $engine->registerFunction('translate', [$this, 'translate']);
31
    }
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