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 ( 164506...170504 )
by Freek
03:32 queued 02:30
created

ExampleSerializer::buildResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\ResponseCache\Serializer;
4
5
use Illuminate\Http\JsonResponse;
6
use Symfony\Component\HttpFoundation\Response;
7
8
class ExampleSerializer extends DefaultSerializer
9
{
10
    protected function getResponseData(Response $response): array
11
    {
12
        $statusCode = $response->getStatusCode();
13
        $headers = $response->headers;
14
15
        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...
16
            $content = $response->getFile()->getPathname();
17
            $type = self::RESPONSE_TYPE_FILE;
18
19
            return compact('statusCode', 'headers', 'content', 'type');
20
        }
21
22
        // If you return it with JsonResponse, save the content as JSON
23
        $content = $response instanceof JsonResponse
24
            ? $response->getData()
25
            : $response->getContent();
26
27
        $type = self::RESPONSE_TYPE_NORMAL;
28
29
        // Save class name
30
        $class = get_class($response);
31
32
        return compact('statusCode', 'headers', 'content', 'type', 'class');
33
    }
34
35
    protected function buildResponse(array $responseProperties): Response
36
    {
37
        $type = $responseProperties['type'] ?? self::RESPONSE_TYPE_NORMAL;
38
39
        if ($type === self::RESPONSE_TYPE_FILE) {
40
            return new BinaryFileResponse(
41
                $responseProperties['content'],
42
                $responseProperties['statusCode']
43
            );
44
        }
45
46
        $class = $responseProperties['class'];
47
48
        // Restore as saved class
49
        return new $class($responseProperties['content'], $responseProperties['statusCode']);
50
    }
51
}
52