Authenticate::terminate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 2
b 1
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Auth;
6
use Closure;
7
use Illuminate\Auth\Middleware\Authenticate as Middleware;
8
use Illuminate\Contracts\Auth\Guard;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\Log;
11
use Illuminate\Support\Facades\Route;
12
13
class Authenticate extends Middleware
14
{
15
    /**
16
     * The Guard implementation.
17
     *
18
     * @var Guard
19
     */
20
    protected $auth;
21
22
    /**
23
     * Create a new filter instance.
24
     *
25
     * @param Guard $auth
26
     *
27
     * @return void
28
     */
29
    public function __construct(Guard $auth)
30
    {
31
        $this->auth = $auth;
32
    }
33
34
    /**
35
     * Get the path the user should be redirected to when they are not authenticated.
36
     *
37
     * @param  \Illuminate\Http\Request  $request
38
     * @return string|null
39
     */
40
    protected function redirectTo($request)
41
    {
42
        if (! $request->expectsJson()) {
43
            return route('login');
44
        }
45
    }
46
47
    /**
48
     * Handle an incoming request.
49
     *
50
     * @param \Illuminate\Http\Request $request
51
     * @param \Closure                 $next
52
     *
53
     * @return mixed
54
     */
55
    public function handle($request, Closure $next)
56
    {
57
        if (! $this->auth->check()) {
58
            return redirect()->to('/login')
59
                ->with('status', 'success')
60
                ->with('message', 'Please login.');
61
        }
62
63
        return $next($request);
64
    }
65
66
    /**
67
     * Log a termination.
68
     * @param \Illuminate\Http\Request $request
69
     * @param $response
70
     *
71
     * @return void
72
     */
73
    public function terminate($request, $response)
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

73
    public function terminate($request, /** @scrutinizer ignore-unused */ $response)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

73
    public function terminate(/** @scrutinizer ignore-unused */ $request, $response)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
        $user = Auth::user();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
76
        $currentRoute = Route::currentRouteName();
0 ignored issues
show
Unused Code introduced by
The assignment to $currentRoute is dead and can be removed.
Loading history...
77
        // Log::info('Authenticate middleware was used: '.$currentRoute.'. ', [$user]);
78
    }
79
}
80