Completed
Push — master ( 141c37...4e2b2d )
by Scott
04:28
created

LangJsonable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 30
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getLangJson() 0 21 4
1
<?php namespace Bedard\Shop\Traits;
2
3
use Lang;
4
5
trait LangJsonable
6
{
7
    /**
8
     * Get a set of language strings and convert them to JSON.
9
     *
10
     * @param  array    $keys
11
     * @return string
12
     */
13
    public function getLangJson($keys)
14
    {
15
        $lang = [];
16
17
        foreach ($keys as $key => $value) {
18
            $isFiltered = gettype($value) === 'array';
19
20
            if (! $isFiltered) {
21
                $key = $value;
22
            }
23
24
            $alias = explode('@', $key);
25
            $languageString = $alias[count($alias) - 1];
26
27
            $lang[$alias[0]] = $isFiltered
28
                ? array_intersect_key(Lang::get($languageString), array_flip($value))
29
                : Lang::get($languageString);
30
        }
31
32
        return json_encode($lang);
33
    }
34
}
35