Passed
Push — master ( 0a47c1...5b0c2e )
by Mattia
23:08
created

SetCacheHeaders   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 3
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
7
class SetCacheHeaders
8
{
9
    /**
10
     * Add cache related HTTP headers.
11
     *
12
     * @param  \Illuminate\Http\Request  $request
13
     * @param  \Closure  $next
14
     * @return \Symfony\Component\HttpFoundation\Response
15
     *
16
     * @throws \InvalidArgumentException
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        /** @var \Symfony\Component\HttpFoundation\Response $response */
21
        $response = $next($request);
22
23
        if (! $request->isMethodCacheable() || !$response->getContent()) {
24
            return $response;
25
        }
26
27
        $response->setEtag(md5($response->getContent()));
28
        $response->setPublic();
29
        $response->setMaxAge(env('USERDATA_CACHE_TIME'));
0 ignored issues
show
Bug introduced by
env('USERDATA_CACHE_TIME') of type PhpOption\S|PhpOption\T is incompatible with the type integer expected by parameter $value of Symfony\Component\HttpFo...n\Response::setMaxAge(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        $response->setMaxAge(/** @scrutinizer ignore-type */ env('USERDATA_CACHE_TIME'));
Loading history...
30
        $response->isNotModified($request);
31
32
        return $response;
33
    }
34
}
35