LangBundler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelLangBundler;
4
5
use LaravelLangBundler\Bundle\Bundle;
6
use LaravelLangBundler\Bundle\BundleMap;
7
8
class LangBundler
9
{
10
    /**
11
     * BundleMap instance.
12
     *
13
     * @var BundleMap
14
     */
15
    protected $bundleMap;
16
17
    /**
18
     * Translator instance.
19
     *
20
     * @var Translator
21
     */
22
    protected $translator;
23
24
    /**
25
     * Construct.
26
     */
27
    public function __construct(BundleMap $bundleMap, Translator $translator)
28
    {
29
        $this->bundleMap = $bundleMap;
30
        $this->translator = $translator;
31
32
        $this->bundleMap->mapBundles();
33
    }
34
35
    /**
36
     * Translate the given message.
37
     *
38
     * @param string $id
39
     * @param array  $parameters
40
     * @param string $locale
41
     *
42
     * @return \Illuminate\Support\Collection
43
     */
44
    public function trans($id, array $parameters = [], $locale = null)
45
    {
46
        $bundle = new Bundle($id, $this->bundleMap);
47
48
        if ($bundle->hasNoValues()) {
49
            return app('translator')->trans($id, $parameters, $locale);
50
        }
51
52
        return $this->translator->translateBundle($bundle, $parameters, $locale);
53
    }
54
}
55