Completed
Pull Request — master (#107)
by Glenn
15:22 queued 07:05
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
/**
12
 * Class SettingsController
13
 * @package App\Http\Controllers
14
 */
15
class SettingsController extends Controller
16
{
17
    /**
18
     * SettingsController Constructor 
19
     */ 
20
    public function __construct()
21
    {
22
        $this->middleware('auth');
23
        $this->middleware('lang');
24
    }
25
26
    /**
27
     * Display a listing of the resource.
28
     *
29
     * @return \Illuminate\Http\Response
30
     */
31
    public function basicView()
32
    {
33
34
        $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...
35
            'Y-m-d' => '2010-12-23',
36
            'm-d-Y' => '12-23-2010',
37
            'd-m-Y' => '23-12-2010',
38
            'Y/m/d' => '2010/12/23',
39
            'm/d/Y' => '12/23/2010',
40
            'd/m/Y' => '23/12/2010',
41
            'Y.m.d' => '2010.12.23',
42
            'd.m.Y' => '23.12.2010',
43
            'm.d.Y' => '12.23.2010',
44
        );
45
46
        $data['time_formats'] = array (
47
            'H:i' => '23:00',
48
            'h:ia' => '11:00pm',
49
            'h:iA' => '11:00PM',
50
            'h:i a' => '11:00 pm',
51
            'h:i A' => '11:00 PM',
52
        );
53
    
54
        $data['title'] = config('timecontrol.title');
55
        $data['email'] = config('timecontrol.email');
56
        $data['date'] = config('timecontrol.date');
57
        $data['time'] = config('timecontrol.time');
58
59
        return view('settings/basic', $data);
60
    }
61
62
    /**
63
     * Update the basic settings.
64
     *
65
     * @param Requests\generalSettingsvalidator $request
66
     * @return \Illuminate\Http\Response
67
     */
68
    public function generalUpdate(Requests\generalSettingsvalidator $request)
69
    {
70
71
        $config = new \Larapack\ConfigWriter\Repository('timecontrol');
72
        $config->set('title', $request->title);
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<App\Http\Requests...neralSettingsvalidator>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
73
        $config->set('email', $request->email);
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\Http\Requests...neralSettingsvalidator>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
74
        $config->set('date', $request->date);
0 ignored issues
show
Documentation introduced by
The property date does not exist on object<App\Http\Requests...neralSettingsvalidator>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
75
        $config->set('time', $request->time);
0 ignored issues
show
Documentation introduced by
The property time does not exist on object<App\Http\Requests...neralSettingsvalidator>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

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