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.

MakeUser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
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\Console\Commands;
26
27
use Illuminate\Console\Command;
28
use Pterodactyl\Repositories\UserRepository;
29
30
class MakeUser extends Command
31
{
32
    /**
33
     * The name and signature of the console command.
34
     *
35
     * @var string
36
     */
37
    protected $signature = 'pterodactyl:user
38
                            {--firstname= : First name to use for this account.}
39
                            {--lastname= : Last name to use for this account.}
40
                            {--username= : Username to use for this account.}
41
                            {--email= : Email address to use for this account.}
42
                            {--password= : Password to assign to the user.}
43
                            {--admin= :  Boolean flag for if user should be an admin.}';
44
45
    /**
46
     * The console command description.
47
     *
48
     * @var string
49
     */
50
    protected $description = 'Create a user within the panel.';
51
52
    /**
53
     * Create a new command instance.
54
     *
55
     * @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...
56
     */
57
    public function __construct()
58
    {
59
        parent::__construct();
60
    }
61
62
    /**
63
     * Execute the console command.
64
     *
65
     * @return mixed
66
     */
67
    public function handle()
68
    {
69
        $data['name_first'] = is_null($this->option('firstname')) ? $this->ask('First Name') : $this->option('firstname');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
70
        $data['name_last'] = is_null($this->option('lastname')) ? $this->ask('Last Name') : $this->option('lastname');
71
        $data['username'] = is_null($this->option('username')) ? $this->ask('Username') : $this->option('username');
72
        $data['email'] = is_null($this->option('email')) ? $this->ask('Email') : $this->option('email');
73
        $data['password'] = is_null($this->option('password')) ? $this->secret('Password') : $this->option('password');
74
        $password_confirmation = is_null($this->option('password')) ? $this->secret('Confirm Password') : $this->option('password');
75
76
        if ($data['password'] !== $password_confirmation) {
77
            return $this->error('The passwords provided did not match!');
78
        }
79
80
        $data['root_admin'] = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin');
81
82
        try {
83
            $user = new UserRepository;
84
            $user->create($data);
85
86
            return $this->info('User successfully created.');
87
        } catch (\Exception $ex) {
88
            return $this->error($ex->getMessage());
89
        }
90
    }
91
}
92