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.

hasCacheableResponseCode()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Spatie\ResponseCache\CacheProfiles;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Str;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class CacheAllSuccessfulGetRequests extends BaseCacheProfile
10
{
11
    public function shouldCacheRequest(Request $request): bool
12
    {
13
        if ($request->ajax()) {
14
            return false;
15
        }
16
17
        if ($this->isRunningInConsole()) {
18
            return false;
19
        }
20
21
        return $request->isMethod('get');
22
    }
23
24
    public function shouldCacheResponse(Response $response): bool
25
    {
26
        if (! $this->hasCacheableResponseCode($response)) {
27
            return false;
28
        }
29
30
        if (! $this->hasCacheableContentType($response)) {
31
            return false;
32
        }
33
34
        return true;
35
    }
36
37
    public function hasCacheableResponseCode(Response $response): bool
38
    {
39
        if ($response->isSuccessful()) {
40
            return true;
41
        }
42
43
        if ($response->isRedirection()) {
44
            return true;
45
        }
46
47
        return false;
48
    }
49
50
    public function hasCacheableContentType(Response $response): bool
51
    {
52
        $contentType = $response->headers->get('Content-Type', '');
53
54
        if (Str::startsWith($contentType, 'text/')) {
55
            return true;
56
        }
57
58
        if (Str::contains($contentType, ['/json', '+json'])) {
59
            return true;
60
        }
61
62
        return false;
63
    }
64
}
65