Completed
Push — master ( f6b863...dc6b17 )
by Albert
02:31
created

TransExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nastoletni\Code\Twig;
6
7
use Symfony\Component\Translation\TranslatorInterface;
8
9
class TransExtension extends \Twig_Extension
10
{
11
    /**
12
     * @var TranslatorInterface
13
     */
14
    private $translator;
15
16
    /**
17
     * TransExtension constructor.
18
     *
19
     * @param TranslatorInterface $translator
20
     */
21 1
    public function __construct(TranslatorInterface $translator)
22
    {
23 1
        $this->translator = $translator;
24 1
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function getFilters()
30
    {
31
        return [
32 1
            new \Twig_SimpleFilter('trans', [$this, 'trans'])
33
        ];
34
    }
35
36
    /**
37
     * Translates given message using Translation component.
38
     *
39
     * @param $message
40
     *
41
     * @return string
42
     */
43
    public function trans($message)
44
    {
45
        return $this->translator->trans($message);
46
    }
47
}