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
Push — master ( 02f07d...0e7d0b )
by Freek
01:47
created

ResponseCache::cacheResponse()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 2
nop 3
1
<?php
2
3
namespace Spatie\ResponseCache;
4
5
use Illuminate\Http\Request;
6
use Spatie\ResponseCache\Hasher\DefaultHasher;
7
use Spatie\ResponseCache\Hasher\RequestHasher;
8
use Symfony\Component\HttpFoundation\Response;
9
use Spatie\ResponseCache\CacheProfiles\CacheProfile;
10
11
class ResponseCache
12
{
13
    /** @var \Spatie\ResponseCache\ResponseCache */
14
    protected $cache;
15
16
    /** @var RequestHasher */
17
    protected $hasher;
18
19
    /** @var \Spatie\ResponseCache\CacheProfiles\CacheProfile */
20
    protected $cacheProfile;
21
22
    public function __construct(ResponseCacheRepository $cache, RequestHasher $hasher, CacheProfile $cacheProfile)
23
    {
24
        $this->cache = $cache;
25
        $this->hasher = $hasher;
26
        $this->cacheProfile = $cacheProfile;
27
    }
28
29
    public function enabled(Request $request): bool
30
    {
31
        return $this->cacheProfile->enabled($request);
32
    }
33
34
    public function shouldCache(Request $request, Response $response): bool
35
    {
36
        if ($request->attributes->has('responsecache.doNotCache')) {
37
            return false;
38
        }
39
40
        if (! $this->cacheProfile->shouldCacheRequest($request)) {
41
            return false;
42
        }
43
44
        return $this->cacheProfile->shouldCacheResponse($response);
45
    }
46
47
    public function cacheResponse(Request $request, Response $response, $lifetimeInSeconds = null): Response
48
    {
49
        if (config('responsecache.add_cache_time_header')) {
50
            $response = $this->addCachedHeader($response);
51
        }
52
53
        $lifetimeInSeconds = $lifetimeInSeconds
54
            ? (int)$lifetimeInSeconds
55
            : $this->cacheProfile->cacheRequestUntil($request);
56
57
        $this->cache->put(
58
            $this->hasher->getHashFor($request),
59
            $response,
60
            $lifetimeInSeconds,
61
        );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
62
63
        return $response;
64
    }
65
66
    public function hasBeenCached(Request $request): bool
67
    {
68
        return config('responsecache.enabled')
69
            ? $this->cache->has($this->hasher->getHashFor($request))
70
            : false;
71
    }
72
73
    public function getCachedResponseFor(Request $request): Response
74
    {
75
        return $this->cache->get($this->hasher->getHashFor($request));
76
    }
77
78
    public function clear()
79
    {
80
        $this->cache->clear();
81
    }
82
83
    protected function addCachedHeader(Response $response): Response
84
    {
85
        $clonedResponse = clone $response;
86
87
        $clonedResponse->headers->set('laravel-responsecache', 'cached on '.date('Y-m-d H:i:s'));
88
89
        return $clonedResponse;
90
    }
91
92
    /**
93
     * @param string|array $uris
94
     *
95
     * @return \Spatie\ResponseCache\ResponseCache
96
     */
97
    public function forget($uris): self
98
    {
99
        $uris = is_array($uris) ? $uris : func_get_args();
100
101
        collect($uris)->each(function ($uri) {
102
            $request = Request::create(url($uri));
103
            $hash = $this->hasher->getHashFor($request);
104
105
            if ($this->cache->has($hash)) {
106
                $this->cache->forget($hash);
107
            }
108
        });
109
110
        return $this;
111
    }
112
}
113