Completed
Push — master ( 01668e...fc24a2 )
by wen
14:50
created

AdminController::reorder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Sco\Admin\Http\Controllers;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
use Illuminate\Http\Request;
7
use Illuminate\Routing\Controller;
8
use Sco\Admin\Contracts\ComponentInterface;
9
10
class AdminController extends Controller
11
{
12
    public function index(ComponentInterface $component)
13
    {
14
        if (!$component->isView()) {
15
            throw new AuthorizationException();
16
        }
17
18
        return view('admin::app');
19
    }
20
21
    public function getList(ComponentInterface $component)
22
    {
23
        if (!$component->isView()) {
24
            throw new AuthorizationException();
25
        }
26
27
        return $component->get();
28
    }
29
30
31
    public function config(ComponentInterface $component)
32
    {
33
        if (!$component->isView()) {
34
            throw new AuthorizationException();
35
        }
36
37
        return $component->getConfigs();
38
    }
39
40
    public function getCreateInfo(ComponentInterface $component)
41
    {
42
        if (!$component->isCreate()) {
43
            throw new AuthorizationException();
44
        }
45
46
        $form = $component->fireCreate();
47
        return $form;
48
    }
49
50
    public function create(ComponentInterface $component)
51
    {
52
        if (!$component->isCreate()) {
53
            throw new AuthorizationException();
54
        }
55
56
        return view('admin::app');
57
    }
58
59
    public function store(ComponentInterface $component, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
        if (!$component->isCreate()) {
62
            throw new AuthorizationException();
63
        }
64
65
        $component->store();
66
    }
67
68
    public function getEditInfo(ComponentInterface $component, $id)
69
    {
70
        if (!$component->isEdit()) {
71
            throw new AuthorizationException();
72
        }
73
74
        $form = $component->fireEdit($id);
75
        return $form;
76
    }
77
78
    public function edit(ComponentInterface $component, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
        if (!$component->isEdit()) {
81
            throw new AuthorizationException();
82
        }
83
84
        return view('admin::app');
85
    }
86
87
    public function update(ComponentInterface $component, Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
    {
89
        if (!$component->isEdit()) {
90
            throw new AuthorizationException();
91
        }
92
93
        $component->update($id);
94
        return response()->json(['message' => 'ok']);
95
    }
96
97 View Code Duplication
    public function delete(ComponentInterface $component, $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...
98
    {
99
        if (!$component->isDelete()) {
100
            throw new AuthorizationException();
101
        }
102
103
        $component->delete($id);
104
        return response()->json(['message' => 'ok']);
105
    }
106
107
    public function forceDelete(ComponentInterface $component, $id)
108
    {
109
        if (!$component->isDestroy()) {
110
            throw new AuthorizationException();
111
        }
112
113
        $component->forceDelete($id);
114
        return response()->json(['message' => 'ok']);
115
    }
116
117
    public function restore(ComponentInterface $component, $id)
118
    {
119
        if (!$component->isRestore()) {
120
            throw new AuthorizationException();
121
        }
122
        $component->restore($id);
123
        return response()->json(['message' => 'ok']);
124
    }
125
126 View Code Duplication
    public function reorder(ComponentInterface $component)
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...
127
    {
128
        if (!$component->isEdit()) {
129
            throw new AuthorizationException();
130
        }
131
132
        return response()->json(['message' => 'ok']);
133
    }
134
}
135