Passed
Push — dev5 ( 8481ee...a622eb )
by Ron
03:52 queued 01:34
created

LogDebugVisits::handle()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 32
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8.0189

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 14
nc 5
nop 2
dl 0
loc 32
ccs 14
cts 15
cp 0.9333
crap 8.0189
rs 8.4444
c 1
b 0
f 0
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Log;
8
use Illuminate\Support\Facades\Auth;
9
use Illuminate\Support\Facades\Route;
10
11
class LogDebugVisits
12
{
13
    protected $ignore = ['_token', 'token'];
14
    protected $redact = ['password', 'password_confirmation', 'oldPass', 'newPass', 'newPass_confirmation'];
15
16
    /**
17
     * Handle an incoming request.
18
     *
19
     * @param  \Illuminate\Http\Request  $request
20
     * @param  \Closure  $next
21
     * @return mixed
22
     */
23 700
    public function handle($request, Closure $next)
24
    {
25 700
        if(config('logging.channels.daily.level') === 'debug')
26
        {
27 700
            $user = isset(Auth::user()->user_id) ? Auth::user()->full_name : \Request::ip();
28 700
            $requestData = $request->request->all();
29
30 700
            Log::debug('Route '.Route::currentRouteName().' visited by '.$user);
31
32 700
            if(!empty($requestData))
33
            {
34 328
                foreach($this->redact as $i)
35
                {
36 328
                    if(Arr::exists($requestData, $i))
37
                    {
38 44
                        $requestData[$i] = '[REDACTED]';
39
                    }
40
                }
41 328
                foreach($this->ignore as $i)
42
                {
43 328
                    if(Arr::exists($requestData, $i))
44
                    {
45 8
                        unset($requestData[$i]);
46
                    }
47
                }
48 328
                Log::debug('Submitted Data ', $requestData);
49
            }
50
51 700
            return $next($request);
52
        }
53
54
        return $next($request);
55
    }
56
}
57