NoHttpCache::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Http\Response;
9
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
10
11
class NoHttpCache
12
{
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param \Illuminate\Http\Request $request
17
     * @param \Closure                 $next
18
     *
19
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SymfonyResponse.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
20
     */
21
    public function handle($request, Closure $next)
22
    {
23
        $response = $next($request);
24
25
        // This step is only needed if you are returning
26
        // a view in your Controller or elsewhere, because
27
        // when returning a view `$next($request)` returns
28
        // a View object, not a Response object, so we need
29
        // to wrap the View back in a Response.
30
        if (! $response instanceof SymfonyResponse) {
31
            $response = new Response($response);
32
        }
33
34
        $response->headers->set('Pragma', 'no-cache');
35
        $response->headers->set('Expires', 'Sat, 01-Jan-2000 00:00:00 GMT');
36
        $response->headers->set('Cache-Control', 'private, no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0');
37
38
        return $response;
39
    }
40
}
41