Passed
Push — main ( 90e5be...1748cd )
by Thierry
04:42
created

UpdateUserPassword   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 14 3
1
<?php
2
3
namespace App\Actions;
4
5
use Illuminate\Support\Facades\Hash;
6
use Illuminate\Support\Facades\Validator;
7
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
8
9
class UpdateUserPassword implements UpdatesUserPasswords
10
{
11
    use Fortify\PasswordValidationRules;
12
13
    /**
14
     * Validate and update the user's password.
15
     *
16
     * @param  mixed  $user
17
     * @param  array  $input
18
     * @return void
19
     */
20
    public function update($user, array $input)
21
    {
22
        Validator::make($input, [
23
            'current_password' => ['required', 'string'],
24
            'password' => $this->passwordRules(),
25
        ])->after(function ($validator) use ($user, $input) {
26
            if (! isset($input['current_password']) || ! Hash::check($input['current_password'], $user->password)) {
27
                $validator->errors()->add('current_password', __('The provided password does not match your current password.'));
28
            }
29
        })->validateWithBag('password');
30
31
        $user->forceFill([
32
            'password' => Hash::make($input['password']),
33
        ])->save();
34
    }
35
}
36