ThemesController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A index() 0 6 1
A store() 0 15 1
A destroy() 0 10 2
1
<?php
2
3
namespace Yajra\CMS\Themes;
4
5
use Illuminate\Http\Request;
6
use Yajra\CMS\Entities\Configuration;
7
use Yajra\CMS\Http\Controllers\Controller;
8
use Yajra\CMS\Themes\Repositories\Repository;
9
10
class ThemesController extends Controller
11
{
12
    /**
13
     * @var \Yajra\CMS\Themes\Repositories\Repository
14
     */
15
    protected $themes;
16
17
    /**
18
     * ThemesController constructor.
19
     *
20
     * @param \Yajra\CMS\Themes\Repositories\Repository $themes
21
     */
22
    public function __construct(Repository $themes)
23
    {
24
        $this->authorizePermissionResource('theme');
25
        $this->themes = $themes;
26
    }
27
28
    /**
29
     * Display themes resource.
30
     *
31
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
32
     */
33
    public function index()
34
    {
35
        $themes = $this->themes->all()->where('type', 'frontend');
36
37
        return view('themes::index', compact('themes'));
38
    }
39
40
    /**
41
     * Store new default theme.
42
     *
43
     * @param \Illuminate\Http\Request $request
44
     * @return \Illuminate\Http\RedirectResponse
45
     */
46
    public function store(Request $request)
47
    {
48
        $this->validate($request, [
0 ignored issues
show
Documentation Bug introduced by
The method validate does not exist on object<Yajra\CMS\Themes\ThemesController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
            'theme' => 'required',
50
        ]);
51
52
        /** @var Configuration $config */
53
        $config        = Configuration::query()->firstOrCreate(['key' => 'themes.frontend']);
54
        $config->value = $request->get('theme');
55
        $config->save();
56
57
        flash()->success(trans('themes::theme.success', ['theme' => $request->get('theme')]));
58
59
        return back();
60
    }
61
62
    /**
63
     * Uninstall a theme.
64
     *
65
     * @param string $theme
66
     * @return \Illuminate\Http\RedirectResponse
67
     */
68
    public function destroy($theme)
69
    {
70
        if ($this->themes->uninstall($theme)) {
71
            flash()->success(trans('themes::theme.deleted', compact('theme')));
72
        } else {
73
            flash()->error(trans('themes::theme.error', compact('theme')));
74
        }
75
76
        return back();
77
    }
78
}
79