Completed
Push — master ( 425779...b6e961 )
by Abdelrahman
08:30
created

NoHttpCache::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Fort\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->header('Pragma', 'no-cache')
0 ignored issues
show
Bug introduced by
The method header() does not exist on Symfony\Component\HttpFoundation\Response. Did you maybe mean sendHeaders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
                 ->header('Expires', 'Sat, 01-Jan-2000 00:00:00 GMT')
36
                 ->header('Cache-Control', 'private, no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
37
38
        return $response;
39
    }
40
}
41