Completed
Push — master ( cba711...9d321b )
by Phecho
06:37 queued 03:17
created

SignupController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getSignup() 0 17 6
B postSignup() 0 42 2
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\Commands\ProjectNamespace\AddProjectNamespaceCommand;
18
use Gitamin\Models\Invite;
19
use GrahamCampbell\Binput\Facades\Binput;
20
use Illuminate\Foundation\Bus\DispatchesJobs;
21
use Illuminate\Routing\Controller;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Gitamin\Http\Controllers\Controller.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
22
use Illuminate\Support\Facades\Redirect;
23
use Illuminate\Support\Facades\View;
24
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
25
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
26
27
class SignupController extends Controller
28
{
29
    use DispatchesJobs;
30
31
    /**
32
     * Handle the signup with invite.
33
     *
34
     * @param string|null $code
35
     *
36
     * @return \Illuminate\View\View
37
     */
38
    public function getSignup($code = null)
39
    {
40
        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...
41
            //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...
42
        }
43
44
        $invite = Invite::where('code', '=', $code)->first();
45
46
        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...
47
            //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...
48
        }
49
50
        return View::make('signup')
51
            ->withCode($invite ? $invite->code : '')
52
            ->withUsername(Binput::old('username'))
53
            ->withEmail(Binput::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)
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
77
        try {
78
            $user = $this->dispatch(new SignupUserCommand(
79
                Binput::get('username'),
80
                Binput::get('password'),
81
                Binput::get('email'),
82
                2
83
            ));
84
            $namespaceData = [
85
                'name' => $user->username,
86
                'path' => $user->username,
87
                'owner_id' => $user->id,
88
                'description' => '',
89
                'type' => 'user',
90
            ];
91
            $this->dispatchFromArray(AddProjectNamespaceCommand::class, $namespaceData);
92
93
        } catch (ValidationException $e) {
94
            return Redirect::route('auth.signup', ['code' => $code])
95
                ->withInput(Binput::except('password'))
96
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.signup.failure')))
97
                ->withErrors($e->getMessageBag());
98
        }
99
100
        //$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...
101
102
        return Redirect::route('auth.login')
103
            ->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('gitamin.signup.success')));
104
    }
105
}
106