WizardProfileController::processWizard()   C
last analyzed

Complexity

Conditions 10
Paths 256

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 19
c 1
b 0
f 0
nc 256
nop 2
dl 0
loc 28
rs 6.1333

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
4
namespace App\Http\Controllers\Profile;
5
6
7
use App\Http\Controllers\Controller;
8
use App\Src\UseCases\Domain\Context\Model\Characteristic;
9
use App\Src\UseCases\Domain\Context\Queries\GetAllCharacteristics;
10
use App\Src\UseCases\Domain\Shared\Gateway\AuthGateway;
11
use App\Src\UseCases\Domain\Users\Dto\GetUserRole;
12
use App\Src\UseCases\Domain\Users\Profile\FillWikiUserProfile;
13
use Illuminate\Http\Request;
14
use Illuminate\Support\Facades\Auth;
15
16
/**
17
 * Controller used for filling public profile for the wiki
18
 */
19
class WizardProfileController extends Controller
20
{
21
    public function showWizard()
22
    {
23
        $characteristics = app(GetAllCharacteristics::class)->get();
24
        $user = app(AuthGateway::class)->current()->toArray();
25
        $roles = app(GetUserRole::class)->get()->toArray();
26
27
        return view('users.wizard-profile.wizard', [
28
            'userRoles' => $roles,
29
            'firstname' => $user['firstname'],
30
            'lastname' => $user['lastname'],
31
            'farmingTypeMain' => $characteristics[Characteristic::FARMING_TYPE],
32
            'croppingTypeMain' => $characteristics[Characteristic::CROPPING_SYSTEM],
33
            'email' => $user['email']
34
        ]);
35
    }
36
37
    public function processWizard(Request $request, FillWikiUserProfile $fillWikiUserProfile)
38
    {
39
        $role = $request->input('role') !== null ? $request->input('role') : '';
40
        $firstname = $request->input('firstname') !== null ? $request->input('firstname') : '';
41
        $lastname = $request->input('lastname') !== null ? $request->input('lastname') : '';
42
        $postalCode = $request->input('postal_code') !== null ? $request->input('postal_code') : '';
43
        $email = $request->input('email') !== null ? $request->input('email') : '';
44
        $farmingType = $request->input('farming_type') !== null ? $request->input('farming_type') : [];
45
46
        $fillWikiUserProfile->fill(Auth::user()->uuid, $role, $firstname, $lastname, $email, $postalCode, $farmingType);
47
48
        if(Auth::user()->hasVerifiedEmail()) {
49
            $user = Auth::user();
50
            if ($request->session()->has('wiki_callback')) {
51
                $user->wiki_token = $request->session()->get('wiki_token');
52
                $user->save();
53
                $callback = urldecode($request->session()->get('wiki_callback'));
0 ignored issues
show
Bug introduced by
It seems like $request->session()->get('wiki_callback') can also be of type null; however, parameter $string of urldecode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
                $callback = urldecode(/** @scrutinizer ignore-type */ $request->session()->get('wiki_callback'));
Loading history...
54
                return redirect($callback);
55
            }
56
57
            if($request->session()->has('sso')){
58
                $sso = $request->session()->get('sso');
59
                $sig = $request->session()->get('sig');
60
                return redirect('discourse/sso?sso='.$sso.'&sig='.$sig);
61
            }
62
        }
63
64
        return redirect()->route('verification.notice');
65
    }
66
}
67