Completed
Pull Request — master (#107)
by Glenn
12:00 queued 06:04
created

SettingsController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 8
Bugs 4 Features 2
Metric Value
wmc 5
c 8
b 4
f 2
lcom 0
cbo 3
dl 0
loc 86
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B basicView() 0 30 1
A generalUpdate() 0 21 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
    public function __construct()
14
    {
15
        $this->middleware('auth');
16
    }
17
18
    /**
19
     * Display a listing of the resource.
20
     *
21
     * @return \Illuminate\Http\Response
22
     */
23
    public function basicView()
24
    {
25
26
    $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...
27
    'Y-m-d' => '2010-12-23',
28
    'm-d-Y' => '12-23-2010',
29
    'd-m-Y' => '23-12-2010',
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
    'd.m.Y' => '23.12.2010',
35
    'm.d.Y' => '12.23.2010',
36
  );
37
38
    $data['time_formats'] = array (
39
    'H:i' => '23:00',
40
    'h:ia' => '11:00pm',
41
    'h:iA' => '11:00PM',
42
    'h:i a' => '11:00 pm',
43
    'h:i A' => '11:00 PM',
44
  );
45
    
46
    $data['title'] = config('timecontrol.title');
47
    $data['email'] = config('timecontrol.email');
48
    $data['date'] = config('timecontrol.date');
49
    $data['time'] = config('timecontrol.time');
50
51
     return view('settings/basic', $data);
52
    }
53
54
    /**
55
     * Update the basic settings.
56
     *
57
     * @param  \Illuminate\Http\Request  $request     
58
     * @return \Illuminate\Http\Response
59
     */
60
    public function generalUpdate(Request $request)
61
    {
62
63
        $config = new \Larapack\ConfigWriter\Repository('timecontrol');
64
        $config->set('title', $request->get('title')); 
65
        $config->set('email', $request->get('email')); 
66
        $config->set('date', $request->get('date')); 
67
        $config->set('time', $request->get('time'));
68
        $config->save(); 
69
70
        if ($config){
71
            sleep(3);
72
            session()->flash('message', 'Settings have been saved');
73
            return redirect('settings/general');
74
        }
75
76
        else {
77
            session()->flash('message', 'Settings have not been saved, please verify');
78
            return redirect('settings/general');
79
        }
80
   }
81
82
    /**
83
     * Display a form to configure the backup settings.
84
     *
85
     * @return \Illuminate\Http\Response
86
     */
87
    public function backupView()
88
    {
89
        $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...
90
        $data['exclude'] = config('laravel-backup.backup.source.files.exclude');
91
92
        $data['keepAllBackupsForDays'] = config('laravel-backup.cleanup.defaultStrategy.keepAllBackupsForDays');
93
94
        return view('settings/backup', $data);
95
    }
96
}
97