Completed
Push — develop ( 3d08a5...0d51b0 )
by Daniel
9s
created

SettingsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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
     * Display a listing of the resource.
36
     *
37
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
38
     */
39
    public function index()
40
    {
41
        return view('settings.list');
42
    }
43
44
    /**
45
     * Show the form for creating a new resource.
46
     *
47
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
48
     */
49
    public function create()
50
    {
51
        //
52
    }
53
54
    /**
55
     * Store a newly created resource in storage.
56
     *
57
     * @param  \Illuminate\Http\Request $request
58
     * @return \Illuminate\Http\Response
59
     */
60
    public function store(Request $request)
61
    {
62
        $key = Input::get('key');
63
        if (Settings::isReadOnly($key)) {
64
            return response('Read only setting', 422);
65
        }
66
67
        $type = Input::get('type');
68
        $value = Input::get('value');
69
70
        if ($type == 'settings-value') {
71
            Settings::set($key, $value);
72
            return response('OK', 200);
73
        }
74
        elseif ($type == 'settings-array') {
75
            $current = Settings::get($key);
76
77
            // remove entries with missing indexes
78
            $delete = array_diff_key($current, $value);
79
            foreach (array_keys($delete) as $index) {
80
                Settings::forget($key.'.'.$index);
81
            }
82
83
            Settings::set($key, $value);
84
            return response('OK', 200);
85
        }
86
87
        return response('Invalid Data', 422);
88
    }
89
90
    /**
91
     * Display the specified resource.
92
     *
93
     * @param  int $id
94
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
95
     */
96
    public function show($id)
97
    {
98
        return view('settings.list', ['section' => $id]);
99
    }
100
101
    /**
102
     * Show the form for editing the specified resource.
103
     *
104
     * @param  int $id
105
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
106
     */
107
    public function edit($id)
108
    {
109
        return view('settings.list', ['section' => $id]);
110
    }
111
112
    /**
113
     * Update the specified resource in storage.
114
     *
115
     * @param  \Illuminate\Http\Request $request
116
     * @param  int $id
117
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
118
     */
119
    public function update(Request $request, $id)
120
    {
121
        //
122
    }
123
124
    /**
125
     * Remove the specified resource from storage.
126
     *
127
     * @param  int $id
128
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
129
     */
130
    public function destroy($id)
131
    {
132
        Settings::forget($id);
133
    }
134
}
135