Passed
Branch main (b90ec4)
by Thierry
20:23 queued 14:04
created

UpdateUserPassword   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 1
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
use Siak\Tontine\Model\User;
9
10
class UpdateUserPassword implements UpdatesUserPasswords
11
{
12
    use Fortify\PasswordValidationRules;
13
14
    /**
15
     * Validate and update the user's password.
16
     *
17
     * @param  array<string, string>  $input
18
     */
19
    public function update(User $user, array $input): void
20
    {
21
        Validator::make($input, [
22
            'current_password' => ['required', 'string', 'current_password:web'],
23
            'password' => $this->passwordRules(),
24
        ], [
25
            'current_password.current_password' => __('The provided password does not match your current password.'),
26
        ])->validateWithBag('password');
27
28
        $user->forceFill([
29
            'password' => Hash::make($input['password']),
30
        ])->save();
31
    }
32
}
33