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
08:45 queued 05:44
created

ServerController::getStartup()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 46
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 8.9411
c 0
b 0
f 0
cc 3
eloc 34
nc 3
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 DB;
28
use Log;
29
use Uuid;
30
use Alert;
31
use Pterodactyl\Models;
32
use Illuminate\Http\Request;
33
use Pterodactyl\Exceptions\DisplayException;
34
use Pterodactyl\Http\Controllers\Controller;
35
use Pterodactyl\Repositories\ServerRepository;
36
use Pterodactyl\Repositories\Daemon\FileRepository;
37
use Pterodactyl\Exceptions\DisplayValidationException;
38
39
class ServerController extends Controller
40
{
41
    /**
42
     * Controller Constructor.
43
     *
44
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
45
     */
46
    public function __construct()
47
    {
48
        //
49
    }
50
51
    /**
52
     * Renders server index page for specified server.
53
     *
54
     * @param  \Illuminate\Http\Request $request
55
     * @return \Illuminate\Contracts\View\View
56
     */
57
    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...
58
    {
59
        $server = Models\Server::byUuid($uuid);
60
61
        $server->js([
62
            'meta' => [
63
                'saveFile' => route('server.files.save', $server->uuidShort),
0 ignored issues
show
Bug introduced by
The property uuidShort 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...
64
                'csrfToken' => csrf_token(),
65
            ],
66
        ]);
67
68
        return view('server.index', [
69
            'server' => $server,
70
            'node' => $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
    }
73
74
    /**
75
     * Renders file overview page.
76
     *
77
     * @param  Request $request
78
     * @return \Illuminate\Contracts\View\View
79
     */
80
    public function getFiles(Request $request, $uuid)
81
    {
82
        $server = Models\Server::byUuid($uuid);
83
        $this->authorize('list-files', $server);
84
85
        $server->js([
86
            'meta' => [
87
                'directoryList' => route('server.files.directory-list', $server->uuidShort),
0 ignored issues
show
Bug introduced by
The property uuidShort 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...
88
                'csrftoken' => csrf_token(),
89
            ],
90
            'permissions' => [
91
                'moveFiles' => $request->user()->can('move-files', $server),
92
                'copyFiles' => $request->user()->can('copy-files', $server),
93
                'compressFiles' => $request->user()->can('compress-files', $server),
94
                'decompressFiles' => $request->user()->can('decompress-files', $server),
95
                'createFiles' => $request->user()->can('create-files', $server),
96
                'downloadFiles' => $request->user()->can('download-files', $server),
97
                'deleteFiles' => $request->user()->can('delete-files', $server),
98
            ],
99
        ]);
100
101
        return view('server.files.index', [
102
            'server' => $server,
103
            'node' => $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...
104
        ]);
105
    }
106
107
    /**
108
     * Renders add file page.
109
     *
110
     * @param  Request $request
111
     * @return \Illuminate\Contracts\View\View
112
     */
113 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...
114
    {
115
        $server = Models\Server::byUuid($uuid);
116
        $this->authorize('add-files', $server);
117
118
        $server->js();
119
120
        return view('server.files.add', [
121
            'server' => $server,
122
            'node' => $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...
123
            'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/',
124
        ]);
125
    }
126
127
    /**
128
     * Renders edit file page for a given file.
129
     *
130
     * @param  Request $request
131
     * @param  string  $uuid
132
     * @param  string  $file
133
     * @return \Illuminate\Contracts\View\View
134
     */
135
    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...
136
    {
137
        $server = Models\Server::byUuid($uuid);
138
        $this->authorize('edit-files', $server);
139
140
        $fileInfo = (object) pathinfo($file);
141
        $controller = new FileRepository($uuid);
142
143
        try {
144
            $fileContent = $controller->returnFileContents($file);
145
        } catch (DisplayException $ex) {
146
            Alert::danger($ex->getMessage())->flash();
147
148
            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...
149
        } catch (\Exception $ex) {
150
            Log::error($ex);
151
            Alert::danger('An error occured while attempting to load the requested file for editing, please try again.')->flash();
152
153
            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...
154
        }
155
156
        $server->js([
157
            'stat' => $fileContent['stat'],
158
        ]);
159
160
        return view('server.files.edit', [
161
            'server' => $server,
162
            'node' => $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...
163
            'file' => $file,
164
            'stat' => $fileContent['stat'],
165
            'contents' => $fileContent['file']->content,
166
            'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
167
        ]);
168
    }
169
170
    /**
171
     * Handles downloading a file for the user.
172
     *
173
     * @param  Request $request
174
     * @param  string  $uuid
175
     * @param  string  $file
176
     * @return \Illuminate\Contracts\View\View
177
     */
178
    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...
179
    {
180
        $server = Models\Server::byUuid($uuid);
181
        $this->authorize('download-files', $server);
182
183
        $download = new Models\Download;
184
185
        $download->token = (string) Uuid::generate(4);
0 ignored issues
show
Documentation introduced by
The property token does not exist on object<Pterodactyl\Models\Download>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
186
        $download->server = $server->uuid;
0 ignored issues
show
Documentation introduced by
The property server does not exist on object<Pterodactyl\Models\Download>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The property uuid 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...
187
        $download->path = $file;
0 ignored issues
show
Documentation introduced by
The property path does not exist on object<Pterodactyl\Models\Download>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
188
189
        $download->save();
190
191
        return redirect($server->node->scheme . '://' . $server->node->fqdn . ':' . $server->node->daemonListen . '/server/file/download/' . $download->token);
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...
Documentation introduced by
The property token does not exist on object<Pterodactyl\Models\Download>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
192
    }
193
194
    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...
195
    {
196
        $server = Models\Server::byUuid($uuid);
197
        $this->authorize('view-allocation', $server);
198
        $server->js();
199
200
        return view('server.settings.allocation', [
201
            'server' => $server->load(['allocations' => function ($query) {
202
                $query->orderBy('ip', 'asc');
203
                $query->orderBy('port', 'asc');
204
            }]),
205
            'node' => $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...
206
        ]);
207
    }
208
209
    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...
210
    {
211
        $server = Models\Server::byUuid($uuid);
212
        $server->load(['allocations' => function ($query) use ($server) {
213
            $query->where('id', $server->allocation_id);
214
        }]);
215
        $this->authorize('view-startup', $server);
216
217
        $variables = Models\ServiceVariable::select(
218
                'service_variables.*',
219
                DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue')
220
            )->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
221
            ->where('service_variables.option_id', $server->option_id)
0 ignored issues
show
Bug introduced by
The property option_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...
222
            ->where('server_variables.server_id', $server->id)
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...
223
            ->get();
224
225
        $service = Models\Service::select(
226
                DB::raw('IFNULL(service_options.executable, services.executable) as executable')
227
            )->leftJoin('service_options', 'service_options.service_id', '=', 'services.id')
228
            ->where('service_options.id', $server->option_id)
229
            ->where('services.id', $server->service_id)
0 ignored issues
show
Bug introduced by
The property service_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...
230
            ->first();
231
232
        $allocation = $server->allocations->pop();
0 ignored issues
show
Bug introduced by
The property allocations 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...
233
        $ServerVariable = [
234
            '{{SERVER_MEMORY}}' => $server->memory,
0 ignored issues
show
Bug introduced by
The property memory 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...
235
            '{{SERVER_IP}}' => $allocation->ip,
236
            '{{SERVER_PORT}}' => $allocation->port,
237
        ];
238
239
        $processed = str_replace(array_keys($ServerVariable), array_values($ServerVariable), $server->startup);
0 ignored issues
show
Bug introduced by
The property startup 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...
240
        foreach ($variables as &$variable) {
241
            $replace = ($variable->user_viewable === 1) ? $variable->a_serverValue : '[hidden]';
242
            $processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
243
        }
244
245
        $server->js();
246
247
        return view('server.settings.startup', [
248
            'server' => $server,
249
            'node' => $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...
250
            'variables' => $variables->where('user_viewable', 1),
251
            'service' => $service,
252
            'processedStartup' => $processed,
253
        ]);
254
    }
255
256
    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...
257
    {
258
        $server = Models\Server::byUuid($uuid);
259
        $this->authorize('view-databases', $server);
260
        $server->js();
261
262
        return view('server.settings.databases', [
263
            'server' => $server,
264
            'node' => $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...
265
            'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')
266
                ->where('server_id', $server->id)
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...
267
                ->join('database_servers', 'database_servers.id', '=', 'databases.db_server')
268
                ->get(),
269
        ]);
270
    }
271
272 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...
273
    {
274
        $server = Models\Server::byUuid($uuid);
275
        $this->authorize('view-sftp', $server);
276
        $server->js();
277
278
        return view('server.settings.sftp', [
279
            'server' => $server,
280
            'node' => $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...
281
        ]);
282
    }
283
284 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...
285
    {
286
        $server = Models\Server::byUuid($uuid);
287
        $this->authorize('reset-sftp', $server);
288
289
        try {
290
            $repo = new ServerRepository;
291
            $repo->updateSFTPPassword($server->id, $request->input('sftp_pass'));
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...
292
            Alert::success('Successfully updated this servers SFTP password.')->flash();
293
        } catch (DisplayValidationException $ex) {
294
            return redirect()->route('server.settings.sftp', $uuid)->withErrors(json_decode($ex->getMessage()));
295
        } catch (DisplayException $ex) {
296
            Alert::danger($ex->getMessage())->flash();
297
        } catch (\Exception $ex) {
298
            Log::error($ex);
299
            Alert::danger('An unknown error occured while attempting to update this server\'s SFTP settings.')->flash();
300
        }
301
302
        return redirect()->route('server.settings.sftp', $uuid);
303
    }
304
305
    public function postSettingsStartup(Request $request, $uuid)
306
    {
307
        $server = Models\Server::byUuid($uuid);
308
        $this->authorize('edit-startup', $server);
309
310
        try {
311
            $repo = new ServerRepository;
312
            $repo->updateStartup($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...
313
                '_token',
314
            ]));
315
            Alert::success('Server startup variables were successfully updated.')->flash();
316
        } catch (DisplayException $ex) {
317
            Alert::danger($ex->getMessage())->flash();
318
        } catch (\Exception $ex) {
319
            Log::error($ex);
320
            Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
321
        }
322
323
        return redirect()->route('server.settings', [
324
            'uuid' => $uuid,
325
            'tab' => 'tab_startup',
326
        ]);
327
    }
328
}
329