Passed
Push — dev6 ( 77ef26...6e2ff7 )
by Ron
16:42
created

UserController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 0
c 2
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Actions\GetUserRoles;
6
use App\Events\Admin\NewUserCreated;
7
use App\Http\Controllers\Controller;
8
use App\Http\Requests\User\UserRequest;
9
use App\Models\User;
10
use App\Models\UserRoles;
11
use App\Models\UserSetting;
12
use App\Models\UserSettingType;
13
use Illuminate\Http\Request;
14
use Illuminate\Support\Facades\Auth;
15
use Inertia\Inertia;
16
17
class UserController extends Controller
18
{
19
    /**
20
     * Display a listing of the resource.
21
     *
22
     * @return \Illuminate\Http\Response
23
     */
24
    public function index()
25
    {
26
        //
27
    }
28
29
    /**
30
     * Show the new user form
31
     */
32
    public function create()
33
    {
34
        $this->authorize('create', User::class);
35
36
        return Inertia::render('Admin/User/Create', [
37
            'roles' => (new GetUserRoles)->run(Auth::user()),
1 ignored issue
show
Bug introduced by
It seems like Illuminate\Support\Facades\Auth::user() can also be of type null; however, parameter $user of App\Actions\GetUserRoles::run() does only seem to accept App\Models\User, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            'roles' => (new GetUserRoles)->run(/** @scrutinizer ignore-type */ Auth::user()),
Loading history...
38
        ]);
39
    }
40
41
    /**
42
     * Store a newly created user
43
     */
44
    public function store(UserRequest $request)
45
    {
46
        $newUser = User::create($request->toArray());
47
48
        //  Add the users settings data
49
        $settings = UserSettingType::all();
50
        foreach($settings as $setting)
51
        {
52
            UserSetting::create([
53
                'user_id'         => $newUser->user_id,
54
                'setting_type_id' => $setting->setting_type_id,
55
                'value'           => true,
56
            ]);
57
        }
58
59
        event(new NewUserCreated($newUser));
60
        return back()->with([
61
            'message' => 'New User Created',
62
            'type'    => 'success',
63
        ]);
64
    }
65
66
    /**
67
     * Display the specified resource.
68
     *
69
     * @param  int  $id
70
     * @return \Illuminate\Http\Response
71
     */
72
    public function show($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

72
    public function show(/** @scrutinizer ignore-unused */ $id)

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

Loading history...
73
    {
74
        //
75
    }
76
77
    /**
78
     * Show the form for editing the specified resource.
79
     *
80
     * @param  int  $id
81
     * @return \Illuminate\Http\Response
82
     */
83
    public function edit($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

83
    public function edit(/** @scrutinizer ignore-unused */ $id)

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

Loading history...
84
    {
85
        //
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param  \Illuminate\Http\Request  $request
92
     * @param  int  $id
93
     * @return \Illuminate\Http\Response
94
     */
95
    public function update(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

95
    public function update(Request $request, /** @scrutinizer ignore-unused */ $id)

This check looks for 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 $request is not used and could be removed. ( Ignorable by Annotation )

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

95
    public function update(/** @scrutinizer ignore-unused */ Request $request, $id)

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

Loading history...
96
    {
97
        //
98
    }
99
100
    /**
101
     * Remove the specified resource from storage.
102
     *
103
     * @param  int  $id
104
     * @return \Illuminate\Http\Response
105
     */
106
    public function destroy($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

106
    public function destroy(/** @scrutinizer ignore-unused */ $id)

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

Loading history...
107
    {
108
        //
109
    }
110
}
111