Completed
Push — master ( dcb670...d63594 )
by Manuel
03:44
created

RemoveChartsFromHttp2ServerPush   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 32
ccs 9
cts 14
cp 0.6429
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 3
A shouldUseServerPush() 0 4 1
1
<?php
2
3
namespace PiFinder\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class RemoveChartsFromHttp2ServerPush
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return mixed
16
     */
17 1
    public function handle($request, Closure $next)
18
    {
19 1
        $this->response = $next($request);
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
21 1
        if ($this->shouldUseServerPush($request) && ! $request->is('stats')) {
22 1
            app('server-push')->resources = collect(app('server-push')->resources)->reject(function ($resource) {
23 1
                return str_contains($resource['path'], '/js/charts.');
24 1
            })->toArray();
25
        }
26
27 1
        return $this->response;
28
    }
29
30
    /**
31
     * @param Request $request
32
     *
33
     * @return bool
34
     */
35 1
    protected function shouldUseServerPush(Request $request) : bool
36
    {
37 1
        return ! $request->ajax();
38
    }
39
}
40