GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

UsersController::account()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Afrittella\BackProject\Http\Controllers;
4
5
use Afrittella\BackProject\Http\Requests\AccountStore;
6
use Afrittella\BackProject\Repositories\Users;
7
use Afrittella\BackProject\Repositories\Roles;
8
use Afrittella\BackProject\Http\Requests\UserAdd;
9
use Afrittella\BackProject\Http\Requests\UserEdit;
10
use Afrittella\BackProject\Events\UserRegistered as Registered;
11
use Prologue\Alerts\Facades\Alert;
12
use Auth;
13
14
class UsersController extends Controller
15
{
16
    public function __construct()
17
    {
18
        $this->middleware('admin');
19
    }
20
21
    /**
22
     * Show all users
23
     */
24
    public function index(Users $users)
25
    {
26
        return view('back-project::users.index')->with('users', $users->transform($users->all()));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
27
    }
28
29
    public function edit(Users $users, Roles $roles, $id)
30
    {
31
        return view('back-project::users.edit')->with('user', $users->find($id))->with('roles', $roles->all());
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
32
    }
33
34
    public function account()
35
    {
36
        $user = Auth::user();
0 ignored issues
show
Unused Code introduced by
$user is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
37
38
        return view('back-project::users.account')->with('user', Auth::user());
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
39
    }
40
41 View Code Duplication
    public function update(UserEdit $request, Users $users, $id)
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...
42
    {
43
        $user = $users->update($request->all(), $id);
0 ignored issues
show
Unused Code introduced by
$user is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
45
        //$users->findBy('id', $id)->roles()->sync($request->input('roles'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
47
        Alert::add('success', trans('back-project::crud.model_updated', ['model' => trans('back-project::users.user')]))->flash();
48
49
        return redirect(route('bp.users.index'));
50
    }
51
52
    public function create(Roles $roles)
53
    {
54
        return view('back-project::users.create')->with('roles', $roles->all());
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
55
    }
56
57 View Code Duplication
    public function store(UserAdd $request, Users $users)
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...
58
    {
59
        $user = $users->create($request->all());
60
61
        event(new Registered($user->id));
62
63
        //$user->assignRole('user');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
65
        Alert::add('success', trans('back-project::crud.model_created', ['model' => trans('back-project::users.user')]))->flash();
66
67
        return redirect(route('bp.users.index'));
68
    }
69
70
    public function accountStore(AccountStore $request, Users $users)
71
    {
72
        $id = Auth::user()->id;
73
74
75
76
        $data = array_merge($request->all(), [
77
            'is_social' => 0,
78
            'confirmed' => 1
79
        ]);
80
81
        $users->update($data, $id);
82
83
        if ($request->method() == 'POST') {
84
            Alert::add('success', trans('back-project::crud.model_updated', ['model' => trans('back-project::users.user')]))->flash();
85
        } else {
86
            Alert::add('success', trans('back-project::crud.model_created', ['model' => trans('back-project::users.user')]))->flash();
87
        }
88
89
90
        return redirect(route('bp.admin.dashboard'));
91
    }
92
93
    public function delete(Users $users, $id)
94
    {
95
        $users->delete($id);
96
97
        Alert::add('success', trans('back-project::crud.model_deleted', ['model' => trans('back-project::users.user')]))->flash();
98
99
        return back();
100
    }
101
}