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 ( 57a888...65f9e3 )
by Dane
16:31 queued 13:22
created

ServiceController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
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\Admin;
26
27
use Log;
28
use Alert;
29
use Pterodactyl\Models;
30
use Illuminate\Http\Request;
31
use Pterodactyl\Exceptions\DisplayException;
32
use Pterodactyl\Http\Controllers\Controller;
33
use Pterodactyl\Repositories\ServiceRepository;
34
use Pterodactyl\Exceptions\DisplayValidationException;
35
36
class ServiceController extends Controller
37
{
38
    /**
39
     * Display service overview page.
40
     *
41
     * @param  Request $request
42
     * @return \Illuminate\View\View
43
     */
44
    public function index(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...
45
    {
46
        return view('admin.services.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.services.ind...ns', 'packs')->get())); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 46 which is incompatible with the return type documented by Pterodactyl\Http\Control...erviceController::index of type Illuminate\View\View.
Loading history...
47
            'services' => Models\Service::withCount('servers', 'options', 'packs')->get(),
48
        ]);
49
    }
50
51
    /**
52
     * Display create service page.
53
     *
54
     * @param  Request $request
55
     * @return \Illuminate\View\View
56
     */
57
    public function new(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...
58
    {
59
        return view('admin.services.new');
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.services.new'); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 59 which is incompatible with the return type documented by Pterodactyl\Http\Control...\ServiceController::new of type Illuminate\View\View.
Loading history...
60
    }
61
62
    /**
63
     * Return base view for a service.
64
     *
65
     * @param  Request $request
66
     * @param  int     $id
67
     * @return \Illuminate\View\View
68
     */
69
    public function view(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...
70
    {
71
        return view('admin.services.view', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.services.vie...s')->findOrFail($id))); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 71 which is incompatible with the return type documented by Pterodactyl\Http\Control...ServiceController::view of type Illuminate\View\View.
Loading history...
72
            'service' => Models\Service::with('options', 'options.servers')->findOrFail($id),
0 ignored issues
show
Bug introduced by
The method findOrFail does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
73
        ]);
74
    }
75
76
    /**
77
     * Return function editing view for a service.
78
     *
79
     * @param  Request $request
80
     * @param  int     $id
81
     * @return \Illuminate\View\View
82
     */
83
    public function viewFunctions(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...
84
    {
85
        return view('admin.services.functions', ['service' => Models\Service::findOrFail($id)]);
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.services.fun...ice::findOrFail($id))); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 85 which is incompatible with the return type documented by Pterodactyl\Http\Control...ntroller::viewFunctions of type Illuminate\View\View.
Loading history...
86
    }
87
88
    /**
89
     * Handle post action for new service.
90
     *
91
     * @param  Request $request
92
     * @return \Illuminate\Response\RedirectResponse
93
     */
94 View Code Duplication
    public function create(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...
95
    {
96
        $repo = new ServiceRepository;
97
98
        try {
99
            $service = $repo->create($request->intersect([
100
                'name', 'description', 'folder', 'startup',
101
            ]));
102
            Alert::success('Successfully created new service!')->flash();
103
104
            return redirect()->route('admin.services.view', $service->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Pterodactyl\Models\Service>. 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...
105
        } catch (DisplayValidationException $ex) {
106
            return redirect()->route('admin.services.new')->withErrors(json_decode($ex->getMessage()))->withInput();
107
        } catch (DisplayException $ex) {
108
            Alert::danger($ex->getMessage())->flash();
109
        } catch (\Exception $ex) {
110
            Log::error($ex);
111
            Alert::danger('An error occured while attempting to add a new service. This error has been logged.')->flash();
112
        }
113
114
        return redirect()->route('admin.services.new')->withInput();
115
    }
116
117
    /**
118
     * Edits configuration for a specific service.
119
     *
120
     * @param  Request $request
121
     * @param  int     $id
122
     * @return \Illuminate\Response\RedirectResponse
123
     */
124
    public function edit(Request $request, $id)
125
    {
126
        $repo = new ServiceRepository;
127
        $redirectTo = ($request->input('redirect_to')) ? 'admin.services.view.functions' : 'admin.services.view';
128
129
        try {
130
            if ($request->input('action') !== 'delete') {
131
                $repo->update($id, $request->intersect([
132
                    'name', 'description', 'folder', 'startup', 'index_file',
133
                ]));
134
                Alert::success('Service has been updated successfully.')->flash();
135
            } else {
136
                $repo->delete($id);
137
                Alert::success('Successfully deleted service from the system.')->flash();
138
139
                return redirect()->route('admin.services');
140
            }
141
        } catch (DisplayValidationException $ex) {
142
            return redirect()->route($redirectTo, $id)->withErrors(json_decode($ex->getMessage()))->withInput();
0 ignored issues
show
Documentation introduced by
$id is of type integer, 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...
143
        } catch (DisplayException $ex) {
144
            Alert::danger($ex->getMessage())->flash();
145
        } catch (\Exception $ex) {
146
            Log::error($ex);
147
            Alert::danger('An error occurred while attempting to update this service. This error has been logged.')->flash();
148
        }
149
150
        return redirect()->route($redirectTo, $id);
0 ignored issues
show
Documentation introduced by
$id is of type integer, 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...
151
    }
152
}
153