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

CacheAllSuccessfulGetRequests   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 5
dl 0
loc 48
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 6 1
1
<?php
2
3
namespace Spatie\ResponseCache\CacheProfiles;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Http\Request;
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)
51
    {
52
        $contentType = $response->headers->get('Content-Type', '');
53
54
        return Str::startsWith($contentType, 'text');
55
    }
56
}
57