Completed
Push — master ( 7197d7...a98d7a )
by Andrii
12:24
created

FatResponse::getContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace hiapi\Core\Http\Psr7\Response;
4
5
use Laminas\Diactoros\Response;
6
use Lcobucci\ContentNegotiation\UnformattedResponse;
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
10
class FatResponse
11
{
12
    public const REQUEST_ATTRIBUTE = 'request';
13
14
    public static function create($content, RequestInterface $request = null): ResponseInterface
15
    {
16
        if ($request === null) {
17
            return new UnformattedResponse(new Response(), $content);
18
        }
19
20
        return new UnformattedResponse(new Response(), $content, [
21
            self::REQUEST_ATTRIBUTE => $request,
22
        ]);
23
    }
24
25
    public static function getRequest(ResponseInterface $response): ?RequestInterface
26
    {
27
        if (!$response instanceof UnformattedResponse) {
0 ignored issues
show
Bug introduced by
The class Lcobucci\ContentNegotiation\UnformattedResponse 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...
28
            return null;
29
        }
30
        $request = $response->getAttributes()[self::REQUEST_ATTRIBUTE] ?? null;
31
32
        return $request instanceof RequestInterface ? $request : null;
33
    }
34
35
    public static function getContent(ResponseInterface $response)
36
    {
37
        return $response instanceof UnformattedResponse ? $response->getUnformattedContent() : null;
0 ignored issues
show
Bug introduced by
The class Lcobucci\ContentNegotiation\UnformattedResponse 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...
38
    }
39
}
40