GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ThemesManagementController   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 166
rs 10
c 0
b 0
f 0
wmc 17

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A update() 0 15 2
A store() 0 23 2
A create() 0 3 1
A index() 0 7 1
A destroy() 0 12 2
A edit() 0 18 4
A show() 0 18 4
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Theme;
6
use App\Models\User;
7
use Auth;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Input;
10
use Validator;
11
12
class ThemesManagementController extends Controller
13
{
14
    /**
15
     * Create a new controller instance.
16
     *
17
     * @return void
18
     */
19
    public function __construct()
20
    {
21
        $this->middleware('auth');
22
    }
23
24
    /**
25
     * Display a listing of the resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function index()
30
    {
31
        $users = User::all();
32
33
        $themes = Theme::orderBy('name', 'asc')->get();
34
35
        return View('themesmanagement.show-themes', compact('themes', 'users'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return View('themesmanag...act('themes', 'users')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
36
    }
37
38
    /**
39
     * Show the form for creating a new resource.
40
     *
41
     * @return \Illuminate\Http\Response
42
     */
43
    public function create()
44
    {
45
        return view('themesmanagement.add-theme');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('themesmanagement.add-theme') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
46
    }
47
48
    /**
49
     * Store a newly created resource in storage.
50
     *
51
     * @param \Illuminate\Http\Request $request
52
     *
53
     * @return \Illuminate\Http\Response
54
     */
55
    public function store(Request $request)
56
    {
57
        $input = Input::only('name', 'link', 'notes', 'status');
58
59
        $validator = Validator::make($input, Theme::rules());
60
61
        if ($validator->fails()) {
62
            return back()->withErrors($validator)->withInput();
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->withError...validator)->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
63
        }
64
65
        $theme = Theme::create([
66
            'name'          => $request->input('name'),
67
            'link'          => $request->input('link'),
68
            'notes'         => $request->input('notes'),
69
            'status'        => $request->input('status'),
70
            'taggable_id'   => 0,
71
            'taggable_type' => 'theme',
72
        ]);
73
74
        $theme->taggable_id = $theme->id;
75
        $theme->save();
76
77
        return redirect('themes/'.$theme->id)->with('success', trans('themes.createSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('themes/...themes.createSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
78
    }
79
80
    /**
81
     * Display the specified resource.
82
     *
83
     * @param int $id
84
     *
85
     * @return \Illuminate\Http\Response
86
     */
87
    public function show($id)
88
    {
89
        $theme = Theme::find($id);
90
        $users = User::all();
91
        $themeUsers = [];
92
93
        foreach ($users as $user) {
94
            if ($user->profile && $user->profile->theme_id === $theme->id) {
95
                $themeUsers[] = $user;
96
            }
97
        }
98
99
        $data = [
100
            'theme'      => $theme,
101
            'themeUsers' => $themeUsers,
102
        ];
103
104
        return view('themesmanagement.show-theme')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('themesmanag...ow-theme')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
105
    }
106
107
    /**
108
     * Show the form for editing the specified resource.
109
     *
110
     * @param int $id
111
     *
112
     * @return \Illuminate\Http\Response
113
     */
114
    public function edit($id)
115
    {
116
        $theme = Theme::find($id);
117
        $users = User::all();
118
        $themeUsers = [];
119
120
        foreach ($users as $user) {
121
            if ($user->profile && $user->profile->theme_id === $theme->id) {
122
                $themeUsers[] = $user;
123
            }
124
        }
125
126
        $data = [
127
            'theme'      => $theme,
128
            'themeUsers' => $themeUsers,
129
        ];
130
131
        return view('themesmanagement.edit-theme')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('themesmanag...it-theme')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
132
    }
133
134
    /**
135
     * Update the specified resource in storage.
136
     *
137
     * @param \Illuminate\Http\Request $request
138
     * @param int                      $id
139
     *
140
     * @return \Illuminate\Http\Response
141
     */
142
    public function update(Request $request, $id)
0 ignored issues
show
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

142
    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...
143
    {
144
        $theme = Theme::find($id);
145
146
        $input = Input::only('name', 'link', 'notes', 'status');
147
148
        $validator = Validator::make($input, Theme::rules($id));
149
150
        if ($validator->fails()) {
151
            return back()->withErrors($validator)->withInput();
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->withError...validator)->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
152
        }
153
154
        $theme->fill($input)->save();
155
156
        return redirect('themes/'.$theme->id)->with('success', trans('themes.updateSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('themes/...themes.updateSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
157
    }
158
159
    /**
160
     * Remove the specified resource from storage.
161
     *
162
     * @param int $id
163
     *
164
     * @return \Illuminate\Http\Response
165
     */
166
    public function destroy($id)
167
    {
168
        $default = Theme::findOrFail(1);
169
        $theme = Theme::findOrFail($id);
170
171
        if ($theme->id != $default->id) {
172
            $theme->delete();
173
174
            return redirect('themes')->with('success', trans('themes.deleteSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('themes'...themes.deleteSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
175
        }
176
177
        return back()->with('error', trans('themes.deleteSelfError'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return back()->with('err...emes.deleteSelfError')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
178
    }
179
}
180