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 (#2)
by Cees-Jan
22:27 queued 12:24
created

JsonDecodeMiddleware::post()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation\Transport\Middleware;
4
5
use ApiClients\Foundation\Middleware\MiddlewareInterface;
6
use ApiClients\Foundation\Middleware\PreTrait;
7
use ApiClients\Foundation\Transport\JsonStream;
8
use ApiClients\Foundation\Transport\Service\JsonDecodeService as JsonDecodeService;
9
use Psr\Http\Message\ResponseInterface;
10
use React\Promise\CancellablePromiseInterface;
11
use function React\Promise\resolve;
12
use React\Stream\ReadableStreamInterface;
13
14
class JsonDecodeMiddleware implements MiddlewareInterface
15
{
16
    use PreTrait;
17
18
    /**
19
     * @var JsonDecodeService
20
     */
21
    private $jsonDecodeService;
22
23
    /**
24
     * JsonDecode constructor.
25
     * @param JsonDecodeService $jsonDecodeService
26
     */
27
    public function __construct(JsonDecodeService $jsonDecodeService)
28
    {
29
        $this->jsonDecodeService = $jsonDecodeService;
30
    }
31
32
    /**
33
     * @return int
34
     */
35
    public function priority(): int
36
    {
37
        return 1000;
38
    }
39
40
    /**
41
     * @param ResponseInterface $response
42
     * @param array $options
43
     * @return CancellablePromiseInterface
44
     */
45
    public function post(ResponseInterface $response, array $options = []): CancellablePromiseInterface
46
    {
47
        if ($response->getBody() instanceof ReadableStreamInterface) {
48
            return resolve($response);
49
        }
50
51
        return $this->jsonDecodeService->handle((string)$response->getBody())->then(function ($json) use ($response) {
52
            $body = new JsonStream($json);
53
            return resolve($response->withBody($body));
54
        });
55
    }
56
}
57