Completed
Push — master ( e76ca6...6280e1 )
by Milroy
04:47 queued 10s
created

ETag::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sarala\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Http\Request;
9
10
class ETag
11
{
12
    public function handle(Request $request, Closure $next)
13
    {
14
        $response = $next($request);
15
16
        if ($request->isMethod('get')) {
17
            $etag = md5($response->getContent());
18
            $requestEtag = str_replace('"', '', $request->getETags());
19
20
            if ($requestEtag && $requestEtag[0] == $etag) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $requestEtag of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
21
                $response->setNotModified();
22
            }
23
24
            $response->setEtag($etag);
25
        }
26
27
        return $response;
28
    }
29
}
30