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.

TaskController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 2
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2017 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 Illuminate\Http\Request;
30
use Pterodactyl\Models\Server;
31
use Pterodactyl\Exceptions\DisplayException;
32
use Pterodactyl\Http\Controllers\Controller;
33
use Pterodactyl\Repositories\TaskRepository;
34
use Pterodactyl\Exceptions\DisplayValidationException;
35
36
class TaskController extends Controller
37
{
38
    /**
39
     * Display task index page.
40
     *
41
     * @param  \Illuminate\Http\Request  $request
42
     * @param  string                    $uuid
43
     * @return \Illuminate\View\View
44
     */
45 View Code Duplication
    public function index(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...
46
    {
47
        $server = Server::byUuid($uuid)->load('tasks');
48
        $this->authorize('list-tasks', $server);
49
        $server->js();
50
51
        return view('server.tasks.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.tasks.index...sks.actions.power')))); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 51 which is incompatible with the return type documented by Pterodactyl\Http\Control...r\TaskController::index of type Illuminate\View\View.
Loading history...
52
            'server' => $server,
53
            'node' => $server->node,
54
            'tasks' => $server->tasks,
55
            'actions' => [
56
                'command' => trans('server.tasks.actions.command'),
57
                'power' => trans('server.tasks.actions.power'),
58
            ],
59
        ]);
60
    }
61
62
    /**
63
     * Display new task page.
64
     *
65
     * @param  \Illuminate\Http\Request  $request
66
     * @param  string                    $uuid
67
     * @return \Illuminate\View\View
68
     */
69 View Code Duplication
    public function create(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...
70
    {
71
        $server = Server::byUuid($uuid);
72
        $this->authorize('create-task', $server);
73
        $server->js();
74
75
        return view('server.tasks.new', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.tasks.new',...de' => $server->node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 75 which is incompatible with the return type documented by Pterodactyl\Http\Control...\TaskController::create of type Illuminate\View\View.
Loading history...
76
            'server' => $server,
77
            'node' => $server->node,
78
        ]);
79
    }
80
81
    /**
82
     * Handle creation of new task.
83
     *
84
     * @param  \Illuminate\Http\Request  $request
85
     * @param  string                    $uuid
86
     * @return \Illuminate\Http\RedirectResponse
87
     */
88
    public function store(Request $request, $uuid)
89
    {
90
        $server = Server::byUuid($uuid);
91
        $this->authorize('create-task', $server);
92
93
        $repo = new TaskRepository;
94
        try {
95
            $repo->create($server->id, $request->user()->id, $request->except([
96
                '_token',
97
            ]));
98
99
            return redirect()->route('server.tasks', $uuid);
0 ignored issues
show
Documentation introduced by
$uuid is of type string, 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...
100
        } catch (DisplayValidationException $ex) {
101
            return redirect()->route('server.tasks.new', $uuid)->withErrors(json_decode($ex->getMessage()))->withInput();
0 ignored issues
show
Documentation introduced by
$uuid is of type string, 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...
102
        } catch (DisplayException $ex) {
103
            Alert::danger($ex->getMessage())->flash();
104
        } catch (\Exception $ex) {
105
            Log::error($ex);
106
            Alert::danger('An unknown error occured while attempting to create this task.')->flash();
107
        }
108
109
        return redirect()->route('server.tasks.new', $uuid);
0 ignored issues
show
Documentation introduced by
$uuid is of type string, 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...
110
    }
111
112
    /**
113
     * Handle deletion of a task.
114
     *
115
     * @param  \Illuminate\Http\Request  $request
116
     * @param  string                    $uuid
117
     * @param  int                       $id
118
     * @return \Illuminate\Http\JsonResponse
119
     */
120 View Code Duplication
    public function delete(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...
121
    {
122
        $server = Server::byUuid($uuid)->load('tasks');
123
        $this->authorize('delete-task', $server);
124
125
        $task = $server->tasks->where('id', $id)->first();
126
        if (! $task) {
127
            return response()->json([
128
                'error' => 'No task by that ID was found associated with this server.',
129
            ], 404);
130
        }
131
132
        $repo = new TaskRepository;
133
        try {
134
            $repo->delete($id);
135
136
            return response()->json([], 204);
137
        } catch (\Exception $ex) {
138
            Log::error($ex);
139
140
            return response()->json([
141
                'error' => 'A server error occured while attempting to delete this task.',
142
            ], 503);
143
        }
144
    }
145
146
    /**
147
     * Toggle the status of a task.
148
     *
149
     * @param  \Illuminate\Http\Request  $request
150
     * @param  string                    $uuid
151
     * @param  int                       $id
152
     * @return \Illuminate\Http\JsonResponse
153
     */
154 View Code Duplication
    public function toggle(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...
155
    {
156
        $server = Server::byUuid($uuid)->load('tasks');
157
        $this->authorize('toggle-task', $server);
158
159
        $task = $server->tasks->where('id', $id)->first();
160
        if (! $task) {
161
            return response()->json([
162
                'error' => 'No task by that ID was found associated with this server.',
163
            ], 404);
164
        }
165
166
        $repo = new TaskRepository;
167
        try {
168
            $resp = $repo->toggle($id);
169
170
            return response()->json([
171
                'status' => $resp,
172
            ]);
173
        } catch (\Exception $ex) {
174
            Log::error($ex);
175
176
            return response()->json([
177
                'error' => 'A server error occured while attempting to toggle this task.',
178
            ], 503);
179
        }
180
    }
181
}
182