SettingController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 78
ccs 0
cts 15
cp 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A update() 0 11 2
A index() 0 13 2
1
<?php
2
3
namespace A17\Twill\Http\Controllers\Admin;
4
5
use A17\Twill\Repositories\SettingRepository;
6
use Illuminate\Config\Repository as Config;
7
use Illuminate\Http\Request;
8
use Illuminate\Routing\Redirector;
9
use Illuminate\Routing\UrlGenerator;
10
use Illuminate\View\Factory as ViewFactory;
11
12
class SettingController extends Controller
13
{
14
    /**
15
     * @var Config
16
     */
17
    protected $config;
18
19
    /**
20
     * @var SettingRepository
21
     */
22
    protected $settings;
23
24
    /**
25
     * @var Redirector
26
     */
27
    protected $redirector;
28
29
    /**
30
     * @var UrlGenerator
31
     */
32
    protected $urlGenerator;
33
34
    /**
35
     * @var ViewFactory
36
     */
37
    protected $viewFactory;
38
39
    public function __construct(
40
        Config $config,
41
        SettingRepository $settings,
42
        Redirector $redirector,
43
        UrlGenerator $urlGenerator,
44
        ViewFactory $viewFactory
45
    ) {
46
        parent::__construct();
47
48
        $this->config = $config;
49
        $this->settings = $settings;
50
        $this->redirector = $redirector;
51
        $this->urlGenerator = $urlGenerator;
52
        $this->viewFactory = $viewFactory;
53
    }
54
55
    /**
56
     * @param string $section
57
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
58
     */
59
    public function index($section)
60
    {
61
        return $this->viewFactory->exists('admin.settings.' . $section)
62
        ? $this->viewFactory->make('admin.settings.' . $section, [
63
            'customForm' => true,
64
            'editableTitle' => false,
65
            'customTitle' => ucfirst($section) . ' settings',
66
            'section' => $section,
67
            'form_fields' => $this->settings->getFormFields($section),
68
            'saveUrl' => $this->urlGenerator->route('admin.settings.update', $section),
69
            'translate' => true,
70
        ])
71
        : $this->redirector->back();
72
    }
73
74
    /**
75
     * @param mixed $section
76
     * @param Request $request
77
     * @return \Illuminate\Http\RedirectResponse
78
     */
79
    public function update($section, Request $request)
80
    {
81
        if (array_key_exists('cancel', $request->all())) {
82
            return $this->redirector->back();
83
        }
84
85
        $this->settings->saveAll($request->except('_token'), $section);
86
87
        fireCmsEvent('cms-settings.saved');
88
89
        return $this->redirector->back();
90
    }
91
}
92