Completed
Push — master ( 52baeb...1d4f3f )
by wen
02:10
created

MenuController::getIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Sco\Admin\Http\Controllers\Controllers\System;
4
5
use Sco\Admin\Http\Controllers\BaseController;
6
use Illuminate\Http\Request;
7
use Sco\Admin\Models\Permission;
8
use Sco\Admin\Repositories\PermissionRepository;
9
10
/**
11
 * 菜单管理
12
 *
13
 */
14
class MenuController extends BaseController
15
{
16
17
    /**
18
     * 菜单列表
19
     *
20
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
21
     */
22
    public function getIndex()
23
    {
24
        $menus = (new Permission())->getMenuTreeList();
25
26
        return $this->render('system.menu.index', compact('menus'));
27
    }
28
29
    /**
30
     * 新增菜单
31
     *
32
     * @param int $pid
33
     *
34
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
35
     */
36
    public function getAdd($pid = 0)
37
    {
38
39
        if ($pid) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
40
41
        }
42
43
        $menus = app(PermissionRepository::class)->getMenuTreeList();
44
        return $this->render('system.menu.add', compact('menus'));
45
    }
46
47
    /**
48
     * 保存菜单信息
49
     *
50
     * @param \Illuminate\Http\Request $request
51
     *
52
     * @return \Illuminate\Http\JsonResponse
53
     */
54 View Code Duplication
    public function postAdd(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
55
    {
56
        $this->validate($request, [
57
            'pid'          => 'integer',
58
            'display_name' => 'required',
59
            'name'         => ['bail', 'required', 'regex:/^[\w\.]+$/'],
60
            //'' => '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
        ]);
62
63
        app(PermissionRepository::class)->saveMenu($request);
64
        return response()->json(success('新增菜单完成', ['url' => route('admin.system.menu')]));
65
    }
66
67
    /**
68
     * 编辑菜单
69
     *
70
     * @param integer $id 菜单ID
71
     *
72
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
73
     */
74
    public function getEdit($id)
75
    {
76
        $menu  = Permission::find($id);
77
        $menus = (new Permission)->getMenuTreeList();
78
        return response()->json(success('ok', compact('menu', 'menus')));
79
        //return $this->render('system.menu.edit', compact('menu', 'menus'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
80
    }
81
82
    /**
83
     * 保存菜单信息
84
     *
85
     * @param \Illuminate\Http\Request $request 提交数据
86
     * @param integer                  $id      菜单ID
87
     *
88
     * @return \Illuminate\Http\JsonResponse
89
     */
90 View Code Duplication
    public function postEdit(Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
91
    {
92
        $this->validate($request, [
93
            'pid'          => 'integer',
94
            'display_name' => 'required',
95
            'name'         => ['bail', 'required', 'regex:/^[\w\.]+$/'],
96
            //'' => '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
        ]);
98
99
        app(PermissionRepository::class)->saveMenu($request, $id);
100
        return response()->json(success('编辑菜单完成', ['url' => route('admin.system.menu')]));
101
    }
102
103
    /**
104
     * 删除菜单
105
     *
106
     * @param integer $id
107
     */
108
    public function getDelete($id)
109
    {
110
111
    }
112
113
114
}
115