Completed
Push — master ( 0d16be...215ca2 )
by Scott
01:59
created

BackendController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getLangJson() 0 21 4
1
<?php namespace Bedard\Shop\Classes;
2
3
use Backend\Classes\Controller as BaseController;
4
use Lang;
5
6
class BackendController extends BaseController
7
{
8
    public function __construct()
9
    {
10
        parent::__construct();
11
12
        $this->addJs('/plugins/bedard/shop/assets/dist/vendor.js');
13
    }
14
15
    /**
16
     * Get a set of language strings and convert them to JSON.
17
     *
18
     * @param  array    $keys
19
     * @return string
20
     */
21
    public function getLangJson($keys)
22
    {
23
        $lang = [];
24
25
        foreach ($keys as $key => $value) {
26
            $isFiltered = gettype($value) === 'array';
27
28
            if (! $isFiltered) {
29
                $key = $value;
30
            }
31
32
            $alias = explode('@', $key);
33
            $languageString = $alias[count($alias) - 1];
34
35
            $lang[$alias[0]] = $isFiltered
36
                ? array_intersect_key(Lang::get($languageString), array_flip($value))
37
                : Lang::get($languageString);
38
        }
39
40
        return json_encode($lang);
41
    }
42
}
43