Authenticate::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 2
eloc 5
c 3
b 1
f 0
nc 2
nop 3
dl 0
loc 19
rs 10
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Auth;
6
use Closure;
7
use Illuminate\Contracts\Auth\Guard;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Log;
10
use Illuminate\Support\Facades\Route;
11
12
class Authenticate
13
{
14
    /**
15
     * The Guard implementation.
16
     *
17
     * @var Guard
18
     */
19
    protected $auth;
20
21
    /**
22
     * Create a new filter instance.
23
     *
24
     * @param Guard $auth
25
     *
26
     * @return void
27
     */
28
    public function __construct(Guard $auth)
29
    {
30
        $this->auth = $auth;
31
    }
32
33
    /**
34
     * Handle an incoming request.
35
     *
36
     * @param \Illuminate\Http\Request $request
37
     * @param \Closure                 $next
38
     * @param $role
39
     *
40
     * @return mixed
41
     */
42
    public function handle($request, Closure $next, $role)
0 ignored issues
show
Unused Code introduced by
The parameter $role 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

42
    public function handle($request, Closure $next, /** @scrutinizer ignore-unused */ $role)

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...
43
    {
44
        if (!$this->auth->check()) {
45
            return redirect()->to('/login')
46
                ->with('status', 'success')
47
                ->with('message', 'Please login.');
48
        }
49
        ////////////////
50
        // if($role == 'all')
51
        // {
52
        //     return $next($request);
53
        // }
54
55
        // if( $this->auth->guest() || !$this->auth->user()->hasRole($role))
56
        // {
57
        //     abort(403);
58
        // }
59
        ////////////////
60
        return $next($request);
61
    }
62
63
    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

63
    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

63
    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...
64
    {
65
        $user = Auth::user();
66
        $currentRoute = Route::currentRouteName();
67
        Log::info('Authenticate middlware was used: '.$currentRoute.'. ', [$user]);
68
    }
69
}
70