Completed
Push — master ( 8927df...f70445 )
by Abdelrahman
02:05
created

UserRemindCommand::handle()   C

Complexity

Conditions 8
Paths 42

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 21
nc 42
nop 0
dl 0
loc 33
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Console\Commands;
17
18
use Illuminate\Mail\Message;
19
use Illuminate\Console\Command;
20
use Illuminate\Support\Facades\Lang;
21
22
class UserRemindCommand extends Command
23
{
24
    /**
25
     * The name and signature of the console command.
26
     *
27
     * @var string
28
     */
29
    protected $signature = 'fort:user:remind
30
                            {user? : The user identifier}
31
                            {action? : The action to remind user of}
32
                            {broker? : The name of the password broker}';
33
34
    /**
35
     * The console command description.
36
     *
37
     * @var string
38
     */
39
    protected $description = 'Remind user to take action (reset password, verify email).';
40
41
    /**
42
     * Execute the console command.
43
     *
44
     * @return void
45
     */
46
    public function handle()
47
    {
48
        $userField = $this->argument('user') ?: $this->ask(Lang::get('rinvex.fort::artisan.user.identifier'));
49
50
        if (intval($userField)) {
51
            $user = $this->laravel['rinvex.fort.user']->find($userField);
52
        } else if (filter_var($userField, FILTER_VALIDATE_EMAIL)) {
53
            $user = $this->laravel['rinvex.fort.user']->findWhere(['email' => $userField])->first();
54
        } else {
55
            $user = $this->laravel['rinvex.fort.user']->findWhere(['username' => $userField])->first();
56
        }
57
58
        if (! $user) {
59
            return $this->error(Lang::get('rinvex.fort::artisan.user.invalid', ['field' => $userField]));
60
        }
61
62
63
        $actionField = $this->argument('action') ?: $this->anticipate(Lang::get('rinvex.fort::artisan.user.action'), ['resetpassword', 'verification']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 152 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
64
65
        switch ($actionField) {
66
            case 'resetpassword':
67
                $this->laravel['rinvex.fort.resetter']->broker($this->argument('broker'))->sendResetLink(['email' => $user->email]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
68
                return $this->info(Lang::get('rinvex.fort::artisan.user.resetpassword'));
69
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
70
71
            case 'verification':
72
                $this->laravel['rinvex.fort.verifier']->broker($this->argument('broker'))->sendVerificationLink(['email' => $user->email]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
73
                return $this->info(Lang::get('rinvex.fort::artisan.user.verification'));
74
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
75
        }
76
77
        return $this->error(Lang::get('rinvex.fort::artisan.user.invalidaction'));
78
    }
79
}
80