Passed
Push — develop ( dda913...1862b5 )
by Nikita
06:47
created

ChangePassword   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 18.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
c 1
b 0
f 0
dl 0
loc 60
ccs 3
cts 16
cp 0.1875
rs 10

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 Illuminate\Console\Command;
6
use Gameap\Models\User;
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
     * Get the console command arguments.
38
     *
39
     * @return array
40
     */
41
    protected function getArguments()
42
    {
43
        return [
44
            ['name', InputArgument::REQUIRED, 'The name of the job.'],
45
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
46
        ];
47
    }
48
49
    /**
50
     * Execute the console command.
51
     *
52
     * @return mixed
53
     */
54
    public function handle()
55
    {
56
        $userLogin = $this->argument('login');
57
        $userPassword = $this->argument('password');
58
59
        try {
60
            $user = User::where(['login' => $userLogin])->firstOrFail();
61
        } catch (ModelNotFoundException $e) {
62
            $this->error("User not found");
63
            return 1;
64
        }
65
66
        $user->password = $userPassword;
67
        $user->save();
68
69
        $this->info("Password changed");
70
    }
71
}
72