Passed
Push — main ( ea0813...90e5be )
by Thierry
08:59 queued 04:05
created

UpdateUserProfileInformation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 9 1
A updateVerifiedUser() 0 9 1
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 UpdateUserProfileInformation 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