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::priority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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