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 ( 1c37a8...7eb737 )
by Dane
03:13
created

ServiceController::listServices()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
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\Daemon;
26
27
use Illuminate\Http\Request;
28
use Pterodactyl\Models\Service;
29
use Pterodactyl\Models\ServiceOption;
30
use Pterodactyl\Http\Controllers\Controller;
31
32
class ServiceController extends Controller
33
{
34
    /**
35
     * Returns a listing of all services currently on the system,
36
     * as well as the associated files and the file hashes for
37
     * caching purposes.
38
     *
39
     * @param  \Illuminate\Http\Request  $request
40
     * @return \Illuminate\Http\JsonResponse
41
     */
42
    public function listServices(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
        $response = [];
45
        foreach (Service::all() as $service) {
46
            $response[$service->folder] = [
47
                'main.json' => sha1($this->getConfiguration($service->id)->toJson()),
48
                'index.js' => sha1($service->index_file),
49
            ];
50
        }
51
52
        return response()->json($response);
53
    }
54
55
    /**
56
     * Returns the contents of the requested file for the given service.
57
     *
58
     * @param  \Illuminate\Http\Request   $request
59
     * @param  string                     $folder
60
     * @param  string                     $file
61
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\FileResponse
62
     */
63
    public function pull(Request $request, $folder, $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...
64
    {
65
        $service = Service::where('folder', $folder)->firstOrFail();
66
67
        if ($file === 'index.js') {
68
            return response($service->index_file)->header('Content-Type', 'text/plain');
0 ignored issues
show
Bug introduced by
The method header() does not exist on Symfony\Component\HttpFoundation\Response. Did you maybe mean sendHeaders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
69
        } elseif ($file === 'main.json') {
70
            return response()->json($this->getConfiguration($service->id));
71
        }
72
73
        return abort(404);
74
    }
75
76
    /**
77
     * Returns a `main.json` file based on the configuration
78
     * of each service option.
79
     *
80
     * @param  int  $id
81
     * @return \Illuminate\Support\Collection
82
     */
83
    protected function getConfiguration($id)
84
    {
85
        $options = ServiceOption::where('service_id', $id)->get();
86
87
        return $options->mapWithKeys(function ($item) use ($options) {
88
            return [
89
                $item->tag => array_filter([
90
                    'symlink' => $options->where('id', $item->config_from)->pluck('tag')->pop(),
91
                    'startup' => json_decode($item->config_startup),
92
                    'stop' => $item->config_stop,
93
                    'configs' => json_decode($item->config_files),
94
                    'log' => json_decode($item->config_logs),
95
                    'query' => 'none',
96
                ]),
97
            ];
98
        });
99
    }
100
}
101