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.

Gateway   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 55
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 2
A execute() 0 12 1
1
<?php
2
3
namespace CMPayments\PaymentSdk;
4
5
use CMPayments\GuzzlePSPAuthenticationMiddleware\AuthenticationMiddleware;
6
use CMPayments\PaymentSdk\Requests\RequestInterface;
7
use GuzzleHttp\Client as HttpClient;
8
use GuzzleHttp\HandlerStack;
9
10
/**
11
 * Gateway to the payments API.
12
 *
13
 * @package CMPayments\PaymentSdk
14
 * @author Jory Geerts <[email protected]>
15
 */
16
class Gateway
17
{
18
    const API_URL = 'https://api.cmpayments.com/';
19
20
    const REQUEST_METHOD_POST = 'POST';
21
    const REQUEST_METHOD_GET = 'GET';
22
23
    /**
24
     * @var HttpClient
25
     */
26
    private $httpClient;
27
28
    /**
29
     * Gateway constructor.
30
     * @param Credentials $credentials
31
     * @param HttpClient|null $httpClient
32
     */
33 5
    public function __construct(Credentials $credentials, HttpClient $httpClient = null)
34
    {
35 5
        if (!$httpClient) {
36 1
            $httpClient = new HttpClient([
37
                'base_uri' => static::API_URL
38 1
            ]);
39 1
        }
40 5
        $this->httpClient = $httpClient;
41
42
        /** @var HandlerStack $handlerStack */
43 5
        $handlerStack = $httpClient->getConfig('handler');
44 5
        $handlerStack->push(
45 5
            new AuthenticationMiddleware(
46 5
                $credentials->getMerchantKey(),
47 5
                $credentials->getMerchantSecret()
48 5
            )
49 5
        );
50 5
    }
51
52
    /**
53
     * Execute a request against the Payments API.
54
     *
55
     * @param RequestInterface $request
56
     * @return array
57
     */
58 4
    public function execute(RequestInterface $request)
59
    {
60 4
        $guzzleResponse = $this->httpClient->request(
61 4
            $request->getRequestMethod(),
62 4
            $request->getEndpoint(),
63
            [
64 4
                'json' => $request->getPayload()
65 4
            ]
66 4
        );
67
68 1
        return \GuzzleHttp\json_decode($guzzleResponse->getBody()->getContents());
69
    }
70
}
71