Passed
Push — develop ( b76999...f6fe64 )
by Nikita
06:51
created

ChangePassword::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.9332
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
9
class ChangePassword extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'user:change-password {login} {password}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Change user password';
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
     * Get the console command arguments.
37
     *
38
     * @return array
39
     */
40
    protected function getArguments()
41
    {
42
        return [
43
            ['name', InputArgument::REQUIRED, 'The name of the job.'],
0 ignored issues
show
Bug introduced by
The type Gameap\Console\Commands\InputArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
45
        ];
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     * @return mixed
52
     */
53
    public function handle()
54
    {
55
        $userLogin = $this->argument('login');
56
        $userPassword = $this->argument('password');
57
58
        try {
59
            $user = User::where(['login' => $userLogin])->firstOrFail();
60
        } catch (ModelNotFoundException $e) {
61
            $this->error("User not found");
62
            return 1;
63
        }
64
65
        $user->password = $userPassword;
66
        $user->save();
67
68
        $this->info("Password changed");
69
    }
70
}
71