Passed
Push — master ( 1ffd02...b93f0b )
by Bertrand
06:21
created

WizardProfileController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B processWizard() 0 18 8
A showWizard() 0 12 1
1
<?php
2
3
4
namespace App\Http\Controllers\Profile;
5
6
7
use App\Http\Controllers\Controller;
8
use App\Src\UseCases\Domain\Agricultural\Dto\GetFarmingType;
9
use App\Src\UseCases\Domain\Users\Dto\GetUserRole;
10
use App\Src\UseCases\Domain\Users\Profile\FillWikiUserProfile;
11
use App\Src\UseCases\Infra\Gateway\Auth\AuthGateway;
12
use Illuminate\Http\Request;
13
use Illuminate\Support\Facades\Auth;
14
15
class WizardProfileController extends Controller
16
{
17
    public function showWizard()
18
    {
19
        $farmingType = app(GetFarmingType::class)->get();
20
        $user = app(AuthGateway::class)->current()->toArray();
21
        $roles = app(GetUserRole::class)->get()->toArray();
22
        return view('users.wizard-profile.wizard', [
23
            'userRoles' => $roles,
24
            'firstname' => $user['firstname'],
25
            'lastname' => $user['lastname'],
26
            'farmingType' => $farmingType['others'],
27
            'farmingTypeMain' => $farmingType['main'],
28
            'email' => $user['email']
29
        ]);
30
    }
31
32
    public function processWizard(Request $request, FillWikiUserProfile $fillWikiUserProfile)
33
    {
34
        $role = $request->input('role') !== null ? $request->input('role') : '';
35
        $firstname = $request->input('firstname') !== null ? $request->input('firstname') : '';
36
        $lastname = $request->input('lastname') !== null ? $request->input('lastname') : '';
37
        $postalCode = $request->input('postal_code') !== null ? $request->input('postal_code') : '';
38
        $email = $request->input('email') !== null ? $request->input('email') : '';
39
        $farmingType = $request->input('farming_type') !== null ? $request->input('farming_type') : [];
40
41
        $fillWikiUserProfile->fill(Auth::user()->uuid, $role, $firstname, $lastname, $email, $postalCode, $farmingType);
0 ignored issues
show
Bug Best Practice introduced by
The property uuid does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
42
        if(session()->has('wiki_callback')){
43
            $user = Auth::user();
44
            $user->wiki_token = session()->get('wiki_token');
0 ignored issues
show
Bug Best Practice introduced by
The property wiki_token does not exist on App\User. Since you implemented __set, consider adding a @property annotation.
Loading history...
45
            $user->save();
46
            $callback = urldecode(session()->get('wiki_callback'));
47
            return redirect($callback);
48
        }
49
        return redirect(config('neayi.wiki_url'));
50
    }
51
}
52