Completed
Push — develop ( d878ad...d28e4b )
by Abdelrahman
05:14
created

AccountSettingsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 58
rs 10
c 3
b 0
f 0
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A edit() 0 14 1
A update() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Http\Controllers\Tenantarea;
6
7
use Illuminate\Http\Request;
8
use Cortex\Fort\Http\Requests\Tenantarea\AccountSettingsRequest;
9
use Cortex\Foundation\Http\Controllers\AuthenticatedController;
10
11
class AccountSettingsController extends AuthenticatedController
12
{
13
    /**
14
     * Show the account update form.
15
     *
16
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
17
     */
18
    public function index()
19
    {
20
        return intend([
21
            'url' => route('tenantarea.account.settings'),
22
        ]);
23
    }
24
25
    /**
26
     * Show the account update form.
27
     *
28
     * @param \Illuminate\Http\Request $request
29
     *
30
     * @return \Illuminate\View\View
31
     */
32
    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...
33
    {
34
        $countries = collect(countries())->map(function ($country, $code) {
35
            return [
36
                'id' => $code,
37
                'text' => $country['name'],
38
                'emoji' => $country['emoji'],
39
            ];
40
        })->values();
41
        $languages = collect(languages())->pluck('name', 'iso_639_1');
42
        $genders = ['m' => trans('cortex/fort::common.male'), 'f' => trans('cortex/fort::common.female')];
43
44
        return view('cortex/fort::tenantarea.pages.account-settings', compact('countries', 'languages', 'genders'));
45
    }
46
47
    /**
48
     * Process the account update form.
49
     *
50
     * @param \Cortex\Fort\Http\Requests\Tenantarea\AccountSettingsRequest $request
51
     *
52
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
53
     */
54
    public function update(AccountSettingsRequest $request)
55
    {
56
        $data = $request->validated();
57
        $currentUser = $request->user($this->getGuard());
58
59
        // Update profile
60
        $currentUser->fill($data)->save();
61
62
        return intend([
63
            'back' => true,
64
            'with' => ['success' => trans('cortex/fort::messages.account.updated_account')]
65
                      + (isset($data['two_factor']) ? ['warning' => trans('cortex/fort::messages.verification.twofactor.phone.auto_disabled')] : []),
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 149 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
66
        ]);
67
    }
68
}
69