Completed
Push — master ( e5a61d...342745 )
by wen
04:30
created

MenuController::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Sco\Admin\Http\Controllers\System;
4
5
use Sco\Admin\Http\Controllers\BaseController;
6
use Illuminate\Http\Request;
7
use Sco\Admin\Models\Permission;
8
9
/**
10
 * 菜单管理
11
 *
12
 */
13
class MenuController extends BaseController
14
{
15
    private $permissionModel;
16
17
    /**
18
     * 菜单列表
19
     *
20
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
21
     */
22
    public function getList()
23
    {
24
        $menus = $this->getPermissionModel()->getMenuTreeList();
25
26
        return response()->json($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
        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...
39
        }
40
41
        $menus = $this->getPermissionModel()->getMenuTreeList();
42
        //return response()->json($menus);
43
        return $this->render('system.menu.add', compact('menus'));
44
    }
45
46
    /**
47
     * 保存菜单信息
48
     *
49
     * @param \Illuminate\Http\Request $request
50
     *
51
     * @return \Illuminate\Http\JsonResponse
52
     */
53 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...
54
    {
55
        $this->validate($request, [
56
            'pid'          => 'bail|integer',
57
            'display_name' => 'bail|required',
58
            'name'         => ['bail', 'required', 'regex:/^[\w\.]+$/'],
59
            //'' => '',
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...
60
        ]);
61
62
        $this->getPermissionModel()->saveMenu($request);
63
        return response()->json(success('新增菜单完成', ['url' => route('admin.system.menu')]));
64
    }
65
66
    /**
67
     * 编辑菜单
68
     *
69
     * @param integer $id 菜单ID
70
     *
71
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
72
     */
73
    public function getEdit($id)
74
    {
75
        $menu  = Permission::find($id);
76
        $menus = $this->getPermissionModel()->getMenuTreeList();
77
        return response()->json(success('ok', compact('menu', 'menus')));
78
        //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...
79
    }
80
81
    /**
82
     * 保存菜单信息
83
     *
84
     * @param \Illuminate\Http\Request $request 提交数据
85
     *
86
     * @return \Illuminate\Http\JsonResponse
87
     */
88 View Code Duplication
    public function save(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...
89
    {
90
        $this->validate($request, [
91
            'pid'          => 'bail|integer',
92
            'display_name' => 'bail|required',
93
            'name'         => ['bail', 'required', 'regex:/^[\w\.#]+$/'],
94
            //'' => '',
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...
95
        ], trans('admin::validation'), trans('admin::validation.attributes'));
96
97
98
        $this->getPermissionModel()->saveMenu($request);
99
        return response()->json(['message' => 'ok']);
100
    }
101
102
103
    /**
104
     * 删除菜单
105
     *
106
     * @param integer $id
107
     */
108
    public function delete($id)
109
    {
110
        $this->getPermissionModel()->deleteMenu($id);
111
        return response()->json(['message' => 'ok']);
112
    }
113
114
115
    /**
116
     * @return \Sco\Admin\Models\Permission
117
     */
118
    private function getPermissionModel()
119
    {
120
        if ($this->permissionModel) {
121
            return $this->permissionModel;
122
        }
123
124
        return $this->permissionModel = new Permission();
125
    }
126
}
127