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

RemoveChartsFromHttp2ServerPush::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.243

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 10
cp 0.7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 2
nop 2
crap 3.243
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