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.

OptionTransformer::includeServers()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
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\ServiceOption;
29
use League\Fractal\TransformerAbstract;
30
31
class OptionTransformer extends TransformerAbstract
32
{
33
    /**
34
     * List of resources that can be included.
35
     *
36
     * @var array
37
     */
38
    protected $availableIncludes = [
39
        'service',
40
        'packs',
41
        'servers',
42
        'variables',
43
    ];
44
45
    /**
46
     * The Illuminate Request object if provided.
47
     *
48
     * @var \Illuminate\Http\Request|bool
49
     */
50
    protected $request;
51
52
    /**
53
     * Setup request object for transformer.
54
     *
55
     * @param  \Illuminate\Http\Request|bool  $request
56
     * @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...
57
     */
58
    public function __construct($request = false)
59
    {
60
        if (! $request instanceof Request && $request !== false) {
61
            throw new DisplayException('Request passed to constructor must be of type Request or false.');
62
        }
63
64
        $this->request = $request;
65
    }
66
67
    /**
68
     * Return a generic transformed service option array.
69
     *
70
     * @return array
71
     */
72
    public function transform(ServiceOption $option)
73
    {
74
        return $option->toArray();
75
    }
76
77
    /**
78
     * Return the parent service for this service option.
79
     *
80
     * @return \Leauge\Fractal\Resource\Collection
81
     */
82
    public function includeService(ServiceOption $option)
83
    {
84
        if ($this->request && ! $this->request->apiKeyHasPermission('service-view')) {
85
            return;
86
        }
87
88
        return $this->item($option->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...
89
    }
90
91
    /**
92
     * Return the packs associated with this service option.
93
     *
94
     * @return \Leauge\Fractal\Resource\Collection
95
     */
96
    public function includePacks(ServiceOption $option)
97
    {
98
        if ($this->request && ! $this->request->apiKeyHasPermission('pack-list')) {
99
            return;
100
        }
101
102
        return $this->collection($option->packs, 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...
103
    }
104
105
    /**
106
     * Return the servers associated with this service option.
107
     *
108
     * @return \Leauge\Fractal\Resource\Collection
109
     */
110
    public function includeServers(ServiceOption $option)
111
    {
112
        if ($this->request && ! $this->request->apiKeyHasPermission('server-list')) {
113
            return;
114
        }
115
116
        return $this->collection($option->servers, new ServerTransformer($this->request), 'server');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...dmin\ServerTransformer>, 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...
117
    }
118
119
    /**
120
     * Return the variables for this service option.
121
     *
122
     * @return \Leauge\Fractal\Resource\Collection
123
     */
124
    public function includeVariables(ServiceOption $option)
125
    {
126
        if ($this->request && ! $this->request->apiKeyHasPermission('option-view')) {
127
            return;
128
        }
129
130
        return $this->collection($option->variables, new ServiceVariableTransformer($this->request), 'variable');
0 ignored issues
show
Documentation introduced by
new \Pterodactyl\Transfo...sformer($this->request) is of type object<Pterodactyl\Trans...iceVariableTransformer>, 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...
131
    }
132
}
133