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.

CacheAllSuccessfulGetRequests   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 5
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldCacheRequest() 0 12 3
A shouldCacheResponse() 0 12 3
A hasCacheableResponseCode() 0 12 3
A hasCacheableContentType() 0 14 3
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