TranslationTwigExtension::getFilters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Translation;
6
7
final class TranslationTwigExtension extends \Twig_Extension
8
{
9
    /**
10
     * @var TranslatorInterface
11
     */
12
    private $translator;
13
14
    /**
15
     * @param TranslatorInterface $translator
16
     */
17 4
    public function __construct(TranslatorInterface $translator)
18
    {
19 4
        $this->translator = $translator;
20 4
    }
21
22
    /**
23
     * @return string
24
     */
25 1
    public function getName()
26
    {
27 1
        return 'translation';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function getFilters()
34
    {
35
        return [
36 1
            new \Twig_SimpleFilter('translate', [$this, 'translate']),
37
        ];
38
    }
39
40
    /**
41
     * @param string $key
42
     * @param string $locale
43
     * @param array  $args
44
     *
45
     * @return string
46
     */
47 2
    public function translate(string $key, string $locale, array $args = []): string
48
    {
49 2
        return $this->translator->translate($locale, $key, $args);
50
    }
51
}
52