Issues (112)

App/Http/Controllers/LaravelRolesController.php (12 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\StoreRoleRequest;
8
use jeremykenedy\LaravelRoles\App\Http\Requests\UpdateRoleRequest;
9
use jeremykenedy\LaravelRoles\App\Services\RoleFormFields;
10
use jeremykenedy\LaravelRoles\Traits\RolesAndPermissionsHelpersTrait;
11
use jeremykenedy\LaravelRoles\Traits\RolesUsageAuthTrait;
12
13
class LaravelRolesController 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...\LaravelRolesController: $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 RoleFormFields();
38
        $data = $service->handle();
0 ignored issues
show
Are you sure the assignment to $data is correct as $service->handle() targeting jeremykenedy\LaravelRole...oleFormFields::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.roles.create', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('laravelrole...d.roles.create', $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

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

86
        return view('laravelroles::laravelroles.crud.roles.edit', /** @scrutinizer ignore-type */ $data);
Loading history...
87
    }
88
89
    /**
90
     * Update the specified resource in storage.
91
     *
92
     * @param \jeremykenedy\LaravelRoles\App\Http\Requests\UpdateRoleRequest $request
93
     * @param int                                                            $id
94
     *
95
     * @return \Illuminate\Http\Response
96
     */
97
    public function update(UpdateRoleRequest $request, $id)
98
    {
99
        $roleData = $request->roleFillData();
100
        $rolePermissions = $request->get('permissions');
101
        $role = $this->updateRoleWithPermissions($id, $roleData, $rolePermissions);
102
103
        return redirect()->route('laravelroles::roles.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...role' => $role->name))) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
104
            ->with('success', trans('laravelroles::laravelroles.flash-messages.role-updated', ['role' => $role->name]));
105
    }
106
107
    /**
108
     * Remove the specified resource from storage.
109
     *
110
     * @param int $id
111
     *
112
     * @return \Illuminate\Http\Response
113
     */
114
    public function destroy($id)
115
    {
116
        $role = $this->deleteRole($id);
117
118
        return redirect(route('laravelroles::roles.index'))
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(route('l...item' => $role->name))) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
119
                    ->with('success', trans('laravelroles::laravelroles.flash-messages.successDeletedItem', ['type' => 'Role', 'item' => $role->name]));
120
    }
121
}
122