Completed
Pull Request — master (#107)
by Glenn
14:55 queued 07:42
created

SettingsController::basicView()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
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
     * SettingsController Constructor 
15
     */ 
16
    public function __construct()
17
    {
18
        $this->middleware('auth');
19
        $this->middleware('lang');
20
    }
21
22
    /**
23
     * Display a listing of the resource.
24
     *
25
     * @return \Illuminate\Http\Response
26
     */
27
    public function basicView()
28
    {
29
30
        $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...
31
            'Y-m-d' => '2010-12-23',
32
            'm-d-Y' => '12-23-2010',
33
            'd-m-Y' => '23-12-2010',
34
            'Y/m/d' => '2010/12/23',
35
            'm/d/Y' => '12/23/2010',
36
            'd/m/Y' => '23/12/2010',
37
            'Y.m.d' => '2010.12.23',
38
            'd.m.Y' => '23.12.2010',
39
            'm.d.Y' => '12.23.2010',
40
        );
41
42
        $data['time_formats'] = array (
43
            'H:i' => '23:00',
44
            'h:ia' => '11:00pm',
45
            'h:iA' => '11:00PM',
46
            'h:i a' => '11:00 pm',
47
            'h:i A' => '11:00 PM',
48
        );
49
    
50
        $data['title'] = config('timecontrol.title');
51
        $data['email'] = config('timecontrol.email');
52
        $data['date'] = config('timecontrol.date');
53
        $data['time'] = config('timecontrol.time');
54
55
        return view('settings/basic', $data);
56
    }
57
58
    /**
59
     * Update the basic settings.
60
     *
61
     * @param  \Illuminate\Http\Request  $request     
62
     * @return \Illuminate\Http\Response
63
     */
64
    public function generalUpdate(Request $request)
65
    {
66
67
        $config = new \Larapack\ConfigWriter\Repository('timecontrol');
68
        $config->set('title', $request->get('title')); 
69
        $config->set('email', $request->get('email')); 
70
        $config->set('date', $request->get('date')); 
71
        $config->set('time', $request->get('time'));
72
        $config->save(); 
73
74 View Code Duplication
        if ($config) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
            sleep(3);
76
            session()->flash('message', 'Settings have been saved');
77
            return redirect('settings/general');
78
        } else {
79
            session()->flash('message', 'Settings have not been saved, please verify');
80
            return redirect('settings/general');
81
        }
82
    }
83
84
    /**
85
     * Display a form to configure the backup settings.
86
     *
87
     * @return \Illuminate\Http\Response
88
     */
89
    public function backupView()
90
    {
91
        $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...
92
        $data['exclude'] = config('laravel-backup.backup.source.files.exclude');
93
94
        $data['keepAllBackupsForDays'] = config('laravel-backup.cleanup.defaultStrategy.keepAllBackupsForDays');
95
96
        return view('settings/backup', $data);
97
    }
98
}
99