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 (#151)
by
unknown
10:09
created

CacheResponse::handle()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 8.6577
c 0
b 0
f 0
cc 6
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
12
class CacheResponse
13
{
14
    /** @var \Spatie\ResponseCache\ResponseCache */
15
    protected $responseCache;
16
17
    public function __construct(ResponseCache $responseCache)
18
    {
19
        $this->responseCache = $responseCache;
20
    }
21
22
    public function handle(Request $request, Closure $next, $lifetimeInMinutes = null): Response
23
    {
24
        if ($this->responseCache->enabled($request)) {
25
            if ($this->responseCache->hasBeenCached($request)) {
26
                event(new ResponseCacheHit($request));
27
28
                $response = $this->responseCache->getCachedResponseFor($request);
29
30
                $pattern = '/<meta name="csrf-token" content="([^"]+)">/';
31
32
                $cachedContent = $response->getContent();
33
34
                if (preg_match($pattern, $cachedContent, $matches)) {
35
36
                    $cachedCsrf = $matches[1];
37
                    $updatedCsrf = csrf_token();
38
39
                    $updatedContent = str_replace($cachedCsrf, $updatedCsrf, $cachedContent);
40
41
                    $response->setContent($updatedContent);
42
43
                }
44
45
                return $response;
46
47
            }
48
        }
49
50
        $response = $next($request);
51
52
        if ($this->responseCache->enabled($request)) {
53
            if ($this->responseCache->shouldCache($request, $response)) {
54
                $this->responseCache->cacheResponse($request, $response, $lifetimeInMinutes);
55
            }
56
        }
57
58
        event(new CacheMissed($request));
59
60
        return $response;
61
    }
62
}
63