AuthController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 97
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A login() 0 4 1
A authenticate() 0 19 2
A logout() 0 6 1
A redirectPath() 0 9 3
A loginPath() 0 4 2
1
<?php namespace WITR\Http\Controllers\Auth;
2
3
use WITR\Http\Controllers\Controller;
4
use Illuminate\Contracts\Auth\Guard;
5
use Illuminate\Contracts\Auth\Registrar;
6
use Illuminate\Http\Request;
7
8
class AuthController extends Controller {
9
10
	/**
11
	 * The Guard implementation.
12
	 *
13
	 * @var Guard
14
	 */
15
	protected $auth;
16
17
	/**
18
	 * Create a new authentication controller instance.
19
	 *
20
	 * @param  \Illuminate\Contracts\Auth\Guard  $auth
21
	 * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
0 ignored issues
show
Bug introduced by
There is no parameter named $registrar. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
22
	 * @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...
23
	 */
24
	public function __construct(Guard $auth)
25
	{
26
		$this->auth = $auth;
27
28
		$this->middleware('guest', ['except' => 'logout']);
29
	}
30
31
	/**
32
	 * Show the application login form.
33
	 *
34
	 * @return \Illuminate\Http\Response
35
	 */
36
	public function login()
37
	{
38
		return view('auth.login');
39
	}
40
41
	/**
42
	 * Handle a login request to the application.
43
	 *
44
	 * @param  \Illuminate\Http\Request  $request
45
	 * @return \Illuminate\Http\Response
46
	 */
47
	public function authenticate(Request $request)
48
	{
49
		$this->validate($request, [
50
			'email' => 'required', 'password' => 'required',
51
		]);
52
53
		$credentials = $request->only('email', 'password');
54
55
		if ($this->auth->attempt($credentials, $request->has('remember')))
56
		{
57
			return redirect()->intended($this->redirectPath());
58
		}
59
60
		return redirect($this->loginPath())
61
					->withInput($request->only('email'))
62
					->withErrors([
63
						'email' => 'These credentials do not match our records.',
64
					]);
65
	}
66
67
	/**
68
	 * Log the user out of the application.
69
	 *
70
	 * @return \Illuminate\Http\Response
71
	 */
72
	public function logout()
73
	{
74
		$this->auth->logout();
75
76
		return redirect('/');
77
	}
78
79
	/**
80
	 * Get the post register / login redirect path.
81
	 *
82
	 * @return string
83
	 */
84
	public function redirectPath()
85
	{
86
		if (property_exists($this, 'redirectPath'))
87
		{
88
			return $this->redirectPath;
0 ignored issues
show
Bug introduced by
The property redirectPath 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...
89
		}
90
91
		return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
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...
92
	}
93
94
	/**
95
	 * Get the path to the login route.
96
	 *
97
	 * @return string
98
	 */
99
	public function loginPath()
100
	{
101
		return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login';
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...
102
	}
103
104
}
105