Completed
Push — master ( 57bab5...72813b )
by Abdelrahman
02:34
created

RolesController::form()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Http\Controllers\Backend;
17
18
use Illuminate\Http\Request;
19
use Rinvex\Fort\Models\Role;
20
use Rinvex\Fort\Contracts\RoleRepositoryContract;
21
use Rinvex\Fort\Http\Controllers\AuthorizedController;
22
23
class RolesController extends AuthorizedController
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $resourceAbilityMap = [
29
        'assign' => 'assign',
30
        'remove' => 'remove',
31
    ];
32
33
    /**
34
     * The role repository instance.
35
     *
36
     * @var \Rinvex\Fort\Contracts\RoleRepositoryContract
37
     */
38
    protected $roleRepository;
39
40
    /**
41
     * Create a new users controller instance.
42
     *
43
     * @param \Rinvex\Fort\Contracts\RoleRepositoryContract $roleRepository
44
     *
45
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
46
     */
47
    public function __construct(RoleRepositoryContract $roleRepository)
48
    {
49
        parent::__construct();
50
51
        $this->authorizeResource(Role::class);
52
53
        $this->roleRepository = $roleRepository;
54
    }
55
56
    /**
57
     * Display a listing of the resource.
58
     *
59
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
60
     */
61
    public function index()
62
    {
63
        $roles = $this->roleRepository->paginate(config('rinvex.fort.backend.items_per_page'));
64
65
        return view('rinvex.fort::backend.roles.index', compact('roles'));
66
    }
67
68
    /**
69
     * Display the specified resource.
70
     *
71
     * @param int $id
72
     *
73
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
74
     */
75
    public function show($id)
76
    {
77
        if (! $role = $this->roleRepository->find($id)) {
78
            return intend([
79
                'intended'   => route('rinvex.fort.backend.roles.index'),
80
                'withErrors' => ['rinvex.fort.role.not_found' => trans('rinvex.fort::backend/messages.role.not_found', ['role' => $id])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
81
            ]);
82
        }
83
84
        $actions   = ['view', 'create', 'edit', 'delete', 'import', 'export'];
85
        $resources = app('rinvex.fort.ability')->findAll()->groupBy('resource');
86
        $columns   = ['resource', 'view', 'create', 'edit', 'delete', 'import', 'export', 'other'];
87
88
        return view('rinvex.fort::backend.roles.show', compact('role', 'resources', 'actions', 'columns'));
89
    }
90
91
    /**
92
     * Bulk control the given resources.
93
     *
94
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
95
     */
96
    public function bulk()
97
    {
98
        //
99
    }
100
101
    /**
102
     * Show the form for creating a new resource.
103
     *
104
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
105
     */
106
    public function create()
107
    {
108
        return $this->form('create', 'store');
109
    }
110
111
    /**
112
     * Show the form for copying the given resource.
113
     *
114
     * @param int $id
115
     *
116
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
117
     */
118
    public function copy($id)
119
    {
120
        return $this->form('copy', 'store', $id);
121
    }
122
123
    /**
124
     * Show the form for editing the given resource.
125
     *
126
     * @param int $id
127
     *
128
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
129
     */
130
    public function edit($id)
131
    {
132
        return $this->form('edit', 'update', $id);
133
    }
134
135
    /**
136
     * Show the form for create/edit/copy of the given resource.
137
     *
138
     * @param string   $mode
139
     * @param string   $action
140
     * @param int|null $id
141
     *
142
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
143
     */
144
    protected function form($mode, $action, $id = null)
145
    {
146
        if (! $role = $this->roleRepository->getModelInstance($id)) {
0 ignored issues
show
Documentation Bug introduced by
The method getModelInstance does not exist on object<Rinvex\Fort\Contr...RoleRepositoryContract>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
147
            return intend([
148
                'intended'   => route('rinvex.fort.backend.roles.index'),
149
                'withErrors' => ['rinvex.fort.role.not_found' => trans('rinvex.fort::backend/messages.role.not_found', ['role' => $id])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
150
            ]);
151
        }
152
153
        $resources = app('rinvex.fort.ability')->findAll()->groupBy('resource');
154
155
        return view('rinvex.fort::backend.roles.form', compact('role', 'resources', 'mode', 'action'));
156
    }
157
158
    /**
159
     * Store a newly created resource in storage.
160
     *
161
     * @param \Illuminate\Http\Request $request
162
     *
163
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
164
     */
165
    public function store(Request $request)
166
    {
167
        dd($request->all());
168
        //
169
    }
170
171
    /**
172
     * Update the given resource in storage.
173
     *
174
     * @param \Illuminate\Http\Request $request
175
     * @param int                      $id
176
     *
177
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
178
     */
179
    public function update(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...
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...
180
    {
181
        //
182
    }
183
184
    /**
185
     * Delete the given resource from storage.
186
     *
187
     * @param int $id
188
     *
189
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
190
     */
191
    public function delete($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...
192
    {
193
        //
194
    }
195
196
    /**
197
     * Import the given resources into storage.
198
     *
199
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
200
     */
201
    public function import()
202
    {
203
        //
204
    }
205
206
    /**
207
     * Export the given resources from storage.
208
     *
209
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
210
     */
211
    public function export()
212
    {
213
        //
214
    }
215
}
216