GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#180)
by Rias
02:53
created

CacheResponse::handle()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.1315
c 0
b 0
f 0
cc 8
nc 8
nop 3
1
<?php
2
3
namespace Spatie\ResponseCache\Middlewares;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Spatie\ResponseCache\ResponseCache;
8
use Spatie\ResponseCache\Events\CacheMissed;
9
use Symfony\Component\HttpFoundation\Response;
10
use Spatie\ResponseCache\Events\ResponseCacheHit;
11
use Spatie\ResponseCache\CacheProfiles\CacheProfile;
12
13
class CacheResponse
14
{
15
    /** @var \Spatie\ResponseCache\ResponseCache */
16
    protected $responseCache;
17
18
    /** @var \Spatie\ResponseCache\CacheProfiles\CacheProfile */
19
    protected $cacheProfile;
20
21
    public function __construct(ResponseCache $responseCache, CacheProfile $cacheProfile)
22
    {
23
        $this->responseCache = $responseCache;
24
        $this->cacheProfile = $cacheProfile;
25
    }
26
27
    public function handle(Request $request, Closure $next, $lifetimeInSeconds = null): Response
28
    {
29
        if ($this->responseCache->enabled($request)) {
30
            if ($this->responseCache->hasBeenCached($request)) {
31
                event(new ResponseCacheHit($request));
32
33
                $response = $this->responseCache->getCachedResponseFor($request);
34
35
                if ($response->getContent()) {
36
                    foreach (config('responsecache.replacers', []) as $replacerClass) {
37
                        $replacer = resolve($replacerClass);
38
                        if ($replacer instanceof \Spatie\ResponseCache\Replacers\Replacer) {
39
                            $cachedValue = $this->responseCache->getCachedKeyFor($request, $replacer->searchFor());
40
                            $response->setContent(str_replace($cachedValue, $replacer->replaceBy(), $response->getContent()));
41
                        }
42
                    }
43
                }
44
45
                return $response;
46
            }
47
        }
48
49
        $response = $next($request);
50
51
        if ($this->responseCache->enabled($request)) {
52
            if ($this->responseCache->shouldCache($request, $response)) {
53
                $this->responseCache->cacheResponse($request, $response, $lifetimeInSeconds);
54
            }
55
        }
56
57
        event(new CacheMissed($request));
58
59
        return $response;
60
    }
61
}
62