Completed
Push — master ( 481c33...0c5dca )
by Nate
04:03
created

Key   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A prepRequest() 0 22 2
1
<?php
2
3
namespace Flipbox\Relay\HubSpot\Middleware\Authorization;
4
5
use Flipbox\Relay\Middleware\AbstractMiddleware;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
class Key extends AbstractMiddleware
10
{
11
12
    /**
13
     * @var string
14
     */
15
    public $key;
16
17
    /**
18
     * @inheritdoc
19
     */
20
    public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next = null)
21
    {
22
        return $next($this->prepRequest($request), $response);
23
    }
24
25
    /**
26
     * @param RequestInterface $request
27
     * @return RequestInterface
28
     */
29
    private function prepRequest(RequestInterface $request)
30
    {
31
        // Requested URI
32
        $uri = $request->getUri();
33
34
        // Get Query
35
        $query = $uri->getQuery();
36
37
        // Append to?
38
        if (!empty($query)) {
39
            $query .= '&';
40
        }
41
42
        // Add our key
43
        $query .= http_build_query([
44
            'hapikey' => $this->key
45
        ]);
46
47
        return $request->withUri(
48
            $uri->withQuery($query)
49
        );
50
    }
51
}
52