Issues (64)

Http/Controllers/ThemesManagementController.php (10 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\DeleteThemeRequest;
6
use App\Http\Requests\StoreThemeRequest;
7
use App\Http\Requests\ThemeRequest;
8
use App\Http\Requests\UpdateThemeRequest;
9
use App\Models\Theme;
10
use App\Services\ThemeServices;
11
use Illuminate\Http\Request;
12
use Illuminate\Http\Response;
13
14
class ThemesManagementController extends Controller
15
{
16
    /**
17
     * Create a new controller instance.
18
     *
19
     * @return void
20
     */
21
    public function __construct()
22
    {
23
        $this->middleware('auth');
24
    }
25
26
    /**
27
     * Display a listing of the resource.
28
     *
29
     * @return \Illuminate\Http\Response
30
     */
31
    public function index()
32
    {
33
        $themes = ThemeServices::getAllThemes();
34
        $currentTheme = ThemeServices::getTheTheme();
35
        $enabledThemes = Theme::enabledThemes()->get();
36
        $user = auth()->user();
37
38
        $data = [
39
            'themes'        => $themes,
40
            'currentTheme'  => $currentTheme,
41
            'enabledThemes' => $enabledThemes,
42
            'user'          => $user,
43
        ];
44
45
        return View('pages.themes.index', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return View('pages.themes.index', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
46
    }
47
48
    /**
49
     * Create theme view.
50
     *
51
     * @return \Illuminate\Http\Response
52
     */
53
    public function create()
54
    {
55
        return view('pages.themes.create-theme');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('pages.themes.create-theme') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        $theme = ThemeServices::getTheme($id);
68
69
        $data = [
70
            'theme' => $theme,
71
        ];
72
73
        return view('pages.themes.show-theme')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('pages.theme...ow-theme')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
74
    }
75
76
    /**
77
     * Edit theme view.
78
     *
79
     * @param int $id Theme Id
80
     *
81
     * @return \Illuminate\Http\Response
82
     */
83
    public function edit($id)
84
    {
85
        $theme = ThemeServices::getTheme($id);
86
87
        $data = [
88
            'theme' => $theme,
89
        ];
90
91
        return view('pages.themes.edit-theme')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('pages.theme...it-theme')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
92
    }
93
94
    /**
95
     * Update a theme resource.
96
     *
97
     * @param \App\Http\Requests\UpdateThemeRequest $request
98
     * @param int                                   $id
99
     *
100
     * @return \Illuminate\Http\Response
101
     */
102
    public function update(UpdateThemeRequest $request, $id)
103
    {
104
        $theme = ThemeServices::getTheme($id);
105
        $theme->fill($request->validated())->save();
106
107
        return redirect()
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...themes.updateSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
108
                ->back()
109
                ->with('success', trans('themes.updateSuccess'));
110
    }
111
112
    /**
113
     * Store a new blog theme request.
114
     *
115
     * @param \App\Http\Requests\StoreThemeRequest $request
116
     *
117
     * @return \Illuminate\Http\Response
118
     */
119
    public function store(StoreThemeRequest $request)
120
    {
121
        $theme = ThemeServices::storeNewTheme($request->validated());
122
123
        return redirect('admin/themes/'.$theme->id)->with('success', trans('themes.createSuccess'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('admin/t...themes.createSuccess')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
124
    }
125
126
    /**
127
     * Update the specified resource in storage.
128
     *
129
     * @param \App\Http\Requests\UpdateDefaultThemeRequest $request
0 ignored issues
show
The type App\Http\Requests\UpdateDefaultThemeRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
130
     *
131
     * @return \Illuminate\Http\Response
132
     */
133
    public function updateDefaultTheme(ThemeRequest $request)
134
    {
135
        $theme = ThemeServices::updateDefaultThemeSetting($request->currentTheme);
136
137
        $data = [
138
            'theme' => $theme,
139
        ];
140
141
        return response()->json([
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(...esponse::HTTP_ACCEPTED) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
142
            'code'      => 202,
143
            'message'   => trans('themes.theme_updated'),
144
            'data'      => $data,
145
        ], Response::HTTP_ACCEPTED);
146
    }
147
148
    /**
149
     * Remove the specified resource from storage.
150
     *
151
     * @param \App\Http\Requests\UpdateDefaultThemeRequest $request
152
     *
153
     * @return \Illuminate\Http\Response
154
     */
155
    public function destroy(DeleteThemeRequest $request, $id)
0 ignored issues
show
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

155
    public function destroy(/** @scrutinizer ignore-unused */ DeleteThemeRequest $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...
156
    {
157
        $theme = ThemeServices::deleteTheme($id);
158
159
        return redirect()
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...ame' => $theme->name))) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
160
                ->route('themes')
161
                ->withSuccess(trans('themes.theme_deleted', ['name' => $theme->name]));
162
    }
163
}
164