LogActivity   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 11
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 3
A shouldLog() 0 13 4
1
<?php
2
3
namespace jeremykenedy\LaravelLogger\App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use jeremykenedy\LaravelLogger\App\Http\Traits\ActivityLogger;
8
9
class LogActivity
10
{
11
    use ActivityLogger;
12
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param Request  $request
17
     * @param \Closure $next
18
     *
19
     * @return mixed
20
     */
21
    public function handle($request, Closure $next, $description = null)
22
    {
23
        if (config('LaravelLogger.loggerMiddlewareEnabled') && $this->shouldLog($request)) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        if (/** @scrutinizer ignore-call */ config('LaravelLogger.loggerMiddlewareEnabled') && $this->shouldLog($request)) {
Loading history...
24
            ActivityLogger::activity($description);
25
        }
26
27
        return $next($request);
28
    }
29
30
    /**
31
     * Determine if the request has a URI that should log.
32
     *
33
     * @param \Illuminate\Http\Request $request
34
     *
35
     * @return bool
36
     */
37
    protected function shouldLog($request)
38
    {
39
        foreach (config('LaravelLogger.loggerMiddlewareExcept', []) as $except) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        foreach (/** @scrutinizer ignore-call */ config('LaravelLogger.loggerMiddlewareExcept', []) as $except) {
Loading history...
40
            if ($except !== '/') {
41
                $except = trim($except, '/');
42
            }
43
44
            if ($request->is($except)) {
45
                return false;
46
            }
47
        }
48
49
        return true;
50
    }
51
}
52