AccountSettingsController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 70
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
A edit() 0 14 1
A update() 0 28 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Controllers\Frontarea;
6
7
use Illuminate\Http\Request;
8
use Cortex\Auth\Http\Requests\Frontarea\AccountSettingsRequest;
9
use Cortex\Foundation\Http\Controllers\AuthenticatedController;
10
11
class AccountSettingsController extends AuthenticatedController
12
{
13
    /**
14
     * Redirect to account settings..
15
     *
16
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
17
     */
18
    public function index()
19
    {
20
        return view('cortex/auth::frontarea.pages.account-index');
21
    }
22
23
    /**
24
     * Edit account settings.
25
     *
26
     * @param \Illuminate\Http\Request $request
27
     *
28
     * @return \Illuminate\View\View
29
     */
30
    public function edit(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        $countries = collect(countries())->map(function ($country, $code) {
33
            return [
34
                'id' => $code,
35
                'text' => $country['name'],
36
                'emoji' => $country['emoji'],
37
            ];
38
        })->values();
39
        $languages = collect(languages())->pluck('name', 'iso_639_1');
40
        $genders = ['male' => trans('cortex/auth::common.male'), 'female' => trans('cortex/auth::common.female')];
41
42
        return view('cortex/auth::frontarea.pages.account-settings', compact('countries', 'languages', 'genders'));
43
    }
44
45
    /**
46
     * Update account settings.
47
     *
48
     * @param \Cortex\Auth\Http\Requests\Frontarea\AccountSettingsRequest $request
49
     *
50
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
51
     */
52
    public function update(AccountSettingsRequest $request)
53
    {
54
        $data = $request->validated();
55
        $currentUser = $request->user($this->getGuard());
56
57
        ! $request->hasFile('profile_picture')
58
        || $currentUser->addMediaFromRequest('profile_picture')
59
                 ->sanitizingFileName(function ($fileName) {
60
                     return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION);
61
                 })
62
                 ->toMediaCollection('profile_picture', config('cortex.foundation.media.disk'));
63
64
        ! $request->hasFile('cover_photo')
65
        || $currentUser->addMediaFromRequest('cover_photo')
66
                 ->sanitizingFileName(function ($fileName) {
67
                     return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION);
68
                 })
69
                 ->toMediaCollection('cover_photo', config('cortex.foundation.media.disk'));
70
71
        // Update profile
72
        $currentUser->fill($data)->save();
73
74
        return intend([
75
            'back' => true,
76
            'with' => ['success' => trans('cortex/auth::messages.account.updated_account')]
77
                      + (isset($data['two_factor']) ? ['warning' => trans('cortex/auth::messages.verification.twofactor.phone.auto_disabled')] : []),
78
        ]);
79
    }
80
}
81