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 (#259)
by Dane
08:47
created

TaskController   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 124
Duplicated Lines 87.1 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 11
dl 108
loc 124
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __constructor() 0 4 1
A getIndex() 21 21 1
A getNew() 15 15 1
B postNew() 22 22 4
B deleteTask() 24 26 4
B toggleTask() 26 28 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2016 Dane Everitt <[email protected]>.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in all
14
 * copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
25
namespace Pterodactyl\Http\Controllers\Server;
26
27
use Log;
28
use Alert;
29
use Javascript;
30
use Pterodactyl\Models;
31
use Illuminate\Http\Request;
32
use Pterodactyl\Repositories;
33
use Pterodactyl\Exceptions\DisplayException;
34
use Pterodactyl\Http\Controllers\Controller;
35
use Pterodactyl\Exceptions\DisplayValidationException;
36
37
class TaskController extends Controller
38
{
39
    public function __constructor()
40
    {
41
        //
42
    }
43
44 View Code Duplication
    public function getIndex(Request $request, $uuid)
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...
45
    {
46
        $server = Models\Server::getByUUID($uuid);
47
        $this->authorize('list-tasks', $server);
48
        $node = Models\Node::find($server->node);
0 ignored issues
show
Bug introduced by
The property node does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
49
50
        Javascript::put([
51
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
52
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
53
        ]);
54
55
        return view('server.tasks.index', [
56
            'server' => $server,
57
            'node' => $node,
58
            'tasks' => Models\Task::where('server', $server->id)->get(),
0 ignored issues
show
Bug introduced by
The property id does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
59
            'actions' => [
60
                'command' => trans('server.tasks.actions.command'),
61
                'power' => trans('server.tasks.actions.power'),
62
            ],
63
        ]);
64
    }
65
66 View Code Duplication
    public function getNew(Request $request, $uuid)
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...
67
    {
68
        $server = Models\Server::getByUUID($uuid);
69
        $this->authorize('create-task', $server);
70
        $node = Models\Node::find($server->node);
0 ignored issues
show
Bug introduced by
The property node does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
71
72
        Javascript::put([
73
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
74
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
75
        ]);
76
        return view('server.tasks.new', [
77
            'server' => $server,
78
            'node' => $node,
79
        ]);
80
    }
81
82 View Code Duplication
    public function postNew(Request $request, $uuid)
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...
83
    {
84
        $server = Models\Server::getByUUID($uuid);
85
        $this->authorize('create-task', $server);
86
87
        try {
88
            $repo = new Repositories\TaskRepository;
89
            $repo->create($server->id, $request->except([
0 ignored issues
show
Bug introduced by
The property id does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
90
                '_token',
91
            ]));
92
            return redirect()->route('server.tasks', $uuid);
93
        } catch (DisplayValidationException $ex) {
94
            return redirect()->route('server.tasks.new', $uuid)->withErrors(json_decode($ex->getMessage()))->withInput();
95
        } catch (DisplayException $ex) {
96
            Alert::danger($ex->getMessage())->flash();
97
        } catch (\Exception $ex) {
98
            Log::error($ex);
99
            Alert::danger('An unknown error occured while attempting to create this task.')->flash();
100
        }
101
102
        return redirect()->route('server.tasks.new', $uuid);
103
    }
104
105 View Code Duplication
    public function deleteTask(Request $request, $uuid, $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...
106
    {
107
        $server = Models\Server::getByUUID($uuid);
108
        $this->authorize('delete-task', $server);
109
110
        $task = Models\Task::findOrFail($id);
111
112
        if (! $task || $server->id !== $task->server) {
0 ignored issues
show
Bug introduced by
The property id does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
113
            return response()->json([
114
                'error' => 'No task by that ID was found associated with this server.',
115
            ], 404);
116
        }
117
118
        try {
119
            $repo = new Repositories\TaskRepository;
120
            $repo->delete($id);
121
122
            return response()->json([], 204);
123
        } catch (\Exception $ex) {
124
            Log::error($ex);
125
126
            return response()->json([
127
                'error' => 'A server error occured while attempting to delete this task.',
128
            ], 503);
129
        }
130
    }
131
132 View Code Duplication
    public function toggleTask(Request $request, $uuid, $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...
133
    {
134
        $server = Models\Server::getByUUID($uuid);
135
        $this->authorize('toggle-task', $server);
136
137
        $task = Models\Task::findOrFail($id);
138
139
        if (! $task || $server->id !== $task->server) {
0 ignored issues
show
Bug introduced by
The property id does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
140
            return response()->json([
141
                'error' => 'No task by that ID was found associated with this server.',
142
            ], 404);
143
        }
144
145
        try {
146
            $repo = new Repositories\TaskRepository;
147
            $resp = $repo->toggle($id);
148
149
            return response()->json([
150
                'status' => $resp,
151
            ]);
152
        } catch (\Exception $ex) {
153
            Log::error($ex);
154
155
            return response()->json([
156
                'error' => 'A server error occured while attempting to toggle this task.',
157
            ], 503);
158
        }
159
    }
160
}
161