Completed
Push — master ( 248e12...0fb364 )
by ARCANEDEV
03:19
created

AuthController::getConfirm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.4286
cc 2
eloc 7
nc 2
nop 1
crap 6
1
<?php namespace Arcanesoft\Auth\Http\Controllers\Front;
2
3
use Arcanesoft\Auth\Bases\Controller;
4
use Arcanesoft\Auth\Http\Requests\Front\RegisterUserRequest;
5
use Arcanesoft\Auth\Models\User;
6
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
7
use Illuminate\Foundation\Auth\ThrottlesLogins;
8
9
/**
10
 * Class     AuthController
11
 *
12
 * @package  Arcanesoft\Auth\Http\Controllers\Front
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class AuthController extends Controller
16
{
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Registration & Login Controller Trait
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    use AuthenticatesAndRegistersUsers, ThrottlesLogins;
22
23
    /* ------------------------------------------------------------------------------------------------
24
     |  Properties
25
     | ------------------------------------------------------------------------------------------------
26
     */
27
    protected $redirectPath        = '/';
28
    protected $redirectTo          = '/';
29
    protected $redirectAfterLogout = '/';
30
31
    /* ------------------------------------------------------------------------------------------------
32
     |  Constructor
33
     | ------------------------------------------------------------------------------------------------
34
     */
35
    /**
36
     * Create a new authentication controller instance.
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
42
        $this->middleware('guest', [
43
            'except' => ['getLogout', 'getConfirm']
44
        ]);
45
    }
46
47
    /* ------------------------------------------------------------------------------------------------
48
     |  Main Functions
49
     | ------------------------------------------------------------------------------------------------
50
     */
51
    /**
52
     * Show the application login form.
53
     *
54
     * @return \Illuminate\Http\Response
55
     */
56
    public function getLogin()
57
    {
58
        return view('auth::public.login');
59
    }
60
61
    /**
62
     * Show the application registration form.
63
     *
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function getRegister()
67
    {
68
        return view('auth::public.register');
69
    }
70
71
    /**
72
     * Handle a registration request for the application.
73
     *
74
     * @param  RegisterUserRequest  $request
75
     *
76
     * @return \Illuminate\Http\Response
77
     */
78
    public function postRegister(RegisterUserRequest $request)
79
    {
80
        $this->createMember($request);
81
82
        return redirect($this->redirectPath());
83
    }
84
85
    /**
86
     * Confirm the member account.
87
     *
88
     * @param  string  $code
89
     *
90
     * @return \Illuminate\Http\Response
91
     */
92
    public function getConfirm($code)
93
    {
94
        $member = (new User)->confirm($code);
95
96
        if ( ! $member->isConfirmed()) {
97
            return '404';
0 ignored issues
show
Bug Best Practice introduced by
The return type of return '404'; (string) is incompatible with the return type documented by Arcanesoft\Auth\Http\Con...hController::getConfirm of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
98
        }
99
100
        return redirect()
101
            ->route('auth::profile.index')
102
            ->with('success', 'You\'re account is confirmed !');
103
    }
104
105
    /* ------------------------------------------------------------------------------------------------
106
     |  Other Functions
107
     | ------------------------------------------------------------------------------------------------
108
     */
109
    /**
110
     * Create a member account.
111
     *
112
     * @param  RegisterUserRequest  $request
113
     *
114
     * @return bool
115
     */
116
    private function createMember(RegisterUserRequest $request)
117
    {
118
        $user = new User($request->all());
119
120
        $user->is_active = true;
121
122
        return $user->save();
123
    }
124
}
125