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

NodesController::viewAllocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
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 DB;
28
use Log;
29
use Alert;
30
use Javascript;
31
use Pterodactyl\Models;
32
use Illuminate\Http\Request;
33
use Pterodactyl\Exceptions\DisplayException;
34
use Pterodactyl\Http\Controllers\Controller;
35
use Pterodactyl\Repositories\NodeRepository;
36
use Pterodactyl\Exceptions\DisplayValidationException;
37
38
class NodesController extends Controller
39
{
40
    /**
41
     * Displays the index page listing all nodes on the panel.
42
     *
43
     * @param  \Illuminate\Http\Request  $request
44
     * @return \Illuminate\View\View
45
     */
46 View Code Duplication
    public function index(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...
47
    {
48
        $nodes = Models\Node::with('location')->withCount('servers');
0 ignored issues
show
Bug introduced by
The method withCount 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...
49
50
        if (! is_null($request->input('query'))) {
51
            $nodes->search($request->input('query'));
52
        }
53
54
        return view('admin.nodes.index', ['nodes' => $nodes->paginate(25)]);
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.nodes.index'...$nodes->paginate(25))); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 54 which is incompatible with the return type documented by Pterodactyl\Http\Control...\NodesController::index of type Illuminate\View\View.
Loading history...
55
    }
56
57
    /**
58
     * Displays create new node page.
59
     *
60
     * @param  \Illuminate\Http\Request  $request
61
     * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
62
     */
63
    public function create(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...
64
    {
65
        $locations = Models\Location::all();
66
        if (! $locations->count()) {
67
            Alert::warning('You must add a location before you can add a new node.')->flash();
68
69
            return redirect()->route('admin.locations');
70
        }
71
72
        return view('admin.nodes.new', ['locations' => $locations]);
73
    }
74
75
    /**
76
     * Post controller to create a new node on the system.
77
     *
78
     * @param  \Illuminate\Http\Request  $request
79
     * @return \Illuminate\Http\RedirectResponse
80
     */
81 View Code Duplication
    public function store(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...
82
    {
83
        try {
84
            $repo = new NodeRepository;
85
            $node = $repo->create(array_merge(
86
                $request->only([
87
                    'public', 'disk_overallocate', 'memory_overallocate',
88
                ]),
89
                $request->intersect([
90
                    'name', 'location_id', 'fqdn',
91
                    'scheme', 'memory', 'disk',
92
                    'daemonBase', 'daemonSFTP', 'daemonListen',
93
                ])
94
            ));
95
            Alert::success('Successfully created new node that can be configured automatically on your remote machine by visiting the configuration tab. <strong>Before you can add any servers you need to first assign some IP addresses and ports.</strong>')->flash();
96
97
            return redirect()->route('admin.nodes.view', $node->id);
98
        } catch (DisplayValidationException $e) {
99
            return redirect()->route('admin.nodes.new')->withErrors(json_decode($e->getMessage()))->withInput();
100
        } catch (DisplayException $e) {
101
            Alert::danger($e->getMessage())->flash();
102
        } catch (\Exception $e) {
103
            Log::error($e);
104
            Alert::danger('An unhandled exception occured while attempting to add this node. Please try again.')->flash();
105
        }
106
107
        return redirect()->route('admin.nodes.new')->withInput();
108
    }
109
110
    /**
111
     * Shows the index overview page for a specific node.
112
     *
113
     * @param  \Illuminate\Http\Request  $request
114
     * @param  int                       $id
115
     * @return \Illuminate\View\View
116
     */
117
    public function viewIndex(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...
118
    {
119
        $node = Models\Node::with('location')->withCount('servers')->findOrFail($id);
0 ignored issues
show
Bug introduced by
The method withCount 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...
120
        $stats = collect(
121
            Models\Server::select(
122
                DB::raw('SUM(memory) as memory, SUM(disk) as disk')
123
            )->where('node_id', $node->id)->first()
124
        )->mapWithKeys(function ($item, $key) use ($node) {
125
            $percent = ($item / $node->{$key}) * 100;
126
127
            return [$key => [
128
                'value' => $item,
129
                'percent' => $percent,
130
                'css' => ($percent <= 75) ? 'green' : (($percent > 90) ? 'red' : 'yellow'),
131
            ]];
132
        })->toArray();
133
134
        return view('admin.nodes.view.index', ['node' => $node, 'stats' => $stats]);
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.nodes.view.i...e, 'stats' => $stats)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 134 which is incompatible with the return type documented by Pterodactyl\Http\Control...esController::viewIndex of type Illuminate\View\View.
Loading history...
135
    }
136
137
    /**
138
     * Shows the settings page for a specific node.
139
     *
140
     * @param  \Illuminate\Http\Request  $request
141
     * @param  int                       $id
142
     * @return \Illuminate\View\View
143
     */
144
    public function viewSettings(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...
145
    {
146
        return view('admin.nodes.view.settings', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.nodes.view.s...dels\Location::all())); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 146 which is incompatible with the return type documented by Pterodactyl\Http\Control...ontroller::viewSettings of type Illuminate\View\View.
Loading history...
147
            'node' => Models\Node::findOrFail($id),
148
            'locations' => Models\Location::all(),
149
        ]);
150
    }
151
152
    /**
153
     * Shows the configuration page for a specific node.
154
     *
155
     * @param  \Illuminate\Http\Request  $request
156
     * @param  int                       $id
157
     * @return \Illuminate\View\View
158
     */
159
    public function viewConfiguration(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...
160
    {
161
        return view('admin.nodes.view.configuration', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.nodes.view.c...ode::findOrFail($id))); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 161 which is incompatible with the return type documented by Pterodactyl\Http\Control...ller::viewConfiguration of type Illuminate\View\View.
Loading history...
162
            'node' => Models\Node::findOrFail($id),
163
        ]);
164
    }
165
166
    /**
167
     * Shows the allocation page for a specific node.
168
     *
169
     * @param  \Illuminate\Http\Request  $request
170
     * @param  int                       $id
171
     * @return \Illuminate\View\View
172
     */
173
    public function viewAllocation(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...
174
    {
175
        $node = Models\Node::findOrFail($id);
176
        $node->setRelation('allocations', $node->allocations()->orderBy('ip', 'asc')->orderBy('port', 'asc')->with('server')->paginate(50));
177
178
        Javascript::put([
179
            'node' => collect($node)->only(['id']),
180
        ]);
181
182
        return view('admin.nodes.view.allocation', ['node' => $node]);
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.nodes.view.a...rray('node' => $node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 182 which is incompatible with the return type documented by Pterodactyl\Http\Control...troller::viewAllocation of type Illuminate\View\View.
Loading history...
183
    }
184
185
    /**
186
     * Shows the server listing page for a specific node.
187
     *
188
     * @param  \Illuminate\Http\Request  $request
189
     * @param  int                       $id
190
     * @return \Illuminate\View\View
191
     */
192
    public function viewServers(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...
193
    {
194
        $node = Models\Node::with('servers.user', 'servers.service', 'servers.option')->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...
195
        Javascript::put([
196
            'node' => collect($node->makeVisible('daemonSecret'))->only(['scheme', 'fqdn', 'daemonListen', 'daemonSecret']),
197
        ]);
198
199
        return view('admin.nodes.view.servers', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin.nodes.view.s...rray('node' => $node)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 199 which is incompatible with the return type documented by Pterodactyl\Http\Control...Controller::viewServers of type Illuminate\View\View.
Loading history...
200
            'node' => $node,
201
        ]);
202
    }
203
204
    /**
205
     * Updates settings for a node.
206
     *
207
     * @param  \Illuminate\Http\Request  $request
208
     * @param  int                       $id
209
     * @return \Illuminate\Http\RedirectResponse
210
     */
211
    public function updateSettings(Request $request, $id)
212
    {
213
        $repo = new NodeRepository;
214
215
        try {
216
            $node = $repo->update($id, array_merge(
0 ignored issues
show
Unused Code introduced by
$node is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
217
                $request->only([
218
                    'public', 'disk_overallocate', 'memory_overallocate',
219
                ]),
220
                $request->intersect([
221
                    'name', 'location_id', 'fqdn',
222
                    'scheme', 'memory', 'disk', 'upload_size',
223
                    'reset_secret', 'daemonSFTP', 'daemonListen',
224
                ])
225
            ));
226
            Alert::success('Successfully updated this node\'s information. If you changed any daemon settings you will need to restart it now.')->flash();
227
        } catch (DisplayValidationException $ex) {
228
            return redirect()->route('admin.nodes.view.settings', $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...
229
        } catch (DisplayException $ex) {
230
            Alert::danger($ex->getMessage())->flash();
231
        } catch (\Exception $ex) {
232
            Log::error($ex);
233
            Alert::danger('An unhandled exception occured while attempting to edit this node. Please try again.')->flash();
234
        }
235
236
        return redirect()->route('admin.nodes.view.settings', $id)->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...
237
    }
238
239
    /**
240
     * Removes a single allocation from a node.
241
     *
242
     * @param  \Illuminate\Http\Request  $request
243
     * @param  int                       $node
244
     * @param  int                       $allocation
245
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
246
     */
247
    public function allocationRemoveSingle(Request $request, $node, $allocation)
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...
248
    {
249
        $query = Models\Allocation::where('node_id', $node)->whereNull('server_id')->where('id', $allocation)->delete();
250
        if ($query < 1) {
251
            return response()->json([
252
                'error' => 'Unable to find an allocation matching those details to delete.',
253
            ], 400);
254
        }
255
256
        return response('', 204);
257
    }
258
259
    /**
260
     * Remove all allocations for a specific IP at once on a node.
261
     *
262
     * @param  \Illuminate\Http\Request  $request
263
     * @param  int                       $node
264
     * @return \Illuminate\Http\RedirectResponse
265
     */
266
    public function allocationRemoveBlock(Request $request, $node)
267
    {
268
        $query = Models\Allocation::where('node_id', $node)->whereNull('server_id')->where('ip', $request->input('ip'))->delete();
269
        if ($query < 1) {
270
            Alert::danger('There was an error while attempting to delete allocations on that IP.')->flash();
271
        } else {
272
            Alert::success('Deleted all unallocated ports for <code>' . $request->input('ip') . '</code>.')->flash();
273
        }
274
275
        return redirect()->route('admin.nodes.view.allocation', $node);
0 ignored issues
show
Documentation introduced by
$node 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...
276
    }
277
278
    /**
279
     * Sets an alias for a specific allocation on a node.
280
     *
281
     * @param  \Illuminate\Http\Request  $request
282
     * @param  int                       $node
283
     * @return \Illuminate\Http\Response
284
     */
285
    public function allocationSetAlias(Request $request, $node)
0 ignored issues
show
Unused Code introduced by
The parameter $node 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...
286
    {
287
        if (! $request->input('allocation_id')) {
288
            return response('Missing required parameters.', 422);
289
        }
290
291
        try {
292
            $update = Models\Allocation::findOrFail($request->input('allocation_id'));
293
            $update->ip_alias = (empty($request->input('alias'))) ? null : $request->input('alias');
294
            $update->save();
295
296
            return response('', 204);
297
        } catch (\Exception $ex) {
298
            throw $ex;
299
        }
300
    }
301
302
    /**
303
     * Creates new allocations on a node.
304
     *
305
     * @param  \Illuminate\Http\Request  $request
306
     * @param  int                       $node
307
     * @return \Illuminate\Http\RedirectResponse
308
     */
309
    public function createAllocation(Request $request, $node)
310
    {
311
        $repo = new NodeRepository;
312
313
        try {
314
            $repo->addAllocations($node, $request->intersect(['allocation_ip', 'allocation_alias', 'allocation_ports']));
315
            Alert::success('Successfully added new allocations!')->flash();
316
        } catch (DisplayValidationException $ex) {
317
            return redirect()->route('admin.nodes.view.allocation', $node)->withErrors(json_decode($ex->getMessage()))->withInput();
0 ignored issues
show
Documentation introduced by
$node 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...
318
        } catch (DisplayException $ex) {
319
            Alert::danger($ex->getMessage())->flash();
320
        } catch (\Exception $ex) {
321
            Log::error($ex);
322
            Alert::danger('An unhandled exception occured while attempting to add allocations this node. This error has been logged.')->flash();
323
        }
324
325
        return redirect()->route('admin.nodes.view.allocation', $node);
0 ignored issues
show
Documentation introduced by
$node 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...
326
    }
327
328
    /**
329
     * Deletes a node from the system.
330
     *
331
     * @param  \Illuminate\Http\Request  $request
332
     * @param  int                       $id
333
     * @return \Illuminate\Http\RedirectResponse
334
     */
335 View Code Duplication
    public function delete(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...
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...
336
    {
337
        $repo = new NodeRepository;
338
339
        try {
340
            $repo->delete($id);
341
            Alert::success('Successfully deleted the requested node from the panel.')->flash();
342
343
            return redirect()->route('admin.nodes');
344
        } catch (DisplayException $ex) {
345
            Alert::danger($ex->getMessage())->flash();
346
        } catch (\Exception $ex) {
347
            Log::error($ex);
348
            Alert::danger('An unhandled exception occured while attempting to delete this node. Please try again.')->flash();
349
        }
350
351
        return redirect()->route('admin.nodes.view', $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...
352
    }
353
354
    /**
355
     * Returns the configuration token to auto-deploy a node.
356
     *
357
     * @param  \Illuminate\Http\Request  $request
358
     * @param  int                       $id
359
     * @return \Illuminate\Http\JsonResponse
360
     */
361
    public function setToken(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...
362
    {
363
        $node = Models\Node::findOrFail($id);
0 ignored issues
show
Unused Code introduced by
$node is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
364
365
        $t = Models\NodeConfigurationToken::create([
366
            'node_id' => $id,
367
            'token' => str_random(32),
368
        ]);
369
370
        return response()->json(['token' => $t->token]);
371
    }
372
}
373