Completed
Branch master (585519)
by Jeremy
40:45 queued 37:23
created

Http/Controllers/LaravelPermissionsController.php (13 issues)

1
<?php
2
3
namespace jeremykenedy\LaravelRoles\App\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
use jeremykenedy\LaravelRoles\App\Http\Requests\StorePermissionRequest;
8
use jeremykenedy\LaravelRoles\App\Http\Requests\UpdatePermissionRequest;
9
use jeremykenedy\LaravelRoles\App\Services\PermissionFormFields;
10
use jeremykenedy\LaravelRoles\Traits\RolesAndPermissionsHelpersTrait;
11
use jeremykenedy\LaravelRoles\Traits\RolesUsageAuthTrait;
12
13
class LaravelPermissionsController extends Controller
14
{
15
    use RolesAndPermissionsHelpersTrait;
0 ignored issues
show
The trait jeremykenedy\LaravelRole...PermissionsHelpersTrait requires some properties which are not provided by jeremykenedy\LaravelRole...elPermissionsController: $role_id, $user_id, $id, $roles, $permission_id
Loading history...
16
    use RolesUsageAuthTrait;
17
18
    /**
19
     * Show the roles and Permissions dashboard.
20
     *
21
     * @return \Illuminate\Http\Response
22
     */
23
    public function index()
24
    {
25
        $data = $this->getDashboardData();
26
27
        return view($data['view'], $data['data']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view($data['view'], $data['data']) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
28
    }
29
30
    /**
31
     * Show the form for creating a new resource.
32
     *
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function create()
36
    {
37
        $service = new PermissionFormFields();
38
        $data = $service->handle();
0 ignored issues
show
Are you sure the assignment to $data is correct as $service->handle() targeting jeremykenedy\LaravelRole...ionFormFields::handle() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
39
40
        return view('laravelroles::laravelroles.crud.permissions.create', $data);
0 ignored issues
show
$data of type void is incompatible with the type Illuminate\Contracts\Support\Arrayable|array expected by parameter $data of view(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        return view('laravelroles::laravelroles.crud.permissions.create', /** @scrutinizer ignore-type */ $data);
Loading history...
Bug Best Practice introduced by
The expression return view('laravelrole...issions.create', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
41
    }
42
43
    /**
44
     * Store a newly created permission in storage.
45
     *
46
     * @param \jeremykenedy\LaravelRoles\App\Http\Requests\StorePermissionRequest $request
47
     *
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function store(StorePermissionRequest $request)
51
    {
52
        $permissionData = $request->permissionFillData();
53
        $permission = $this->storeNewPermission($permissionData);
54
55
        return redirect()->route('laravelroles::roles.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...=> $permission->name))) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
56
                            ->with('success', trans('laravelroles::laravelroles.flash-messages.permission-create', ['permission' => $permission->name]));
57
    }
58
59
    /**
60
     * Display the specified resource.
61
     *
62
     * @param int $id
63
     *
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function show($id)
67
    {
68
        $data = $this->getPermissionItemData($id);
69
70
        return view('laravelroles::laravelroles.crud.permissions.show', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('laravelrole...rmissions.show', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
71
    }
72
73
    /**
74
     * Edit the specified resource.
75
     *
76
     * @param int $id
77
     *
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function edit(Request $request, $id)
81
    {
82
        $service = new PermissionFormFields($id);
83
        $data = $service->handle();
0 ignored issues
show
Are you sure the assignment to $data is correct as $service->handle() targeting jeremykenedy\LaravelRole...ionFormFields::handle() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
84
85
        return view('laravelroles::laravelroles.crud.permissions.edit', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('laravelrole...rmissions.edit', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
$data of type void is incompatible with the type Illuminate\Contracts\Support\Arrayable|array expected by parameter $data of view(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

85
        return view('laravelroles::laravelroles.crud.permissions.edit', /** @scrutinizer ignore-type */ $data);
Loading history...
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \jeremykenedy\LaravelRoles\App\Http\Requests\UpdatePermissionRequest $request
92
     * @param int                                                                  $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(UpdatePermissionRequest $request, $id)
97
    {
98
        $permissionData = $request->permissionFillData($id);
0 ignored issues
show
The call to jeremykenedy\LaravelRole...t::permissionFillData() has too many arguments starting with $id. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        /** @scrutinizer ignore-call */ 
99
        $permissionData = $request->permissionFillData($id);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
99
        $permission = $this->updatePermission($id, $permissionData);
100
101
        return redirect()->route('laravelroles::roles.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...=> $permission->name))) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
102
            ->with('success', trans('laravelroles::laravelroles.flash-messages.permission-updated', ['permission' => $permission->name]));
103
    }
104
105
    /**
106
     * Remove the specified resource from storage.
107
     *
108
     * @param int $id
109
     *
110
     * @return \Illuminate\Http\Response
111
     */
112
    public function destroy($id)
113
    {
114
        $permission = $this->deletePermission($id);
115
116
        return redirect(route('laravelroles::roles.index'))
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...=> $permission->name))) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
117
                    ->with('success', trans('laravelroles::laravelroles.flash-messages.successDeletedItem', ['type' => 'Permission', 'item' => $permission->name]));
118
    }
119
}
120