Passed
Push — master ( 4a21ec...0b8f44 )
by Jeremy
02:39 queued 02:02
created

LogActivity::shouldLog()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 5
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace jeremykenedy\LaravelLogger\App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use jeremykenedy\LaravelLogger\App\Http\Traits\ActivityLogger;
8
9
class LogActivity
10
{
11
    use ActivityLogger;
0 ignored issues
show
Bug introduced by
The trait jeremykenedy\LaravelLogg...p\Traits\ActivityLogger requires the property $id which is not provided by jeremykenedy\LaravelLogg...\Middleware\LogActivity.
Loading history...
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
     * @return bool
35
     */
36
    protected function shouldLog($request)
37
    {
38
        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

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