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

ChangePassword::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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