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
13:42 queued 03:45
created

JsonDecodeMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A post() 0 11 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
     * @param ResponseInterface $response
34
     * @param array $options
35
     * @return CancellablePromiseInterface
36
     */
37
    public function post(ResponseInterface $response, array $options = []): CancellablePromiseInterface
38
    {
39
        if ($response->getBody() instanceof ReadableStreamInterface) {
40
            return resolve($response);
41
        }
42
43
        return $this->jsonDecodeService->handle((string)$response->getBody())->then(function ($json) use ($response) {
44
            $body = new JsonStream($json);
45
            return resolve($response->withBody($body));
46
        });
47
    }
48
}
49