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 (#371)
by Dane
05:00 queued 02:14
created

AllocationTransformer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A transform() 0 4 1
A transformWithFilter() 0 8 2
A transformForServer() 0 4 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\Allocation;
29
use League\Fractal\TransformerAbstract;
30
31
class AllocationTransformer extends TransformerAbstract
32
{
33
    /**
34
     * The filter to be applied to this transformer.
35
     *
36
     * @var bool|string
37
     */
38
    protected $filter;
39
40
    /**
41
     * The Illuminate Request object if provided.
42
     *
43
     * @var \Illuminate\Http\Request|bool
44
     */
45
    protected $request;
46
47
    /**
48
     * Setup request object for transformer.
49
     *
50
     * @param  \Illuminate\Http\Request|bool  $request
51
     * @param  bool                           $filter
52
     * @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...
53
     */
54
    public function __construct($request = false, $filter = false)
55
    {
56
        if (! $request instanceof Request && $request !== false) {
57
            throw new DisplayException('Request passed to constructor must be of type Request or false.');
58
        }
59
60
        $this->request = $request;
61
        $this->filter = $filter;
62
    }
63
64
    /**
65
     * Return a generic transformed allocation array.
66
     *
67
     * @return array
68
     */
69
    public function transform(Allocation $allocation)
70
    {
71
        return $this->transformWithFilter($allocation);
72
    }
73
74
    /**
75
     * Determine which transformer filter to apply.
76
     *
77
     * @return array
78
     */
79
    protected function transformWithFilter(Allocation $allocation)
80
    {
81
        if ($this->filter === 'server') {
82
            return $this->transformForServer($allocation);
83
        }
84
85
        return $allocation->toArray();
86
    }
87
88
    /**
89
     * Transform the allocation to only return information not duplicated
90
     * in the server response (discard node_id and server_id).
91
     *
92
     * @return array
93
     */
94
    protected function transformForServer(Allocation $allocation)
95
    {
96
        return collect($allocation)->only('id', 'ip', 'ip_alias', 'port')->toArray();
97
    }
98
}
99