SignupController::getSignup()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 18
rs 8.8571
cc 6
eloc 9
nc 4
nop 1
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Http\Controllers;
13
14
use AltThree\Validator\ValidationException;
15
use Gitamin\Commands\Invite\ClaimInviteCommand;
16
use Gitamin\Commands\User\SignupUserCommand;
17
use Gitamin\Exceptions\UserAlreadyBeenTakenException;
18
use Gitamin\Models\Invite;
19
use Illuminate\Foundation\Bus\DispatchesJobs;
20
use Illuminate\Support\Facades\Redirect;
21
use Illuminate\Support\Facades\Request;
22
use Illuminate\Support\Facades\View;
23
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
24
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
25
26
class SignupController extends Controller
27
{
28
    use DispatchesJobs;
29
30
    /**
31
     * Handle the signup with invite.
32
     *
33
     * @param string|null $code
34
     *
35
     * @return \Illuminate\View\View
36
     */
37
    public function getSignup($code = null)
38
    {
39
        if ($code === null) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
40
            //throw new NotFoundHttpException();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
        }
42
43
        $invite = Invite::where('code', '=', $code)->first();
44
45
        if (! $invite || $invite->claimed()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
46
            //throw new BadRequestHttpException();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
        }
48
49
        return View::make('signup')
50
            ->withCode($invite ? $invite->code : '')
51
            ->withPageTitle('signup')
52
            ->withUsername(Request::old('username'))
53
            ->withEmail(Request::old('emai', $invite ? $invite->email : ''));
54
    }
55
56
    /**
57
     * Handle the unsubscribe.
58
     *
59
     * @param string|null $code
60
     *
61
     * @return \Illuminate\View\View
62
     */
63
    public function postSignup($code = null)
0 ignored issues
show
Unused Code introduced by
The parameter $code 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...
64
    {
65
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
        if ($code === null) {
67
            throw new NotFoundHttpException();
68
        }
69
70
        $invite = Invite::where('code', '=', $code)->first();
71
72
        if (!$invite || $invite->claimed()) {
73
            throw new BadRequestHttpException();
74
        }
75
        */
76
        $code = 'gitamin';
77
        try {
78
            $user = $this->dispatch(new SignupUserCommand(
0 ignored issues
show
Unused Code introduced by
$user is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
79
                Request::get('username'),
80
                Request::get('password'),
81
                Request::get('email'),
82
                2
83
            ));
84
        } catch (ValidationException $e) {
85
            return Redirect::route('signup.signup', ['code' => $code])
86
                ->withInput(Request::except('password'))
87
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.signup.failure')))
88
                ->withErrors($e->getMessageBag());
89
        } catch (UserAlreadyBeenTakenException $e) {
90
            return Redirect::route('signup.signup', ['code' => $code])
91
                ->withInput(Request::except('password'))
92
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.signup.failure')))
93
                ->withErrors($e->getMessage());
94
        }
95
96
        //$this->dispatch(new ClaimInviteCommand($invite));
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
98
        return Redirect::route('auth.login')
99
            ->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('gitamin.signup.success')));
100
    }
101
}
102