ThemesController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 5
dl 0
loc 69
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A destroy() 0 10 2
A __construct() 0 5 1
A store() 0 15 1
1
<?php
2
3
namespace Yajra\CMS\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Yajra\CMS\Entities\Configuration;
7
use Yajra\CMS\Repositories\Theme\Repository;
8
9
class ThemesController extends Controller
10
{
11
    /**
12
     * @var \Yajra\CMS\Repositories\Theme\Repository
13
     */
14
    protected $themes;
15
16
    /**
17
     * ThemesController constructor.
18
     *
19
     * @param \Yajra\CMS\Repositories\Theme\Repository $themes
20
     */
21
    public function __construct(Repository $themes)
22
    {
23
        $this->authorizePermissionResource('theme');
24
        $this->themes = $themes;
25
    }
26
27
    /**
28
     * Display themes resource.
29
     *
30
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
31
     */
32
    public function index()
33
    {
34
        $themes = $this->themes->all();
35
36
        return view('administrator.themes.index', compact('themes'));
37
    }
38
39
    /**
40
     * Store new default theme.
41
     *
42
     * @param \Illuminate\Http\Request $request
43
     * @return \Illuminate\Http\RedirectResponse
44
     */
45
    public function store(Request $request)
46
    {
47
        $this->validate($request, [
48
            'theme' => 'required',
49
        ]);
50
51
        /** @var Configuration $config */
52
        $config        = Configuration::query()->firstOrCreate(['key' => 'theme.frontend']);
53
        $config->value = $request->get('theme');
54
        $config->save();
55
56
        flash()->success(trans('cms::theme.success', ['theme' => $request->get('theme')]));
0 ignored issues
show
Bug introduced by
It seems like trans('cms::theme.succes...request->get('theme'))) targeting trans() can also be of type object<Illuminate\Contra...Translation\Translator>; however, Laracasts\Flash\FlashNotifier::success() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
57
58
        return back();
59
    }
60
61
    /**
62
     * Uninstall a theme.
63
     *
64
     * @param string $theme
65
     * @return \Illuminate\Http\RedirectResponse
66
     */
67
    public function destroy($theme)
68
    {
69
        if ($this->themes->uninstall($theme)) {
70
            flash()->success(trans('cms::theme.deleted', compact('theme')));
0 ignored issues
show
Bug introduced by
It seems like trans('cms::theme.deleted', compact('theme')) targeting trans() can also be of type object<Illuminate\Contra...Translation\Translator>; however, Laracasts\Flash\FlashNotifier::success() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
71
        } else {
72
            flash()->error(trans('cms::theme.error', compact('theme')));
0 ignored issues
show
Bug introduced by
It seems like trans('cms::theme.error', compact('theme')) targeting trans() can also be of type object<Illuminate\Contra...Translation\Translator>; however, Laracasts\Flash\FlashNotifier::error() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
73
        }
74
75
        return back();
76
    }
77
}
78