Completed
Push — develop ( f37ae4...1d947e )
by Nate
18:30
created

ApplicationKeyConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 63
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHubId() 0 4 1
A prepareAuthorizationRequest() 0 24 2
A handleAuthorizationResponse() 0 7 1
1
<?php
2
3
namespace flipbox\hubspot\connections;
4
5
use flipbox\hubspot\connections\ConnectionInterface;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
class ApplicationKeyConnection implements ConnectionInterface
10
{
11
    /**
12
     * @var
13
     */
14
    public $key;
15
16
    /**
17
     * @var
18
     */
19
    public $hubId;
20
21
    /**
22
     * @return string
23
     */
24
    public function getHubId(): string
25
    {
26
        return $this->hubId;
27
    }
28
29
    /**
30
     * Add the 'hapikey' to the query
31
     *
32
     * @inheritdoc
33
     */
34
    public function prepareAuthorizationRequest(
35
        RequestInterface $request
36
    ): RequestInterface {
37
38
        // Requested URI
39
        $uri = $request->getUri();
40
41
        // Get Query
42
        $query = $uri->getQuery();
43
44
        // Append to?
45
        if (!empty($query)) {
46
            $query .= '&';
47
        }
48
49
        // Add our key
50
        $query .= http_build_query([
51
            'hapikey' => $this->key
52
        ]);
53
54
        return $request->withUri(
55
            $uri->withQuery($query)
56
        );
57
    }
58
59
    /**
60
     * We can't do much, just return the response
61
     *
62
     * @inheritdoc
63
     */
64
    public function handleAuthorizationResponse(
65
        ResponseInterface $response,
66
        RequestInterface $request,
67
        callable $callable
68
    ): ResponseInterface {
69
        return $response;
70
    }
71
}
72