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

LocationsController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 8
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIndex() 0 6 1
A deleteLocation() 0 14 2
A patchLocation() 0 16 3
A postLocation() 0 19 4
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\Admin;
26
27
use Alert;
28
use Pterodactyl\Models;
29
use Illuminate\Http\Request;
30
use Pterodactyl\Exceptions\DisplayException;
31
use Pterodactyl\Http\Controllers\Controller;
32
use Pterodactyl\Repositories\LocationRepository;
33
use Pterodactyl\Exceptions\DisplayValidationException;
34
35
class LocationsController extends Controller
36
{
37
    public function __construct()
38
    {
39
        //
40
    }
41
42
    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...
43
    {
44
        return view('admin.locations.index', [
45
            'locations' => Models\Location::withCount('nodes', 'servers')->paginate(20),
46
        ]);
47
    }
48
49
    public function deleteLocation(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...
50
    {
51
        $location = Models\Location::withCount('nodes')->findOrFail($id);
52
53
        if ($location->nodes_count > 0) {
54
            return response()->json([
55
                'error' => 'You cannot remove a location that is currently assigned to a node.',
56
            ], 422);
57
        }
58
59
        $location->delete();
60
61
        return response('', 204);
62
    }
63
64
    public function patchLocation(Request $request, $id)
65
    {
66
        try {
67
            $location = new LocationRepository;
68
            $location->edit($id, $request->only(['long', 'short']));
69
70
            return response('', 204);
71
        } catch (DisplayValidationException $ex) {
72
            return response()->json([
73
                'error' => 'There was a validation error while processing this request. Location descriptions must be between 1 and 255 characters, and the location code must be between 1 and 20 characters with no spaces or special characters.',
74
            ], 422);
75
        } catch (\Exception $ex) {
76
            // This gets caught and processed into JSON anyways.
77
            throw $ex;
78
        }
79
    }
80
81
    public function postLocation(Request $request)
82
    {
83
        try {
84
            $location = new LocationRepository;
85
            $location->create($request->only(['long', 'short']));
86
            Alert::success('New location successfully added.')->flash();
87
88
            return redirect()->route('admin.locations');
89
        } catch (DisplayValidationException $ex) {
90
            return redirect()->route('admin.locations')->withErrors(json_decode($ex->getMessage()))->withInput();
91
        } catch (DisplayException $ex) {
92
            Alert::danger($ex->getMessage())->flash();
93
        } catch (\Exception $ex) {
94
            Log::error($ex);
95
            Alert::danger('An unhandled exception occured while attempting to add this location. Please try again.')->flash();
96
        }
97
98
        return redirect()->route('admin.locations')->withInput();
99
    }
100
}
101