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
Push — develop ( eeeb4b...f58858 )
by Dane
02:55
created

ServerController   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 333
Duplicated Lines 23.42 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 24
lcom 1
cbo 10
dl 78
loc 333
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndex() 0 20 1
A getConsole() 0 17 1
B getFiles() 0 26 1
A getAddFile() 13 13 2
B getEditFile() 0 34 4
A getDownloadFile() 0 15 1
A getAllocation() 0 14 1
B getStartup() 0 29 3
A getDatabases() 14 14 1
A getSFTP() 11 11 1
A postSettingsSFTP() 20 20 4
A postSettingsStartup() 20 20 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 - 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 Uuid;
29
use Alert;
30
use Pterodactyl\Models;
31
use Illuminate\Http\Request;
32
use Pterodactyl\Exceptions\DisplayException;
33
use Pterodactyl\Http\Controllers\Controller;
34
use Pterodactyl\Repositories\ServerRepository;
35
use Pterodactyl\Repositories\Daemon\FileRepository;
36
use Pterodactyl\Exceptions\DisplayValidationException;
37
38
class ServerController extends Controller
39
{
40
    /**
41
     * Renders server index page for specified server.
42
     *
43
     * @param  \Illuminate\Http\Request  $request
44
     * @param  string                    $uuid
45
     * @return \Illuminate\View\View
46
     */
47
    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...
48
    {
49
        $server = Models\Server::byUuid($uuid);
50
51
        $server->js([
52
            'meta' => [
53
                'saveFile' => route('server.files.save', $server->uuidShort),
54
                'csrfToken' => csrf_token(),
55
            ],
56
            'config' => [
57
                'console_count' => config('pterodactyl.console.count'),
58
                'console_freq' => config('pterodactyl.console.freq'),
59
            ],
60
        ]);
61
62
        return view('server.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.index', arr...de' => $server->node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 62 which is incompatible with the return type documented by Pterodactyl\Http\Control...verController::getIndex of type Illuminate\View\View.
Loading history...
63
            'server' => $server,
64
            'node' => $server->node,
65
        ]);
66
    }
67
68
    /**
69
     * Renders server console as an individual item.
70
     *
71
     * @param  \Illuminate\Http\Request  $request
72
     * @param  string                    $uuid
73
     * @return \Illuminate\View\View
74
     */
75
    public function getConsole(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...
76
    {
77
        \Debugbar::disable();
78
        $server = Models\Server::byUuid($uuid);
79
80
        $server->js([
81
            'config' => [
82
                'console_count' => config('pterodactyl.console.count'),
83
                'console_freq' => config('pterodactyl.console.freq'),
84
            ],
85
        ]);
86
87
        return view('server.console', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.console', a...de' => $server->node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 87 which is incompatible with the return type documented by Pterodactyl\Http\Control...rController::getConsole of type Illuminate\View\View.
Loading history...
88
            'server' => $server,
89
            'node' => $server->node,
90
        ]);
91
    }
92
93
    /**
94
     * Renders file overview page.
95
     *
96
     * @param  \Illuminate\Http\Request  $request
97
     * @param  string                    $uuid
98
     * @return \Illuminate\View\View
99
     */
100
    public function getFiles(Request $request, $uuid)
101
    {
102
        $server = Models\Server::byUuid($uuid);
103
        $this->authorize('list-files', $server);
104
105
        $server->js([
106
            'meta' => [
107
                'directoryList' => route('server.files.directory-list', $server->uuidShort),
108
                'csrftoken' => csrf_token(),
109
            ],
110
            'permissions' => [
111
                'moveFiles' => $request->user()->can('move-files', $server),
112
                'copyFiles' => $request->user()->can('copy-files', $server),
113
                'compressFiles' => $request->user()->can('compress-files', $server),
114
                'decompressFiles' => $request->user()->can('decompress-files', $server),
115
                'createFiles' => $request->user()->can('create-files', $server),
116
                'downloadFiles' => $request->user()->can('download-files', $server),
117
                'deleteFiles' => $request->user()->can('delete-files', $server),
118
            ],
119
        ]);
120
121
        return view('server.files.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.files.index...de' => $server->node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 121 which is incompatible with the return type documented by Pterodactyl\Http\Control...verController::getFiles of type Illuminate\View\View.
Loading history...
122
            'server' => $server,
123
            'node' => $server->node,
124
        ]);
125
    }
126
127
    /**
128
     * Renders add file page.
129
     *
130
     * @param  \Illuminate\Http\Request  $request
131
     * @param  string                    $uuid
132
     * @return \Illuminate\View\View
133
     */
134 View Code Duplication
    public function getAddFile(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...
135
    {
136
        $server = Models\Server::byUuid($uuid);
137
        $this->authorize('create-files', $server);
138
139
        $server->js();
140
141
        return view('server.files.add', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.files.add',...t('dir'), '/') . '/')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 141 which is incompatible with the return type documented by Pterodactyl\Http\Control...rController::getAddFile of type Illuminate\View\View.
Loading history...
142
            'server' => $server,
143
            'node' => $server->node,
144
            'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/',
145
        ]);
146
    }
147
148
    /**
149
     * Renders edit file page for a given file.
150
     *
151
     * @param  \Illuminate\Http\Request  $request
152
     * @param  string                    $uuid
153
     * @param  string                    $file
154
     * @return \Illuminate\View\View
155
     */
156
    public function getEditFile(Request $request, $uuid, $file)
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...
157
    {
158
        $server = Models\Server::byUuid($uuid);
159
        $this->authorize('edit-files', $server);
160
161
        $fileInfo = (object) pathinfo($file);
162
        $controller = new FileRepository($uuid);
163
164
        try {
165
            $fileContent = $controller->returnFileContents($file);
166
        } catch (DisplayException $ex) {
167
            Alert::danger($ex->getMessage())->flash();
168
169
            return redirect()->route('server.files.index', $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...
Bug Best Practice introduced by
The return type of return redirect()->route...r.files.index', $uuid); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by Pterodactyl\Http\Control...Controller::getEditFile of type Illuminate\View\View.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
170
        } catch (\Exception $ex) {
171
            Log::error($ex);
172
            Alert::danger('An error occured while attempting to load the requested file for editing, please try again.')->flash();
173
174
            return redirect()->route('server.files.index', $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...
Bug Best Practice introduced by
The return type of return redirect()->route...r.files.index', $uuid); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by Pterodactyl\Http\Control...Controller::getEditFile of type Illuminate\View\View.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
175
        }
176
177
        $server->js([
178
            'stat' => $fileContent['stat'],
179
        ]);
180
181
        return view('server.files.edit', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.files.edit'...>dirname, '/') . '/')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 181 which is incompatible with the return type documented by Pterodactyl\Http\Control...Controller::getEditFile of type Illuminate\View\View.
Loading history...
182
            'server' => $server,
183
            'node' => $server->node,
184
            'file' => $file,
185
            'stat' => $fileContent['stat'],
186
            'contents' => $fileContent['file']->content,
187
            'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
188
        ]);
189
    }
190
191
    /**
192
     * Handles downloading a file for the user.
193
     *
194
     * @param  \Illuminate\Http\Request  $request
195
     * @param  string                    $uuid
196
     * @param  string                    $file
197
     * @return \Illuminate\View\View
198
     */
199
    public function getDownloadFile(Request $request, $uuid, $file)
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...
200
    {
201
        $server = Models\Server::byUuid($uuid);
202
        $this->authorize('download-files', $server);
203
204
        $download = new Models\Download;
205
206
        $download->token = (string) Uuid::generate(4);
207
        $download->server = $server->uuid;
208
        $download->path = $file;
209
210
        $download->save();
211
212
        return redirect($server->node->scheme . '://' . $server->node->fqdn . ':' . $server->node->daemonListen . '/server/file/download/' . $download->token);
213
    }
214
215
    /**
216
     * Returns the allocation overview for a server.
217
     *
218
     * @param  \Illuminate\Http\Request  $request
219
     * @param  string                    $uuid
220
     * @return \Illuminate\View\View
221
     */
222
    public function getAllocation(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...
223
    {
224
        $server = Models\Server::byUuid($uuid);
225
        $this->authorize('view-allocation', $server);
226
        $server->js();
227
228
        return view('server.settings.allocation', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.settings.al...de' => $server->node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 228 which is incompatible with the return type documented by Pterodactyl\Http\Control...ntroller::getAllocation of type Illuminate\View\View.
Loading history...
229
            'server' => $server->load(['allocations' => function ($query) {
230
                $query->orderBy('ip', 'asc');
231
                $query->orderBy('port', 'asc');
232
            }]),
233
            'node' => $server->node,
234
        ]);
235
    }
236
237
    /**
238
     * Returns the startup overview for a server.
239
     *
240
     * @param  \Illuminate\Http\Request  $request
241
     * @param  string                    $uuid
242
     * @return \Illuminate\View\View
243
     */
244
    public function getStartup(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...
245
    {
246
        $server = Models\Server::byUuid($uuid);
247
        $server->load(['node', 'allocation', 'variables.variable']);
248
249
        $this->authorize('view-startup', $server);
250
251
        $replacements = [
252
            '{{SERVER_MEMORY}}' => $server->memory,
253
            '{{SERVER_IP}}' => $server->allocation->ip,
254
            '{{SERVER_PORT}}' => $server->allocation->port,
255
        ];
256
257
        $processed = str_replace(array_keys($replacements), array_values($replacements), $server->startup);
258
        foreach ($server->variables as $v) {
259
            $replace = ($v->user_can_view) ? $v->variable_value : '[hidden]';
260
            $processed = str_replace('{{' . $v->variable->env_variable . '}}', $replace, $processed);
261
        }
262
263
        $server->js();
264
265
        return view('server.settings.startup', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.settings.st...artup' => $processed)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 265 which is incompatible with the return type documented by Pterodactyl\Http\Control...rController::getStartup of type Illuminate\View\View.
Loading history...
266
            'server' => $server,
267
            'node' => $server->node,
268
            'variables' => $server->variables->where('user_can_view', true),
269
            'service' => $server->service,
270
            'processedStartup' => $processed,
271
        ]);
272
    }
273
274
    /**
275
     * Returns the database overview for a server.
276
     *
277
     * @param  \Illuminate\Http\Request  $request
278
     * @param  string                    $uuid
279
     * @return \Illuminate\View\View
280
     */
281 View Code Duplication
    public function getDatabases(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...
282
    {
283
        $server = Models\Server::byUuid($uuid);
284
        $this->authorize('view-databases', $server);
285
286
        $server->load('node', 'databases.host');
287
        $server->js();
288
289
        return view('server.settings.databases', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.settings.da...> $server->databases)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 289 which is incompatible with the return type documented by Pterodactyl\Http\Control...ontroller::getDatabases of type Illuminate\View\View.
Loading history...
290
            'server' => $server,
291
            'node' => $server->node,
292
            'databases' => $server->databases,
293
        ]);
294
    }
295
296
    /**
297
     * Returns the SFTP overview for a server.
298
     *
299
     * @param  \Illuminate\Http\Request  $request
300
     * @param  string                    $uuid
301
     * @return \Illuminate\View\View
302
     */
303 View Code Duplication
    public function getSFTP(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...
304
    {
305
        $server = Models\Server::byUuid($uuid);
306
        $this->authorize('view-sftp', $server);
307
        $server->js();
308
309
        return view('server.settings.sftp', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('server.settings.sf...de' => $server->node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 309 which is incompatible with the return type documented by Pterodactyl\Http\Control...rverController::getSFTP of type Illuminate\View\View.
Loading history...
310
            'server' => $server,
311
            'node' => $server->node,
312
        ]);
313
    }
314
315
    /**
316
     * Handles changing the SFTP password for a server.
317
     *
318
     * @param  \Illuminate\Http\Request  $request
319
     * @param  string                    $uuid
320
     * @return \Illuminate\Http\RedirectResponse
321
     */
322 View Code Duplication
    public function postSettingsSFTP(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...
323
    {
324
        $server = Models\Server::byUuid($uuid);
325
        $this->authorize('reset-sftp', $server);
326
327
        try {
328
            $repo = new ServerRepository;
329
            $repo->updateSFTPPassword($server->id, $request->input('sftp_pass'));
0 ignored issues
show
Bug introduced by
It seems like $request->input('sftp_pass') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array; however, Pterodactyl\Repositories...y::updateSFTPPassword() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
330
            Alert::success('Successfully updated this servers SFTP password.')->flash();
331
        } catch (DisplayValidationException $ex) {
332
            return redirect()->route('server.settings.sftp', $uuid)->withErrors(json_decode($ex->getMessage()));
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...
333
        } catch (DisplayException $ex) {
334
            Alert::danger($ex->getMessage())->flash();
335
        } catch (\Exception $ex) {
336
            Log::error($ex);
337
            Alert::danger('An unknown error occured while attempting to update this server\'s SFTP settings.')->flash();
338
        }
339
340
        return redirect()->route('server.settings.sftp', $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...
341
    }
342
343
    /**
344
     * Handles changing the startup settings for a server.
345
     *
346
     * @param  \Illuminate\Http\Request  $request
347
     * @param  string                    $uuid
348
     * @return \Illuminate\Http\RedirectResponse
349
     */
350 View Code Duplication
    public function postSettingsStartup(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...
351
    {
352
        $server = Models\Server::byUuid($uuid);
353
        $this->authorize('edit-startup', $server);
354
355
        try {
356
            $repo = new ServerRepository;
357
            $repo->updateStartup($server->id, $request->except('_token'));
358
            Alert::success('Server startup variables were successfully updated.')->flash();
359
        } catch (DisplayValidationException $ex) {
360
            return redirect()->route('server.settings.startup', $uuid)->withErrors(json_decode($ex->getMessage()));
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...
361
        } catch (DisplayException $ex) {
362
            Alert::danger($ex->getMessage())->flash();
363
        } catch (\Exception $ex) {
364
            Log::error($ex);
365
            Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
366
        }
367
368
        return redirect()->route('server.settings.startup', $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...
369
    }
370
}
371