CreateUser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use App\User;
7
use Illuminate\Support\Facades\Hash;
8
use Illuminate\Support\Str;
9
10
class CreateUser extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'app:create-user {email}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Creates a user with the given email as email address and username. Password will be generated and printed on commandline.';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
        $user = new User();
44
        $user->email = $this->argument('email');
45
        $user->name = $this->argument('email');
46
        $user->email_verified_at = new \DateTime();
47
        $password = Str::random(20);
48
        $user->password = Hash::make($password);
49
        $user->save();
50
        $this->info('Your password: ' . $password);
51
    }
52
}
53