Completed
Pull Request — master (#310)
by
unknown
11:24
created

CreateUser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 28 5
1
<?php
2
3
namespace Backpack\Base\app\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
class CreateUser extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'backpack:user
15
                            {--name= : The name of the new user}
16
                            {--email= : The user\'s email address}
17
                            {--password= : User\'s password}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new user';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function handle()
32
    {
33
        $this->info('Creating a new user');
34
35
        if (!$name = $this->option('name')) {
36
            $name = $this->ask('Name');
37
        }
38
39
        if (!$email = $this->option('email')) {
40
            $email = $this->ask('Email');
41
        }
42
43
        if (!$password = $this->option('password')) {
44
            $password = $this->secret('Password');
45
        }
46
47
        $auth = config('backpack.base.user_model_fqn', 'App\User');
48
        $user = new $auth();
49
        $user->name = $name;
50
        $user->email = $email;
51
        $user->password = bcrypt($password);
0 ignored issues
show
Bug introduced by
It seems like $password defined by $this->option('password') on line 43 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...
52
53
        if ($user->save()) {
54
            $this->info('Successfully created new user');
55
        } else {
56
            $this->error('Something went wrong trying to save your user');
57
        }
58
    }
59
}
60