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 ( 98e8f7...48bfbc )
by Cees-Jan
11s
created

JsonEncodeMiddleware::pre()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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