Completed
Push — master ( a3496d...130652 )
by Jeremy
15:26
created

ThemesManagementController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\DeleteThemeRequest;
7
use App\Http\Requests\StoreThemeRequest;
8
use App\Http\Requests\ThemeRequest;
9
use App\Http\Requests\UpdateThemeRequest;
10
use App\Services\BlogThemeServices;
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 = BlogThemeServices::getAllThemes();
34
        $currentTheme = BlogThemeServices::getBlogTheme();
35
36
        $data = [
37
            'themes'        => $themes,
38
            'currentTheme'  => $currentTheme,
39
        ];
40
41
        return View('admin.themesmanagement.index', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return View('admin.theme...nagement.index', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
42
    }
43
44
    /**
45
     * Create theme view.
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function create()
50
    {
51
        return view('admin.themesmanagement.create-theme');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.theme...nagement.create-theme') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
52
    }
53
54
    /**
55
     * Display the specified resource.
56
     *
57
     * @param int $id
58
     *
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function show($id)
62
    {
63
        $theme = BlogThemeServices::getTheme($id);
64
65
        $data = [
66
            'theme' => $theme,
67
        ];
68
69
        return view('admin.themesmanagement.show-theme')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.theme...ow-theme')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
70
    }
71
72
    /**
73
     * Edit theme view.
74
     *
75
     * @param int $id Theme Id
76
     *
77
     * @return \Illuminate\Http\Response
78
     */
79
    public function edit($id)
80
    {
81
        $theme = BlogThemeServices::getTheme($id);
82
83
        $data = [
84
            'theme' => $theme,
85
        ];
86
87
        return view('admin.themesmanagement.edit-theme')->with($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.theme...it-theme')->with($data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
88
    }
89
90
    /**
91
     * Update a theme resource.
92
     *
93
     * @param \App\Http\Requests\UpdateThemeRequest $request
94
     * @param int                                   $id
95
     *
96
     * @return \Illuminate\Http\Response
97
     */
98
    public function update(UpdateThemeRequest $request, $id)
99
    {
100
        $theme = BlogThemeServices::getTheme($id);
101
        $theme->fill($request->validated())->save();
102
103
        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...
104
                ->back()
105
                ->with('success', trans('themes.updateSuccess'));
106
    }
107
108
    /**
109
     * Store a new blog theme request.
110
     *
111
     * @param \App\Http\Requests\StoreThemeRequest $request
112
     *
113
     * @return \Illuminate\Http\Response
114
     */
115
    public function store(StoreThemeRequest $request)
116
    {
117
        $theme = BlogThemeServices::storeNewTheme($request->validated());
118
119
        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...
120
    }
121
122
    /**
123
     * Update the specified resource in storage.
124
     *
125
     * @param \App\Http\Requests\UpdateDefaultThemeRequest $request
0 ignored issues
show
Bug introduced by
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...
126
     *
127
     * @return \Illuminate\Http\Response
128
     */
129
    public function updateDefaultTheme(ThemeRequest $request)
130
    {
131
        $theme = BlogThemeServices::updateDefaultThemeSetting($request->currentTheme);
132
133
        $data = [
134
            'theme' => $theme,
135
        ];
136
137
        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...
138
            'code'      => 202,
139
            'message'   => trans('themes.theme_updated'),
140
            'data'      => $data,
141
        ], Response::HTTP_ACCEPTED);
142
    }
143
144
    /**
145
     * Remove the specified resource from storage.
146
     *
147
     * @param \App\Http\Requests\UpdateDefaultThemeRequest $request
148
     *
149
     * @return \Illuminate\Http\Response
150
     */
151
    public function destroy(DeleteThemeRequest $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

151
    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...
152
    {
153
        $theme = BlogThemeServices::deleteBlogTheme($id);
154
155
        return redirect()
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...ame' => $theme->name))) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
156
                ->route('themes')
157
                ->withSuccess(trans('themes.theme_deleted', ['name' => $theme->name]));
158
    }
159
}
160