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

shouldUseServerPush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1.125
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