Passed
Push — master ( eff73f...ae14df )
by Siim
14:39
created

TranslatorTrait::translate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: siim
5
 * Date: 4.02.19
6
 * Time: 11:07
7
 */
8
9
namespace Sf4\Api\Utils\Traits;
10
11
use Symfony\Contracts\Translation\TranslatorInterface;
12
13
trait TranslatorTrait
14
{
15
16
    /** @var TranslatorInterface */
17
    protected $translator;
18
19
    /**
20
     * @return TranslatorInterface
21
     */
22
    public function getTranslator(): TranslatorInterface
23
    {
24
        return $this->translator;
25
    }
26
27
    /**
28
     * @param TranslatorInterface $translator
29
     */
30
    public function setTranslator(TranslatorInterface $translator): void
31
    {
32
        $this->translator = $translator;
33
    }
34
35
    /**
36
     * @param $id
37
     * @param array $parameters
38
     * @param null $domain
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $domain is correct as it would always require null to be passed?
Loading history...
39
     * @param null $locale
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $locale is correct as it would always require null to be passed?
Loading history...
40
     * @return string
41
     */
42
    public function translate($id, array $parameters = array(), $domain = null, $locale = null): string
43
    {
44
        if ($this->translator) {
45
            return $this->translator->trans($id, $parameters, $domain, $locale);
46
        }
47
48
        return $id;
49
    }
50
}
51