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 (#244)
by
unknown
01:11
created

ExampleSerializer::getResponseData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Spatie\ResponseCache\Serializer;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use Spatie\ResponseCache\Serializer\DefaultSerializer;
7
use Illuminate\Http\JsonResponse;
8
9
class ExampleSerializer extends DefaultSerializer
10
{
11
    protected function getResponseData(Response $response): array
12
    {
13
        $statusCode = $response->getStatusCode();
14
        $headers = $response->headers;
15
16
        if ($response instanceof BinaryFileResponse) {
0 ignored issues
show
Bug introduced by
The class Spatie\ResponseCache\Serializer\BinaryFileResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
17
            $content = $response->getFile()->getPathname();
18
            $type = self::RESPONSE_TYPE_FILE;
19
20
            return compact('statusCode', 'headers', 'content', 'type');
21
        }
22
23
        // If you return it with JsonResponse, save the content as JSON
24
        $content = $response instanceof JsonResponse
25
            ? $response->getData()
26
            : $response->getContent();
27
28
        $type = self::RESPONSE_TYPE_NORMAL;
29
30
        // Save class name
31
        $class = get_class($response);
32
33
        return compact('statusCode', 'headers', 'content', 'type', 'class');
34
    }
35
36
    protected function buildResponse(array $responseProperties): Response
37
    {
38
        $type = $responseProperties['type'] ?? self::RESPONSE_TYPE_NORMAL;
39
40
        if ($type === self::RESPONSE_TYPE_FILE) {
41
            return new BinaryFileResponse(
42
                $responseProperties['content'],
43
                $responseProperties['statusCode']
44
            );
45
        }
46
47
        $class = $responseProperties['class'];
48
49
        // Restore as saved class
50
        return new $class($responseProperties['content'], $responseProperties['statusCode']);
51
    }
52
}
53