Passed
Push — master ( 609094...890e61 )
by
05:08
created

ApplicationInstallCommand::actionDev()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Qsnh/meedu.
5
 *
6
 * (c) XiaoTeng <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace App\Console\Commands;
13
14
use App\Models\Administrator;
15
use Illuminate\Console\Command;
16
use Illuminate\Support\Facades\Artisan;
17
18
class ApplicationInstallCommand extends Command
19
{
20
    /**
21
     * The name and signature of the console command.
22
     *
23
     * @var string
24
     */
25
    protected $signature = 'install {action}';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Application install tools.';
33
34
    /**
35
     * Create a new command instance.
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /**
43
     * Execute the console command.
44
     *
45
     * @return mixed
46
     */
47
    public function handle()
48
    {
49
        $action = $this->argument('action');
50
        if (! $action) {
51
            $this->warn('Please choice action.');
52
53
            return;
54
        }
55
56
        $method = 'action'.implode('', array_map('ucfirst', explode('_', $action)));
0 ignored issues
show
Bug introduced by
It seems like $action can also be of type array; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $method = 'action'.implode('', array_map('ucfirst', explode('_', /** @scrutinizer ignore-type */ $action)));
Loading history...
57
        if (! method_exists($this, $method)) {
58
            $this->warn('action not exists.');
59
60
            return;
61
        }
62
63
        return $this->{$method}();
64
    }
65
66
    public function actionAdministrator()
67
    {
68
        $name = '超级管理员';
69
        $email = '';
70
        while ($email == '') {
71
            $email = $this->ask('please input administrator email:', '');
72
            if ($email != '') {
73
                $exists = Administrator::whereEmail($email)->exists();
74
                if ($exists) {
75
                    $this->warn('email has already exists.');
76
                    $email = '';
77
                }
78
            }
79
        }
80
81
        $password = '';
82
        while ($password == '') {
83
            $password = $this->ask('please input administrator password:', '');
84
        }
85
86
        $passwordRepeat = '';
87
        while ($passwordRepeat == '') {
88
            $passwordRepeat = $this->ask('please input administrator password repeat:', '');
89
        }
90
91
        if ($passwordRepeat != $password) {
92
            $this->warn('password not correct.');
93
94
            return;
95
        }
96
97
        $administrator = new Administrator([
98
            'name' => $name,
99
            'email' => $email,
100
            'password' => bcrypt($password),
101
        ]);
102
        $administrator->save();
103
104
        $this->info('administrator create success.');
105
    }
106
107
    public function actionDev()
108
    {
109
        Artisan::call('migrate');
110
        Artisan::call('db:seed');
111
        Administrator::create([
112
            'name' => '小滕',
113
            'email' => '[email protected]',
114
            'password' => bcrypt('123123'),
115
        ]);
116
    }
117
}
118