Completed
Push — settings-ui3 ( 981273...ffa13c )
by Tony
03:08
created

SettingsController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 108
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 4 1
A index() 0 4 1
B store() 0 26 5
A show() 0 4 1
A edit() 0 4 1
A update() 0 4 1
A destroy() 0 4 1
1
<?php
2
/*
3
 * Copyright (C) 2016 Tony Murray <[email protected]>
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
/**
18
 * SettingsController.php
19
 *
20
 * @package    LibreNMS
21
 * @author     Tony Murray <[email protected]>
22
 * @copyright  2016 Tony Murray
23
 * @license    @license http://opensource.org/licenses/GPL-3.0 GNU Public License v3 or later
24
 */
25
26
namespace App\Http\Controllers;
27
28
use Illuminate\Http\Request;
29
use Input;
30
use Settings;
31
32
class SettingsController extends Controller
33
{
34
    /**
35
     * Constructor
36
     */
37
    public function __construct(Request $request)
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $this->middleware('auth');
40
    }
41
42
    /**
43
     * Display a listing of the resource.
44
     *
45
     * @return \Illuminate\Http\Response
46
     */
47
    public function index()
48
    {
49
        return view('settings.list');
50
    }
51
52
    /**
53
     * Show the form for creating a new resource.
54
     *
55
     * @return \Illuminate\Http\Response
56
     */
57
    public function create()
58
    {
59
        //
60
    }
61
62
    /**
63
     * Store a newly created resource in storage.
64
     *
65
     * @param  \Illuminate\Http\Request $request
66
     * @return \Illuminate\Http\Response
67
     */
68
    public function store(Request $request)
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
        $key = Input::get('key');
71
        if (Settings::isReadOnly($key)) {
72
            return response('Read only setting', 422);
73
        }
74
75
        $type = Input::get('type');
76
        if ($type == 'settings-value') {
77
            Settings::set($key, Input::get('value'));
78
            return response('OK', 200);
79
        } elseif ($type == 'settings-array') {
80
            $new = Input::get('value');
81
            $current = Settings::get($key);
82
83
            // remove entries with missing indexes
84
            $delete = array_diff_key($current, $new);
85
            foreach ($delete as $index => $value) {
86
                Settings::forget($key . '.' . $index);
87
            }
88
89
            Settings::set($key, $new);
90
            return response('OK', 200);
91
        }
92
        return response('Invalid Data', 422);
93
    }
94
95
    /**
96
     * Display the specified resource.
97
     *
98
     * @param  int $id
99
     * @return \Illuminate\Http\Response
100
     */
101
    public function show($id)
102
    {
103
        return view('settings.list', ['section' => $id]);
104
    }
105
106
    /**
107
     * Show the form for editing the specified resource.
108
     *
109
     * @param  int $id
110
     * @return \Illuminate\Http\Response
111
     */
112
    public function edit($id)
113
    {
114
        return view('settings.list', ['section' => $id]);
115
    }
116
117
    /**
118
     * Update the specified resource in storage.
119
     *
120
     * @param  \Illuminate\Http\Request $request
121
     * @param  int $id
122
     * @return \Illuminate\Http\Response
123
     */
124
    public function update(Request $request, $id)
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
125
    {
126
        //
127
    }
128
129
    /**
130
     * Remove the specified resource from storage.
131
     *
132
     * @param  int $id
133
     * @return \Illuminate\Http\Response
134
     */
135
    public function destroy($id)
136
    {
137
        Settings::forget($id);
138
    }
139
}
140