Completed
Pull Request — master (#107)
by Glenn
23:25 queued 15:40
created

SettingsController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 11
Bugs 4 Features 3
Metric Value
wmc 5
c 11
b 4
f 3
lcom 0
cbo 3
dl 0
loc 87
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B basicView() 0 30 1
A generalUpdate() 0 19 2
A backupView() 0 9 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
7
use App\Http\Requests;
8
use App\Http\Controllers\Controller;
9
10
11
class SettingsController extends Controller
12
{
13
    /**
14
     * SettingsController Constructor 
15
     */ 
16
    public function __construct()
17
    {
18
        $this->middleware('auth');
19
    }
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function basicView()
27
    {
28
29
        $data['date_formats'] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
30
            'Y-m-d' => '2010-12-23',
31
            'm-d-Y' => '12-23-2010',
32
            'd-m-Y' => '23-12-2010',
33
            'Y/m/d' => '2010/12/23',
34
            'm/d/Y' => '12/23/2010',
35
            'd/m/Y' => '23/12/2010',
36
            'Y.m.d' => '2010.12.23',
37
            'd.m.Y' => '23.12.2010',
38
            'm.d.Y' => '12.23.2010',
39
        );
40
41
        $data['time_formats'] = array (
42
            'H:i' => '23:00',
43
            'h:ia' => '11:00pm',
44
            'h:iA' => '11:00PM',
45
            'h:i a' => '11:00 pm',
46
            'h:i A' => '11:00 PM',
47
        );
48
    
49
        $data['title'] = config('timecontrol.title');
50
        $data['email'] = config('timecontrol.email');
51
        $data['date'] = config('timecontrol.date');
52
        $data['time'] = config('timecontrol.time');
53
54
        return view('settings/basic', $data);
55
    }
56
57
    /**
58
     * Update the basic settings.
59
     *
60
     * @param  \Illuminate\Http\Request  $request     
61
     * @return \Illuminate\Http\Response
62
     */
63
    public function generalUpdate(Request $request)
64
    {
65
66
        $config = new \Larapack\ConfigWriter\Repository('timecontrol');
67
        $config->set('title', $request->get('title')); 
68
        $config->set('email', $request->get('email')); 
69
        $config->set('date', $request->get('date')); 
70
        $config->set('time', $request->get('time'));
71
        $config->save(); 
72
73
        if ($config) {
74
            sleep(3);
75
            session()->flash('message', 'Settings have been saved');
76
            return redirect('settings/general');
77
        } else {
78
            session()->flash('message', 'Settings have not been saved, please verify');
79
            return redirect('settings/general');
80
        }
81
    }
82
83
    /**
84
     * Display a form to configure the backup settings.
85
     *
86
     * @return \Illuminate\Http\Response
87
     */
88
    public function backupView()
89
    {
90
        $data['include'] = config('laravel-backup.backup.source.files.include');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
91
        $data['exclude'] = config('laravel-backup.backup.source.files.exclude');
92
93
        $data['keepAllBackupsForDays'] = config('laravel-backup.cleanup.defaultStrategy.keepAllBackupsForDays');
94
95
        return view('settings/backup', $data);
96
    }
97
}
98