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 ( c3abb3...a85ac8 )
by Dane
11:30
created

APIController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2016 Dane Everitt <[email protected]>
5
 * Some Modifications (c) 2015 Dylan Seidt <[email protected]>.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
namespace Pterodactyl\Http\Controllers\Base;
27
28
use Log;
29
use Alert;
30
use Pterodactyl\Models;
31
use Illuminate\Http\Request;
32
use Pterodactyl\Repositories\APIRepository;
33
use Pterodactyl\Exceptions\DisplayException;
34
use Pterodactyl\Http\Controllers\Controller;
35
use Pterodactyl\Exceptions\DisplayValidationException;
36
37
class APIController extends Controller
38
{
39
    public function index(Request $request)
40
    {
41
        $keys = Models\APIKey::where('user', $request->user()->id)->get();
42
        foreach ($keys as &$key) {
43
            $key->permissions = Models\APIPermission::where('key_id', $key->id)->get();
44
        }
45
46
        return view('base.api.index', [
47
            'keys' => $keys,
48
        ]);
49
    }
50
51
    public function create(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...
52
    {
53
        return view('base.api.new');
54
    }
55
56 View Code Duplication
    public function save(Request $request)
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...
57
    {
58
        try {
59
            $repo = new APIRepository($request->user());
60
            $secret = $repo->create($request->except(['_token']));
61
            Alert::success('An API Keypair has successfully been generated. The API secret for this public key is shown below and will not be shown again.<br /><br /><code>' . $secret . '</code>')->flash();
62
63
            return redirect()->route('account.api');
64
        } catch (DisplayValidationException $ex) {
65
            return redirect()->route('account.api.new')->withErrors(json_decode($ex->getMessage()))->withInput();
66
        } catch (DisplayException $ex) {
67
            Alert::danger($ex->getMessage())->flash();
68
        } catch (\Exception $ex) {
69
            Log::error($ex);
70
            Alert::danger('An unhandled exception occured while attempting to add this API key.')->flash();
71
        }
72
73
        return redirect()->route('account.api.new')->withInput();
74
    }
75
76 View Code Duplication
    public function revoke(Request $request, $key)
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...
77
    {
78
        try {
79
            $repo = new APIRepository($request->user());
80
            $repo->revoke($key);
81
82
            return response('', 204);
83
        } catch (\Exception $ex) {
84
            return response()->json([
85
                'error' => 'An error occured while attempting to remove this key.',
86
            ], 503);
87
        }
88
    }
89
}
90