Test Setup Failed
Pull Request — master (#107)
by Tim
07:58
created

SettingsController::backupView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
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
        if ($config) {
75
            sleep(3);
76
            session()->flash('message', trans('FlashSession.settingSaveSuccess'));
77
            return redirect('settings/general');
78
        } else {
79
            session()->flash('message', trans('FlashSession.settingSaveFailure'));
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