CreateUser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 32 6
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:base:user
15
                            {--N|name= : The name of the new user}
16
                            {--E|email= : The user\'s email address}
17
                            {--P|password= : User\'s password}
18
                            {--encrypt=true : Encrypt user\'s password if it\'s plain text ( true by default )}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Create a new user';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @return mixed
31
     */
32
    public function handle()
33
    {
34
        $this->info('Creating a new user');
35
36
        if (!$name = $this->option('name')) {
37
            $name = $this->ask('Name');
38
        }
39
40
        if (!$email = $this->option('email')) {
41
            $email = $this->ask('Email');
42
        }
43
44
        if (!$password = $this->option('password')) {
45
            $password = $this->secret('Password');
46
        }
47
48
        if ($this->option('encrypt')) {
49
            $password = bcrypt($password);
50
        }
51
52
        $auth = config('backpack.base.user_model_fqn', 'App\User');
53
        $user = new $auth();
54
        $user->name = $name;
55
        $user->email = $email;
56
        $user->password = $password;
57
58
        if ($user->save()) {
59
            $this->info('Successfully created new user');
60
        } else {
61
            $this->error('Something went wrong trying to save your user');
62
        }
63
    }
64
}
65