UserSettingsController::change_language()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use App\Models\User;
11
use App\Models\UserSetting;
12
use Illuminate\Http\Request;
13
14
class UserSettingsController extends Controller
15
{
16
    public function index()
17
    {
18
        $settings = UserSetting::whereUserId(\Auth::user()->id)->first();
19
20
        return view('auth.settings', [
21
            'settings' => $settings,
22
        ]);
23
    }
24
25
    public function store_rowsPerPage(Request $req)
26
    {
27
        $this->validate($req, [
28
            'row_dev'     => 'required',
29
            'row_games'   => 'required',
30
        ]);
31
32
        $set = UserSetting::whereUserId(\Auth::id())->first();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 26 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
        $set->rows_per_page_games = $req->get('row_games');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34
        $set->rows_per_page_developer = $req->get('row_dev');
35
        $set->save();
36
37
        return redirect()->action('UserSettingsController@index');
38
    }
39
40
    public function change_username(Request $request)
41
    {
42
        $this->validate($request, [
43
            'usernameold'   => 'required',
44
            'usernamenew'   => 'required',
45
        ]);
46
47
        if (\Auth::user()->name == $request->get('usernameold')) {
48
            $check = User::whereName($request->get('usernamenew'))->get();
0 ignored issues
show
Bug introduced by
The method get does only exist in Illuminate\Database\Query\Builder, but not in App\Models\User.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
49
50
            if ($check->count() == 0) {
51
                $user = \Auth::user();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52
                $user->name = $request->get('usernamenew');
53
                $user->save();
54
            }
55
        }
56
57
        return view('auth.settings');
58
    }
59
60
    public function store_password(Request $request)
61
    {
62
        $this->validate($request, [
63
            'passwordold' => 'required',
64
            'password1'   => 'required',
65
            'password2'   => 'required',
66
        ]);
67
68
        if ($request->get('password1') == $request->get('password2')) {
69
            if (\Hash::check($request->get('passwordold'), \Auth::user()->password)) {
70
                $user = \Auth::user();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
71
                $user->password = \Hash::make($request->get('password1'));
72
                $user->save();
73
            }
74
        }
75
76
        return view('auth.settings');
77
    }
78
79
    public function change_setting($setting, $value)
80
    {
81
        $set = UserSetting::whereUserId(\Auth::id())->first();
82
83
        $set->update([$setting => $value]);
84
85
        return redirect()->action('UserSettingsController@index');
86
    }
87
88 View Code Duplication
    public function change_language(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
89
    {
90
        $l = UserSetting::whereUserId(\Auth::id())->first();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
91
        $l->language = $request->get('language');
92
        $l->save();
93
94
        return redirect()->back();
95
    }
96
97 View Code Duplication
    public function change_download_template(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
98
    {
99
        $l = UserSetting::whereUserId(\Auth::id())->first();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 20 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
100
        $l->download_template = $request->get('download_template');
101
        $l->save();
102
103
        return redirect()->back();
104
    }
105
}
106