Completed
Push — master ( 386d91...b7e3b8 )
by Jasper
07:38
created

CacheMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Swis\LaravelStaticRequestCache\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Swis\LaravelStaticRequestCache\StaticRequestCache;
8
use Symfony\Component\HttpFoundation\Response;
9
10
class CacheMiddleware
11
{
12
    /**
13
     * @var \Swis\LaravelStaticRequestCache\StaticRequestCache
14
     */
15
    protected $staticRequestCache;
16
17
    /**
18
     * @param \Swis\LaravelStaticRequestCache\StaticRequestCache $staticRequestCache
19
     */
20 15
    public function __construct(StaticRequestCache $staticRequestCache)
21
    {
22 15
        $this->staticRequestCache = $staticRequestCache;
23 15
    }
24
25
    /**
26
     * Handle an incoming request.
27
     *
28
     * @param  Request $request
29
     * @param  \Closure $next
30
     * @return mixed
31
     */
32 5
    public function handle($request, Closure $next)
33
    {
34 5
        return $next($request);
35
    }
36
37
    /**
38
     * @param \Illuminate\Http\Request                   $request
39
     * @param \Symfony\Component\HttpFoundation\Response $response
40
     */
41 10
    public function terminate(Request $request, Response $response)
42
    {
43 10
        if ($this->staticRequestCache->shouldStoreResponse($request, $response)) {
44 5
            $this->staticRequestCache->store($request, $response);
45
        }
46 10
    }
47
}
48