Completed
Push — master ( 86fd56...98623b )
by wen
02:52
created

MenuController::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
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
    public function postAdd(Request $request)
54
    {
55
        $this->validate($request, [
56
            'pid'          => 'integer',
57
            'display_name' => '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
    public function save(Request $request)
89
    {
90
        $this->validate($request, [
91
            'pid'          => 'integer',
92
            'display_name' => '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
        ]);
96
97
        return response()->json($request->all());
98
99
        //$this->getPermissionModel()->saveMenu($request, $id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
100
        //return response()->json(success('编辑菜单完成', ['url' => route('admin.system.menu')]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
101
    }
102
103
104
    /**
105
     * 删除菜单
106
     *
107
     * @param integer $id
108
     */
109
    public function getDelete($id)
110
    {
111
    }
112
113
114
    /**
115
     * @return \Sco\Admin\Models\Permission
116
     */
117
    private function getPermissionModel()
118
    {
119
        if ($this->permissionModel) {
120
            return $this->permissionModel;
121
        }
122
123
        return $this->permissionModel = new Permission();
124
    }
125
}
126