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.
Completed
Push — master ( 5d4e73...25e621 )
by Niels
03:58
created

AbstractApi   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 74
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 10 2
A post() 0 12 2
A parseResponse() 0 10 3
1
<?php namespace Ntholenaar\MultiSafepayClient\Api;
2
3
use Ntholenaar\MultiSafepayClient\Client;
4
use Psr\Http\Message\ResponseInterface;
5
6
abstract class AbstractApi implements ApiInterface
7
{
8
    /**
9
     * HultiSafepay API Client.
10
     *
11
     * @var Client
12
     */
13
    protected $client;
14
15
    /**
16
     * @param Client $client
17
     */
18
    public function __construct(Client $client)
19
    {
20
        $this->client = $client;
21
    }
22
23
    /**
24
     * Execute an Http GET request.
25
     *
26
     * @param $path
27
     * @param array $parameters
28
     * @return mixed
29
     */
30
    protected function get($path, array $parameters = array())
31
    {
32
        if (count($parameters) > 0) {
33
            $path .= '?' . http_build_query($parameters);
34
        }
35
36
        $response = $this->client->getHttpClient()->get($path);
37
38
        return $this->parseResponse($response);
39
    }
40
41
    /**
42
     * Execute an http POST request.
43
     *
44
     * @param $path
45
     * @param array $parameters
46
     * @param array $body
47
     * @return mixed
48
     */
49
    protected function post($path, array $parameters = array(), $body = array())
50
    {
51
        if (count($parameters) > 0) {
52
            $path .= '?' . http_build_query($parameters);
53
        }
54
55
        $body = json_encode($body);
56
57
        $response = $this->client->getHttpClient()->post($path, [], $body);
58
59
        return $this->parseResponse($response);
60
    }
61
62
    /**
63
     * Parse the response.
64
     *
65
     * @param ResponseInterface $response
66
     * @return mixed
67
     * @throws \Exception
68
     */
69
    protected function parseResponse(ResponseInterface $response)
70
    {
71
        $response = json_decode($response->getBody()->getContents());
72
73
        if (isset($response->success) && $response->success) {
74
            return $response->data;
75
        }
76
77
        throw new \Exception($response->error_info, $response->error_code);
78
    }
79
}
80