Completed
Pull Request — master (#107)
by Glenn
13:15 queued 08:10
created

SettingsController::basicView()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

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