Completed
Push — master ( 74da27...ac625a )
by wen
12:26
created

Admin::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
namespace Sco\Admin;
5
6
use Auth;
7
use Route;
8
use Illuminate\Foundation\Application;
9
use Sco\Admin\Contracts\Admin as AdminContract;
10
use Illuminate\Config\Repository as ConfigRepository;
11
12
class Admin implements AdminContract
13
{
14
    /**
15
     * @var \Illuminate\Foundation\Application
16
     */
17
    protected $app;
18
19
    /**
20
     * @var \Illuminate\Config\Repository
21
     */
22
    protected $config;
23
24
    public function __construct(Application $app)
25
    {
26
        $this->app = $app;
27
        $this->config = new ConfigRepository(
28
            $this->app['config']->get('admin', [])
29
        );
30
    }
31
32
    public function getMenus($list = null)
33
    {
34
        $list = $list ?: $this->config->get('menus');
35
        $menus = collect();
36
        foreach ($list as $key => $items) {
37
            if (is_string($items)) {
38
                if (Route::has($items)) {
39 View Code Duplication
                    if (Auth::user()->can($items)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
                        $menus->push([
41
                            'title' => $key,
42
                            'url'   => route($items, [], false),
43
                            'child' => [],
44
                        ]);
45
                    }
46 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
                    $config = $this->getConfig($items);
48
                    if ($config && $config->getAttribute('permissions.view')) {
49
                        $menus->push([
50
                            'title' => $config->getAttribute('title'),
51
                            'url'   => route('admin.model.index', ['model' => $items], false),
52
                            'child' => [],
53
                        ]);
54
                    }
55
                }
56 View Code Duplication
            } elseif (is_array($items)) { // child
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
                $childs = $this->getMenus($items);
58
                if ($childs->isNotEmpty()) {
59
                    $menu = [
60
                        'title' => $key,
61
                        'url'   => '/#',
62
                        'child' => $childs,
63
                    ];
64
                    $menus->push($menu);
65
                }
66
            }
67
        }
68
        return $menus;
69
    }
70
71
    public function getConfig($name)
72
    {
73
        return $this->app['admin.config.factory']->make($name);
74
    }
75
}
76