Passed
Push — master ( b831b6...96f132 )
by John
06:04 queued 21s
created

BanUser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\Console\Commands\Manage;
4
5
use Illuminate\Console\Command;
6
use App\Models\Eloquent\UserBanned;
7
use App\User;
8
9
class BanUser extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'manage:ban {--uid=: the user you want to ban} {--time=: Unban time, Supports time that can be resolved by the strtotime method} {--reason=: reason}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Ban a user';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @return void
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function handle()
41
    {
42
        $uid=(int)$this->option('uid');
43
        $reason=$this->option('reason');
44
        $time=$this->option('time');
45
        $user = User::find($uid);
46
        if(empty($user)) {
47
            $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>User Not Found</>\n");
48
            return;
49
        }
50
        try{
51
            $ban_time = date('Y-m-d H:i:s',strtotime($time));
52
            UserBanned::create([
53
                'user_id'    => $user->id,
54
                'reason'     => $reason,
55
                'removed_at' => $ban_time
56
            ]);
57
            $this->line("The user <fg=yellow>{$user->name}</> will be banned until <fg=yellow>{$ban_time}</>");
58
        }catch(Throwable $e){
0 ignored issues
show
Bug introduced by
The type App\Console\Commands\Manage\Throwable was not found. Did you mean Throwable? If so, make sure to prefix the type with \.
Loading history...
59
            $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>Wrong Time.</>\n");
60
            return;
61
        }
62
    }
63
}
64