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.
Completed
Pull Request — develop (#286)
by Dane
04:53 queued 02:03
created

UserController::getIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>
5
 * Some Modifications (c) 2015 Dylan Seidt <[email protected]>.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
namespace Pterodactyl\Http\Controllers\Admin;
27
28
use Log;
29
use Alert;
30
use Illuminate\Http\Request;
31
use Pterodactyl\Models\User;
32
use Pterodactyl\Exceptions\DisplayException;
33
use Pterodactyl\Http\Controllers\Controller;
34
use Pterodactyl\Repositories\UserRepository;
35
use Pterodactyl\Exceptions\DisplayValidationException;
36
37
class UserController extends Controller
38
{
39
    /**
40
     * Controller Constructor.
41
     */
42
    public function __construct()
43
    {
44
        //
45
    }
46
47
    // @TODO: implement nicolaslopezj/searchable to clean up this disaster.
48
    public function getIndex(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        return view('admin.users.index', [
51
            'users' => User::paginate(25),
52
        ]);
53
    }
54
55
    public function getNew(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        return view('admin.users.new');
58
    }
59
60
    public function getView(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62
        return view('admin.users.view', [
63
            'user' => User::with('servers.node')->findOrFail($id),
0 ignored issues
show
Bug introduced by
The method findOrFail does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

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...
64
        ]);
65
    }
66
67 View Code Duplication
    public function deleteUser(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
68
    {
69
        try {
70
            $repo = new UserRepository;
71
            $repo->delete($id);
72
            Alert::success('Successfully deleted user from system.')->flash();
73
74
            return redirect()->route('admin.users');
75
        } catch (DisplayException $ex) {
76
            Alert::danger($ex->getMessage())->flash();
77
        } catch (\Exception $ex) {
78
            Log::error($ex);
79
            Alert::danger('An exception was encountered while attempting to delete this user.')->flash();
80
        }
81
82
        return redirect()->route('admin.users.view', $id);
83
    }
84
85
    public function postNew(Request $request)
86
    {
87
        try {
88
            $user = new UserRepository;
89
            $userid = $user->create($request->only([
90
                'email', 'password', 'name_first',
91
                'name_last', 'username', 'root_admin',
92
            ]));
93
            Alert::success('Account has been successfully created.')->flash();
94
95
            return redirect()->route('admin.users.view', $userid);
0 ignored issues
show
Documentation introduced by
$userid is of type object<Pterodactyl\Models\User>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
96
        } catch (DisplayValidationException $ex) {
97
            return redirect()->route('admin.users.new')->withErrors(json_decode($ex->getMessage()))->withInput();
98
        } catch (\Exception $ex) {
99
            Log::error($ex);
100
            Alert::danger('An error occured while attempting to add a new user.')->flash();
101
102
            return redirect()->route('admin.users.new');
103
        }
104
    }
105
106
    public function updateUser(Request $request, $user)
107
    {
108
        try {
109
            $repo = new UserRepository;
110
            $repo->update($user, $request->only([
111
                'email', 'password', 'name_first',
112
                'name_last', 'username', 'root_admin',
113
            ]));
114
            Alert::success('User account was successfully updated.')->flash();
115
        } catch (DisplayValidationException $ex) {
116
            return redirect()->route('admin.users.view', $user)->withErrors(json_decode($ex->getMessage()));
117
        } catch (\Exception $e) {
118
            Log::error($e);
119
            Alert::danger('An error occured while attempting to update this user.')->flash();
120
        }
121
122
        return redirect()->route('admin.users.view', $user);
123
    }
124
125
    public function getJson(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
126
    {
127
        return User::select('email')->get()->pluck('email');
128
    }
129
}
130