Url::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/relay-salesforce/blob/master/LICENSE.md
6
 * @link       https://github.com/flipbox/relay-salesforce
7
 */
8
9
namespace Flipbox\Relay\Salesforce\Middleware;
10
11
use Flipbox\Relay\Middleware\AbstractMiddleware;
12
use Psr\Http\Message\RequestInterface;
13
use Psr\Http\Message\ResponseInterface;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class Url extends AbstractMiddleware
20
{
21
    /**
22
     * The request method
23
     */
24
    public $method = 'GET';
25
26
    /**
27
     * The url
28
     */
29
    public $url;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function __invoke(
35
        RequestInterface $request,
36
        ResponseInterface $response,
37
        callable $next = null
38
    ) {
39
        parent::__invoke($request, $response, $next);
40
41
        $request = $this->prepareUri(
42
            $request->withMethod($this->method)
43
        );
44
45
        return $next($request, $response);
46
    }
47
48
    /**
49
     * @param RequestInterface $request
50
     * @return RequestInterface
51
     */
52
    protected function prepareUri(RequestInterface $request)
53
    {
54
        $uri = $request->getUri();
55
        return $request->withUri(
56
            $uri->withPath(
57
                rtrim($this->url, "/")  . "/"
58
            )
59
        );
60
    }
61
}
62