Passed
Push — dev6 ( 1762ad...6b002f )
by Ron
08:16
created

LogDebugVisits::handle()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 7

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 8.8333
cc 7
nc 4
nop 2
crap 7
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Arr;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Log;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\Support\Facades\Route;
11
12
class LogDebugVisits
13
{
14
    //  These items should never be logged
15
    protected $ignore = ['_token', 'token'];
16
    //  These items are logged with masked input to show that they did exist during the session
17
    protected $redact = ['password', 'password_confirmation'];
18
19
20
    /**
21
\     * When Debug Logging is one, log every page visit and all $request data
22
     */
23 195
    public function handle(Request $request, Closure $next)
24
    {
25 195
        $user = isset(Auth::user()->user_id) ? Auth::user()->full_name : \Request::ip();
2 ignored issues
show
Bug introduced by
Accessing user_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
26 195
        $requestData = $request->request->all();
27
28 195
        Log::debug('Route '.Route::currentRouteName().' visited by '.$user);
29
30 195
        if(!empty($requestData))
31
        {
32 85
            foreach($this->redact as $i)
33
            {
34 85
                if(Arr::exists($requestData, $i))
35
                {
36 15
                    $requestData[$i] = '[REDACTED]';
37
                }
38
            }
39 85
            foreach($this->ignore as $i)
40
            {
41 85
                if(Arr::exists($requestData, $i))
42
                {
43 4
                    unset($requestData[$i]);
44
                }
45
            }
46 85
            Log::debug('Submitted Data ', $requestData);
47
        }
48
49 195
        return $next($request);
50
    }
51
}
52