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 ( 97ac62...e852ca )
by Cees-Jan
11:49 queued 08:28
created

JsonEncodeMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 44
ccs 13
cts 13
cp 1
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 pre() 0 12 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Json;
4
5
use ApiClients\Foundation\Middleware\ErrorTrait;
6
use ApiClients\Foundation\Middleware\MiddlewareInterface;
7
use ApiClients\Foundation\Middleware\PostTrait;
8
use ApiClients\Foundation\Middleware\Priority;
9
use ApiClients\Tools\Json\JsonEncodeService;
10
use Psr\Http\Message\RequestInterface;
11
use React\Promise\CancellablePromiseInterface;
12
use RingCentral\Psr7\BufferStream;
13
use function React\Promise\resolve;
14
15
class JsonEncodeMiddleware implements MiddlewareInterface
16
{
17
    use PostTrait;
18
    use ErrorTrait;
19
20
    /**
21
     * @var JsonEncodeService
22
     */
23
    private $jsonEncodeService;
24
25
    /**
26
     * @param JsonEncodeService $jsonEncodeService
27
     */
28 3
    public function __construct(JsonEncodeService $jsonEncodeService)
29
    {
30 3
        $this->jsonEncodeService = $jsonEncodeService;
31 3
    }
32
33
    /**
34
     * @return int
35
     */
36 1
    public function priority(): int
37
    {
38 1
        return Priority::FIRST;
39
    }
40
41
    /**
42
     * @param RequestInterface $request
43
     * @param array $options
44
     * @return CancellablePromiseInterface
45
     */
46 2
    public function pre(RequestInterface $request, array $options = []): CancellablePromiseInterface
47
    {
48 2
        if (!($request->getBody() instanceof JsonStream)) {
49 1
            return resolve($request);
50
        }
51
52 1
        return $this->jsonEncodeService->encode($request->getBody()->getJson())->then(function ($json) use ($request) {
53 1
            $body = new BufferStream(strlen($json));
54 1
            $body->write($json);
55 1
            return resolve($request->withBody($body)->withAddedHeader('Content-Type', 'application/json'));
56 1
        });
57
    }
58
}
59