Completed
Push — master ( a3d07b...f35753 )
by Arjay
14:10
created

ThemesController::destroy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 10
rs 9.4285
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\Theme\Repository;
8
9
class ThemesController extends Controller
10
{
11
    /**
12
     * @var \Yajra\CMS\Theme\Repository
13
     */
14
    protected $themes;
15
16
    /**
17
     * ThemesController constructor.
18
     *
19
     * @param \Yajra\CMS\Theme\Repository $themes
20
     */
21
    public function __construct(Repository $themes)
22
    {
23
        $this->themes = $themes;
24
    }
25
26
    /**
27
     * Display themes resource.
28
     *
29
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
30
     */
31
    public function index()
32
    {
33
        $themes = $this->themes->all();
34
35
        return view('administrator.themes.index', compact('themes'));
36
    }
37
38
    /**
39
     * Store new default theme.
40
     *
41
     * @param \Illuminate\Http\Request $request
42
     * @return \Illuminate\Http\RedirectResponse
43
     */
44
    public function store(Request $request)
45
    {
46
        /** @var Configuration $config */
47
        $config        = Configuration::query()->firstOrCreate(['key' => 'theme.frontend']);
48
        $config->value = $request->get('theme');
49
        $config->save();
50
51
        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<Symfony\Component...on\TranslatorInterface>; 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...
52
53
        return back();
54
    }
55
56
    /**
57
     * Uninstall a theme.
58
     *
59
     * @param string $theme
60
     * @return \Illuminate\Http\RedirectResponse
61
     */
62
    public function destroy($theme)
63
    {
64
        if ($this->themes->uninstall($theme)) {
65
            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<Symfony\Component...on\TranslatorInterface>; 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...
66
        } else {
67
            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<Symfony\Component...on\TranslatorInterface>; 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...
68
        }
69
70
        return back();
71
    }
72
}
73