LangBundler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A trans() 0 10 2
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