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

UpdateUserPassword::update()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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