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

AbilitiesController::form()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 11
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\Ability;
20
use Rinvex\Fort\Contracts\AbilityRepositoryContract;
21
use Rinvex\Fort\Http\Controllers\AuthorizedController;
22
23
class AbilitiesController extends AuthorizedController
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $resourceAbilityMap = [
29
        'give'   => 'give',
30
        'revoke' => 'revoke',
31
    ];
32
33
    /**
34
     * The ability repository instance.
35
     *
36
     * @var \Rinvex\Fort\Contracts\AbilityRepositoryContract
37
     */
38
    protected $abilityRepository;
39
40
    /**
41
     * Create a new abilities controller instance.
42
     *
43
     * @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...
44
     */
45
    public function __construct(AbilityRepositoryContract $abilityRepository)
46
    {
47
        parent::__construct();
48
49
        $this->authorizeResource(Ability::class);
50
51
        $this->abilityRepository = $abilityRepository;
52
    }
53
54
    /**
55
     * Display a listing of the resource.
56
     *
57
     * @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...
58
     */
59
    public function index()
60
    {
61
        $abilities = $this->abilityRepository->paginate(config('rinvex.fort.backend.items_per_page'));
62
63
        return view('rinvex.fort::backend.abilities.index', compact('abilities'));
64
    }
65
66
    /**
67
     * Display the specified resource.
68
     *
69
     * @param int $id
70
     *
71
     * @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...
72
     */
73
    public function show($id)
74
    {
75
        if (! $ability = $this->abilityRepository->find($id)) {
76
            return intend([
77
                'intended'   => route('rinvex.fort.backend.abilities.index'),
78
                'withErrors' => ['rinvex.fort.ability.not_found' => trans('rinvex.fort::backend/messages.ability.not_found', ['ability' => $id])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 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...
79
            ]);
80
        }
81
82
        return view('rinvex.fort::backend.abilities.show', compact('ability'));
83
    }
84
85
    /**
86
     * Bulk control the given resources.
87
     *
88
     * @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...
89
     */
90
    public function bulk()
91
    {
92
        //
93
    }
94
95
    /**
96
     * Show the form for creating a new resource.
97
     *
98
     * @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...
99
     */
100
    public function create()
101
    {
102
        return $this->form('create', 'store');
103
    }
104
105
    /**
106
     * Show the form for copying the given resource.
107
     *
108
     * @param int $id
109
     *
110
     * @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...
111
     */
112
    public function copy($id)
113
    {
114
        return $this->form('copy', 'store', $id);
115
    }
116
117
    /**
118
     * Show the form for editing the given resource.
119
     *
120
     * @param int $id
121
     *
122
     * @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...
123
     */
124
    public function edit($id)
125
    {
126
        return $this->form('edit', 'update', $id);
127
    }
128
129
    /**
130
     * Show the form for create/edit/copy of the given resource.
131
     *
132
     * @param string   $mode
133
     * @param string   $action
134
     * @param int|null $id
135
     *
136
     * @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...
137
     */
138
    protected function form($mode, $action, $id = null)
139
    {
140
        if (! $ability = $this->abilityRepository->getModelInstance($id)) {
0 ignored issues
show
Documentation Bug introduced by
The method getModelInstance does not exist on object<Rinvex\Fort\Contr...lityRepositoryContract>? 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...
141
            return intend([
142
                'intended'   => route('rinvex.fort.backend.abilities.index'),
143
                'withErrors' => ['rinvex.fort.ability.not_found' => trans('rinvex.fort::backend/messages.ability.not_found', ['ability' => $id])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 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...
144
            ]);
145
        }
146
147
        return view('rinvex.fort::backend.abilities.form', compact('ability', 'resources', 'mode', 'action'));
148
    }
149
150
    /**
151
     * Store a newly created resource in storage.
152
     *
153
     * @param \Illuminate\Http\Request $request
154
     *
155
     * @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...
156
     */
157
    public function store(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...
158
    {
159
        //
160
    }
161
162
    /**
163
     * Update the given resource in storage.
164
     *
165
     * @param \Illuminate\Http\Request $request
166
     * @param int                      $id
167
     *
168
     * @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...
169
     */
170
    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...
171
    {
172
        //
173
    }
174
175
    /**
176
     * Delete the given resource from storage.
177
     *
178
     * @param int $id
179
     *
180
     * @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...
181
     */
182
    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...
183
    {
184
        //
185
    }
186
187
    /**
188
     * Import the given resources into storage.
189
     *
190
     * @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...
191
     */
192
    public function import()
193
    {
194
        //
195
    }
196
197
    /**
198
     * Export the given resources from storage.
199
     *
200
     * @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...
201
     */
202
    public function export()
203
    {
204
        //
205
    }
206
}
207