Completed
Push — master ( df4800...ec8b14 )
by Manuel
03:30
created

UserCreate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 47.83%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 82
ccs 11
cts 23
cp 0.4783
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getArguments() 0 6 1
A getOptions() 0 7 1
A fire() 0 16 3
1
<?php
2
3
namespace PiFinder\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Contracts\Auth\Registrar;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class UserCreate extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'user:create';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a user.';
25
26
    /**
27
     * The registrar implementation.
28
     *
29
     * @var Registrar
30
     */
31
    private $registrar;
32
33
    /**
34
     * Create a new command instance.
35
     *
36
     * @param Registrar $registrar
37
     */
38 4
    public function __construct(Registrar $registrar)
39
    {
40 4
        parent::__construct();
41
42 4
        $this->registrar = $registrar;
43 4
    }
44
45
    /**
46
     * Execute the console command.
47
     *
48
     * @return mixed
49
     */
50
    public function fire()
51
    {
52
        $email = $this->argument('email');
53
        $password = $this->option('password');
54
        $password_confirmation = $this->option('password_confirmation');
55
56
        if (!$password) {
57
            $password = $this->secret('What password should the user have?');
58
        }
59
60
        if (!$password_confirmation) {
61
            $password_confirmation = $this->secret('Please confirm the password.');
62
        }
63
64
        $this->registrar->create(compact('email', 'password', 'password_confirmation'));
65
    }
66
67
    /**
68
     * Get the console command arguments.
69
     *
70
     * @return array
71
     */
72 4
    protected function getArguments()
73
    {
74
        return [
75 4
            ['email', InputArgument::REQUIRED, 'The email address of the user.'],
76 4
        ];
77
    }
78
79
    /**
80
     * Get the console command options.
81
     *
82
     * @return array
83
     */
84 4
    protected function getOptions()
85
    {
86
        return [
87 4
            ['password', null, InputOption::VALUE_OPTIONAL, 'The password for the user.', null],
88 4
            ['password_confirmation', null, InputOption::VALUE_OPTIONAL, 'Password confirmation.', null],
89 4
        ];
90
    }
91
}
92