Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

LogDebugVisits   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 44
ccs 14
cts 15
cp 0.9333
rs 10
c 1
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 32 8
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