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.

ServerTransformer::includeOption()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
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\Transformers\Admin;
26
27
use Illuminate\Http\Request;
28
use Pterodactyl\Models\Server;
29
use League\Fractal\TransformerAbstract;
30
31
class ServerTransformer extends TransformerAbstract
32
{
33
    /**
34
     * List of resources that can be included.
35
     *
36
     * @var array
37
     */
38
    protected $availableIncludes = [
39
        'allocations',
40
        'user',
41
        'subusers',
42
        'pack',
43
        'service',
44
        'option',
45
        'variables',
46
        'location',
47
        'node',
48
    ];
49
50
    /**
51
     * The Illuminate Request object if provided.
52
     *
53
     * @var \Illuminate\Http\Request|bool
54
     */
55
    protected $request;
56
57
    /**
58
     * Setup request object for transformer.
59
     *
60
     * @param  \Illuminate\Http\Request|bool  $request
61
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
62
     */
63
    public function __construct($request = false)
64
    {
65
        if (! $request instanceof Request && $request !== false) {
66
            throw new DisplayException('Request passed to constructor must be of type Request or false.');
67
        }
68
69
        $this->request = $request;
70
    }
71
72
    /**
73
     * Return a generic transformed server array.
74
     *
75
     * @return array
76
     */
77
    public function transform(Server $server)
78
    {
79
        return collect($server->toArray())->only($server->getTableColumns())->toArray();
80
    }
81
82
    /**
83
     * Return a generic array of allocations for this server.
84
     *
85
     * @return \Leauge\Fractal\Resource\Collection
86
     */
87
    public function includeAllocations(Server $server)
88
    {
89
        if ($this->request && ! $this->request->apiKeyHasPermission('server-view')) {
90
            return;
91
        }
92
93
        return $this->collection($server->allocations, new AllocationTransformer($this->request, 'server'), 'allocation');
0 ignored issues
show
Documentation introduced by
'server' is of type string, but the function expects a boolean.

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...
Documentation introduced by
new \Pterodactyl\Transfo...his->request, 'server') is of type object<Pterodactyl\Trans...\AllocationTransformer>, but the function expects a callable.

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...
94
    }
95
96
    /**
97
     * Return a generic array of data about subusers for this server.
98
     *
99
     * @return \Leauge\Fractal\Resource\Collection
100
     */
101
    public function includeSubusers(Server $server)
102
    {
103
        if ($this->request && ! $this->request->apiKeyHasPermission('server-view')) {
104
            return;
105
        }
106
107
        return $this->collection($server->subusers, new SubuserTransformer($this->request), 'subuser');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...min\SubuserTransformer>, but the function expects a callable.

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...
108
    }
109
110
    /**
111
     * Return a generic array of data about subusers for this server.
112
     *
113
     * @return \Leauge\Fractal\Resource\Item
114
     */
115
    public function includeUser(Server $server)
116
    {
117
        if ($this->request && ! $this->request->apiKeyHasPermission('user-view')) {
118
            return;
119
        }
120
121
        return $this->item($server->user, new UserTransformer($this->request), 'user');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...\Admin\UserTransformer>, but the function expects a callable.

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...
122
    }
123
124
    /**
125
     * Return a generic array with pack information for this server.
126
     *
127
     * @return \Leauge\Fractal\Resource\Item
128
     */
129
    public function includePack(Server $server)
130
    {
131
        if ($this->request && ! $this->request->apiKeyHasPermission('pack-view')) {
132
            return;
133
        }
134
135
        return $this->item($server->pack, new PackTransformer($this->request), 'pack');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...\Admin\PackTransformer>, but the function expects a callable.

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...
136
    }
137
138
    /**
139
     * Return a generic array with service information for this server.
140
     *
141
     * @return \Leauge\Fractal\Resource\Item
142
     */
143
    public function includeService(Server $server)
144
    {
145
        if ($this->request && ! $this->request->apiKeyHasPermission('service-view')) {
146
            return;
147
        }
148
149
        return $this->item($server->service, new ServiceTransformer($this->request), 'service');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...min\ServiceTransformer>, but the function expects a callable.

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...
150
    }
151
152
    /**
153
     * Return a generic array with service option information for this server.
154
     *
155
     * @return \Leauge\Fractal\Resource\Item
156
     */
157
    public function includeOption(Server $server)
158
    {
159
        if ($this->request && ! $this->request->apiKeyHasPermission('option-view')) {
160
            return;
161
        }
162
163
        return $this->item($server->option, new OptionTransformer($this->request), 'option');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...dmin\OptionTransformer>, but the function expects a callable.

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...
164
    }
165
166
    /**
167
     * Return a generic array of data about subusers for this server.
168
     *
169
     * @return \Leauge\Fractal\Resource\Collection
170
     */
171
    public function includeVariables(Server $server)
172
    {
173
        if ($this->request && ! $this->request->apiKeyHasPermission('server-view')) {
174
            return;
175
        }
176
177
        return $this->collection($server->variables, new ServerVariableTransformer($this->request), 'server_variable');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...verVariableTransformer>, but the function expects a callable.

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...
178
    }
179
180
    /**
181
     * Return a generic array with pack information for this server.
182
     *
183
     * @return \Leauge\Fractal\Resource\Item
184
     */
185
    public function includeLocation(Server $server)
186
    {
187
        if ($this->request && ! $this->request->apiKeyHasPermission('location-list')) {
188
            return;
189
        }
190
191
        return $this->item($server->location, new LocationTransformer($this->request), 'location');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...in\LocationTransformer>, but the function expects a callable.

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...
192
    }
193
194
    /**
195
     * Return a generic array with pack information for this server.
196
     *
197
     * @return \Leauge\Fractal\Resource\Item|void
198
     */
199
    public function includeNode(Server $server)
200
    {
201
        if ($this->request && ! $this->request->apiKeyHasPermission('node-view')) {
202
            return;
203
        }
204
205
        return $this->item($server->node, new NodeTransformer($this->request), 'node');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...\Admin\NodeTransformer>, but the function expects a callable.

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...
206
    }
207
}
208