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
03:05 queued 22s
created

Server::pack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Models;
26
27
use Auth;
28
use Illuminate\Database\Eloquent\Model;
29
use Illuminate\Notifications\Notifiable;
30
use Illuminate\Database\Eloquent\SoftDeletes;
31
32
class Server extends Model
33
{
34
    use Notifiable, SoftDeletes;
35
36
    /**
37
     * The table associated with the model.
38
     *
39
     * @var string
40
     */
41
    protected $table = 'servers';
42
43
    /**
44
     * The attributes excluded from the model's JSON form.
45
     *
46
     * @var array
47
     */
48
    protected $hidden = ['daemonSecret', 'sftp_password'];
49
50
    /**
51
     * The attributes that should be mutated to dates.
52
     *
53
     * @var array
54
     */
55
    protected $dates = ['deleted_at'];
56
57
    /**
58
     * Fields that are not mass assignable.
59
     *
60
     * @var array
61
     */
62
    protected $guarded = ['id', 'installed', 'created_at', 'updated_at', 'deleted_at'];
63
64
     /**
65
      * Cast values to correct type.
66
      *
67
      * @var array
68
      */
69
     protected $casts = [
70
         'node' => 'integer',
71
         'suspended' => 'integer',
72
         'owner' => 'integer',
73
         'memory' => 'integer',
74
         'swap' => 'integer',
75
         'disk' => 'integer',
76
         'io' => 'integer',
77
         'cpu' => 'integer',
78
         'oom_disabled' => 'integer',
79
         'port' => 'integer',
80
         'service' => 'integer',
81
         'option' => 'integer',
82
         'installed' => 'integer',
83
     ];
84
85
    /**
86
     * @var array
87
     */
88
    protected static $serverUUIDInstance = [];
89
90
    /**
91
     * @var mixed
92
     */
93
    protected static $user;
94
95
    /**
96
     * Constructor.
97
     */
98
    public function __construct()
99
    {
100
        parent::__construct();
101
        self::$user = Auth::user();
102
    }
103
104
    /**
105
     * Returns array of all servers owned by the logged in user.
106
     * Returns all users servers if user is a root admin.
107
     *
108
     * @return \Illuminate\Database\Eloquent\Collection
109
     */
110
    public static function getUserServers($paginate = null)
111
    {
112
        $query = self::select(
113
            'servers.*',
114
            'nodes.name as nodeName',
115
            'locations.short as a_locationShort',
116
            'allocations.ip',
117
            'allocations.ip_alias',
118
            'allocations.port',
119
            'services.name as a_serviceName',
120
            'service_options.name as a_serviceOptionName'
121
        )->join('nodes', 'servers.node_id', '=', 'nodes.id')
122
        ->join('locations', 'nodes.location', '=', 'locations.id')
123
        ->join('services', 'servers.service_id', '=', 'services.id')
124
        ->join('service_options', 'servers.option_id', '=', 'service_options.id')
125
        ->join('allocations', 'servers.allocation_id', '=', 'allocations.id');
126
127
        if (self::$user->root_admin !== 1) {
128
            $query->whereIn('servers.id', Subuser::accessServers());
129
        }
130
131
        if (is_numeric($paginate)) {
132
            return $query->paginate($paginate);
133
        }
134
135
        return $query->get();
136
    }
137
138
    /**
139
     * Returns a single server specified by UUID.
140
     * DO NOT USE THIS TO MODIFY SERVER DETAILS OR SAVE THOSE DETAILS.
141
     * YOU WILL OVERWRITE THE SECRET KEY AND BREAK THINGS.
142
     *
143
     * @param  string $uuid The Short-UUID of the server to return an object about.
144
     * @return \Illuminate\Database\Eloquent\Collection
145
     */
146
    public static function byUuid($uuid)
147
    {
148
        $query = self::with('service', 'node')->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
0 ignored issues
show
Bug introduced by
The method where 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...
149
150
        if (! Auth::user()->isRootAdmin()) {
151
            $query->whereIn('id', Subuser::accessServers());
152
        }
153
154
        $result = $query->first();
155
156
        if (! is_null($result)) {
157
            $result->daemonSecret = Auth::user()->daemonToken($result);
158
        }
159
160
        return $result;
161
    }
162
163
    /**
164
     * Returns non-administrative headers for accessing a server on the daemon.
165
     *
166
     * @param  string $uuid
0 ignored issues
show
Bug introduced by
There is no parameter named $uuid. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
167
     * @return array
168
     */
169
    public function getHeaders()
170
    {
171
        return [
172
            'X-Access-Server' => $this->uuid,
0 ignored issues
show
Documentation introduced by
The property uuid does not exist on object<Pterodactyl\Models\Server>. 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...
173
            'X-Access-Token' => Auth::user()->daemonToken($this),
174
        ];
175
    }
176
177
    /**
178
     * Gets all allocations associated with this server.
179
     *
180
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
181
     */
182
    public function allocations()
183
    {
184
        return $this->hasMany(Allocation::class, 'assigned_to');
185
    }
186
187
    /**
188
     * Gets information for the pack associated with this server.
189
     *
190
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
191
     */
192
    public function pack()
193
    {
194
        return $this->hasOne(ServicePack::class, 'id', 'pack_id');
195
    }
196
197
    /**
198
     * Gets information for the service associated with this server.
199
     *
200
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
201
     */
202
    public function service()
203
    {
204
        return $this->hasOne(Service::class, 'id', 'service_id');
205
    }
206
207
    /**
208
     * Gets information for the service option associated with this server.
209
     *
210
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
211
     */
212
    public function option()
213
    {
214
        return $this->hasOne(ServiceOptions::class, 'id', 'option_id');
215
    }
216
217
    /**
218
     * Gets information for the service variables associated with this server.
219
     *
220
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
221
     */
222
    public function variables()
223
    {
224
        return $this->hasMany(ServerVariables::class);
225
    }
226
227
    /**
228
     * Gets information for the node associated with this server.
229
     *
230
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
231
     */
232
    public function node()
233
    {
234
        return $this->hasOne(Node::class, 'id', 'node_id');
235
    }
236
}
237