ChangePassword   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 20%

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 59
ccs 3
cts 15
cp 0.2
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 2
A getArguments() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
namespace Gameap\Console\Commands;
4
5
use Gameap\Models\User;
6
use Illuminate\Console\Command;
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class ChangePassword extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'user:change-password {login} {password}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Change user password';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31 3
    public function __construct()
32
    {
33 3
        parent::__construct();
34 3
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
        $userLogin    = $this->argument('login');
44
        $userPassword = $this->argument('password');
45
46
        try {
47
            $user = User::where(['login' => $userLogin])->firstOrFail();
48
        } catch (ModelNotFoundException $e) {
49
            $this->error('User not found');
50
            return 1;
51
        }
52
53
        $user->password = $userPassword;
54
        $user->save();
55
56
        $this->info('Password changed');
57
    }
58
59
    /**
60
     * Get the console command arguments.
61
     *
62
     * @return array
63
     */
64
    protected function getArguments()
65
    {
66
        return [
67
            ['name', InputArgument::REQUIRED, 'The name of the job.'],
68
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
69
        ];
70
    }
71
}
72