CheckCurrentUser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 7
c 3
b 1
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 2
A terminate() 0 5 1
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Auth;
6
use Closure;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Log;
9
use Illuminate\Support\Facades\Route;
10
11
class CheckCurrentUser
12
{
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param \Illuminate\Http\Request $request
17
     * @param \Closure                 $next
18
     *
19
     * @return mixed
20
     */
21
    public function handle($request, Closure $next)
22
    {
23
        if (! $request->user()) {
24
            abort(403, 'Unauthorized action.');
25
        }
26
27
        return $next($request);
28
    }
29
30
    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

30
    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

30
    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...
31
    {
32
        $user = Auth::user();
33
        $currentRoute = Route::currentRouteName();
34
        Log::info('CheckCurrentUser middlware was used: '.$currentRoute.'. ', [$user]);
35
    }
36
}
37