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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A priority() 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
     * @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