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

UpdateUserProfile::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace App\Actions;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Facades\Validator;
7
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
8
9
class UpdateUserProfile implements UpdatesUserProfileInformation
10
{
11
    /**
12
     * Validate and update the given user's profile information.
13
     *
14
     * @param  mixed  $user
15
     * @param  array  $input
16
     * @return void
17
     */
18
    public function update($user, array $input)
19
    {
20
        Validator::make($input, [
21
            'name' => ['required', 'string', 'max:255'],
22
            'city' => ['string', 'max:100'],
23
            'country_code' => ['string', 'size:2'],
24
        ])->validateWithBag('profile');
25
26
        $user->forceFill(Arr::only($input, ['name', 'city', 'country_code']))->save();
27
    }
28
29
    /**
30
     * Update the given verified user's profile information.
31
     *
32
     * @param  mixed  $user
33
     * @param  array  $input
34
     * @return void
35
     */
36
    protected function updateVerifiedUser($user, array $input)
37
    {
38
        $user->forceFill([
39
            'name' => $input['name'],
40
            'email' => $input['email'],
41
            'email_verified_at' => null,
42
        ])->save();
43
44
        $user->sendEmailVerificationNotification();
45
    }
46
}
47