JsonRequest::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
ccs 0
cts 15
cp 0
rs 9.7
cc 2
nc 2
nop 3
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/relay-hubspot/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/relay-hubspot
7
 */
8
9
namespace Flipbox\Relay\HubSpot\Middleware;
10
11
use Flipbox\Http\Stream\Factory as StreamFactory;
12
use Flipbox\Relay\Middleware\AbstractMiddleware;
13
use Psr\Http\Message\RequestInterface;
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class JsonRequest extends AbstractMiddleware
21
{
22
    /**
23
     * @var array
24
     */
25
    public $payload;
26
27
    /**
28
     * @inheritdoc
29
     * @throws \Flipbox\Http\Stream\Exceptions\InvalidStreamException
30
     */
31
    public function __invoke(
32
        RequestInterface $request,
33
        ResponseInterface $response,
34
        callable $next = null
35
    ) {
36
        parent::__invoke($request, $response, $next);
37
38
        if ($this->payload !== null) {
39
            $request = $request->withBody(
40
                StreamFactory::create(
41
                    json_encode($this->payload)
42
                )
43
            );
44
        }
45
46
        return $next($request, $response);
47
    }
48
}
49