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.

ManageUsers   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 100
rs 10
c 1
b 0
f 0
wmc 13
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C handle() 0 70 12
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\User;
6
use Illuminate\Console\Command;
7
8
class ManageUsers extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'mmex:user {email?} {password?} {--delete} {--admin} {--noadmin}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Add, remove and change users from commandline';
23
24
    /**
25
     * Create a new command instance.
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct();
30
    }
31
32
    /**
33
     * Execute the console command.
34
     *
35
     * @return mixed
36
     */
37
    public function handle()
38
    {
39
        $email = $this->argument('email');
40
        $password = $this->argument('password');
41
42
        $delete = $this->option('delete');
43
        $admin = $this->option('admin');
44
        $noadmin = $this->option('noadmin');
45
46
        $user = User::whereEmail($email)->first();
47
48
        if ($delete) {
49
            if (!$user) {
50
                $this->error(sprintf('User %s does not exist!', $email));
51
            } else {
52
                $user->delete();
53
54
                $this->warn(sprintf('%s was deleted', $user->username));
55
            }
56
57
            return;
58
        }
59
60
        if (empty($email) && empty($password)) {
61
            $headers = ['Name', 'Email', 'Admin', 'MMEX Guid', 'Locale', 'API Key', 'Created at'];
62
63
            $users = User::all(['name', 'email', 'is_admin', 'mmex_guid', 'locale', 'api_token', 'created_at'])->toArray();
64
65
            $this->info(sprintf('%d users found', count($users)));
66
67
            $this->table($headers, $users);
68
69
            return;
70
        }
71
72
        if (!$user) {
73
            $name = $this->ask('Name of user?');
74
            $user = User::create([
75
                'name'     => $name,
76
                'email'    => $email,
77
                'password' => bcrypt($password),
0 ignored issues
show
Bug introduced by
It seems like $password defined by $this->argument('password') on line 40 can also be of type array; however, bcrypt() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
78
            ]);
79
80
            $this->info(sprintf('User %s was created!', $user->username));
81
        } else {
82
            if ($password) {
83
                $user->password = bcrypt($password);
0 ignored issues
show
Bug introduced by
It seems like $password defined by $this->argument('password') on line 40 can also be of type array; however, bcrypt() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
84
                $user->save();
85
86
                $this->info(sprintf('%s\'s password was updated!', $user->name));
87
            }
88
        }
89
90
        if ($admin || $noadmin) {
91
            if (!$user) {
92
                $this->error(sprintf('User %s does not exist!', $email));
93
            } else {
94
                $user->is_admin = $admin || $noadmin;
95
                $user->save();
96
97
                if ($admin == true) {
98
                    $this->info('Admin privileges set');
99
                } else {
100
                    $this->info('Admin privileges removed');
101
                }
102
103
                return;
104
            }
105
        }
106
    }
107
}
108