LoginController::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 0
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\Base\app\Http\Controllers\Auth;
4
5
use Backpack\Base\app\Http\Controllers\Controller;
6
use Illuminate\Foundation\Auth\AuthenticatesUsers;
7
use Illuminate\Http\Request;
8
9
class LoginController extends Controller
10
{
11
    protected $data = []; // the information we send to the view
12
13
    /*
14
    |--------------------------------------------------------------------------
15
    | Login Controller
16
    |--------------------------------------------------------------------------
17
    |
18
    | This controller handles authenticating users for the application and
19
    | redirecting them to your home screen. The controller uses a trait
20
    | to conveniently provide its functionality to your applications.
21
    |
22
    */
23
    use AuthenticatesUsers {
24
        logout as defaultLogout;
25
    }
26
27
    /**
28
     * Create a new controller instance.
29
     *
30
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
31
     */
32
    public function __construct()
33
    {
34
        $guard = backpack_guard_name();
35
36
        $this->middleware("guest:$guard", ['except' => 'logout']);
37
38
        // ----------------------------------
39
        // Use the admin prefix in all routes
40
        // ----------------------------------
41
42
        // If not logged in redirect here.
43
        $this->loginPath = property_exists($this, 'loginPath') ? $this->loginPath
0 ignored issues
show
Bug introduced by
The property loginPath does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
            : backpack_url('login');
45
46
        // Redirect here after successful login.
47
        $this->redirectTo = property_exists($this, 'redirectTo') ? $this->redirectTo
0 ignored issues
show
Bug introduced by
The property redirectTo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
            : backpack_url('dashboard');
49
50
        // Redirect here after logout.
51
        $this->redirectAfterLogout = property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout
0 ignored issues
show
Bug introduced by
The property redirectAfterLogout does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
            : backpack_url();
53
    }
54
55
    /**
56
     * Return custom username for authentication.
57
     *
58
     * @return string
59
     */
60
    public function username()
61
    {
62
        return backpack_authentication_column();
63
    }
64
65
    /**
66
     * Log the user out and redirect him to specific location.
67
     *
68
     * @param \Illuminate\Http\Request $request
69
     *
70
     * @return \Illuminate\Http\Response
71
     */
72
    public function logout(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
73
    {
74
        // Do the default logout procedure
75
        $this->guard()->logout();
76
77
        // And redirect to custom location
78
        return redirect($this->redirectAfterLogout);
79
    }
80
81
    /**
82
     * Get the guard to be used during logout.
83
     *
84
     * @return \Illuminate\Contracts\Auth\StatefulGuard
85
     */
86
    protected function guard()
87
    {
88
        return backpack_auth();
89
    }
90
91
    // -------------------------------------------------------
92
    // Laravel overwrites for loading backpack views
93
    // -------------------------------------------------------
94
95
    /**
96
     * Show the application login form.
97
     *
98
     * @return \Illuminate\Http\Response
99
     */
100
    public function showLoginForm()
101
    {
102
        $this->data['title'] = trans('backpack::base.login'); // set the page title
103
        $this->data['username'] = $this->username();
104
105
        return view('backpack::auth.login', $this->data);
106
    }
107
}
108