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 ( 4c3a00...a7513d )
by Cees-Jan
02:33
created

XmlEncodeMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A pre() 0 17 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Xml;
4
5
use ApiClients\Foundation\Middleware\Annotation\Third;
6
use ApiClients\Foundation\Middleware\ErrorTrait;
7
use ApiClients\Foundation\Middleware\MiddlewareInterface;
8
use ApiClients\Foundation\Middleware\PostTrait;
9
use ApiClients\Foundation\Transport\ParsedContentsInterface;
10
use ApiClients\Tools\Xml\XmlEncodeService;
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 XmlEncodeMiddleware implements MiddlewareInterface
17
{
18
    use PostTrait;
19
    use ErrorTrait;
20
21
    /**
22
     * @var XmlEncodeService
23
     */
24
    private $xmlEncodeService;
25
26
    /**
27
     * @param XmlEncodeService $xmlEncodeService
28
     */
29 2
    public function __construct(XmlEncodeService $xmlEncodeService)
30
    {
31 2
        $this->xmlEncodeService = $xmlEncodeService;
32 2
    }
33
34
    /**
35
     * @param  RequestInterface            $request
36
     * @param  array                       $options
37
     * @return CancellablePromiseInterface
38
     *
39
     * @Third()
40
     */
41 2
    public function pre(
42
        RequestInterface $request,
43
        string $transactionId,
44
        array $options = []
45
    ): CancellablePromiseInterface {
46 2
        $body = $request->getBody();
47 2
        if (!($body instanceof ParsedContentsInterface)) {
48 1
            return resolve($request);
49
        }
50
51 1
        return $this->xmlEncodeService->encode($body->getParsedContents())->then(function (string $xml) use ($request) {
52 1
            $body = new BufferStream(strlen($xml));
53 1
            $body->write($xml);
54
55 1
            return resolve($request->withBody($body)->withAddedHeader('Content-Type', 'text/xml'));
56 1
        });
57
    }
58
}
59