Passed
Push — dev5 ( 6692a0...1b6b88 )
by Ron
08:06
created

LogDebugVisits::handle()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 32
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 8.1515

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 14
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 32
ccs 13
cts 15
cp 0.8667
crap 8.1515
rs 8.4444
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'];
14
    protected $redact = ['password', 'password_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($requestData)
0 ignored issues
show
Bug Best Practice introduced by
The expression $requestData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
33
            {
34 330
                foreach($this->redact as $i)
35
                {
36 330
                    if(Arr::exists($requestData, $i))
37
                    {
38 30
                        $requestData[$i] = '[REDACTED]';
39
                    }
40
                }
41 330
                foreach($this->ignore as $i)
42
                {
43 330
                    if(Arr::exists($requestData, $i))
44
                    {
45
                        unset($requestData[$i]);
46
                    }
47
                }
48 330
                Log::debug('Submitted Data ', $requestData);
49
            }
50
51 700
            return $next($request);
52
        }
53
54
        return $next($request);
55
    }
56
}
57