PRequest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A prepareRequest() 0 8 1
A getResponse() 0 7 1
A performGetRequest() 0 6 1
A performPostRequest() 0 6 1
A addBody() 0 6 1
1
<?php
2
3
namespace ParkwayProjects\PayWithBank3D;
4
5
use GuzzleHttp\Client;
6
use ParkwayProjects\PayWithBank3D\Exceptions\Exceptions;
7
8
abstract class PRequest
9
{
10
    protected $client;
11
12
    protected $response;
13
14
    protected $data;
15
16
    public function __construct()
17
    {
18
        if (empty(PayWithBank3D::$secretKey) || empty(PayWithBank3D::$publicKey)) {
19
            throw Exceptions::create('format.is_null');
20
        }
21
22
        $this->prepareRequest();
23
    }
24
25
    protected function prepareRequest()
26
    {
27
        $this->client = new Client([
28
            'base_uri' => PayWithBank3D::$baseUrl[PayWithBank3D::$mode],
29
            'auth' => [PayWithBank3D::$publicKey, PayWithBank3D::$secretKey],
30
            'headers' => ['Content-Type' => 'application/json', 'Accept' => 'application/json'],
31
        ]);
32
    }
33
34
    public function getResponse()
35
    {
36
        $response = new Response($this->response);
0 ignored issues
show
Compatibility introduced by
$this->response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
37
        $json = $response->toJSON();
38
39
        return json_decode($json, true);
40
    }
41
42
    protected function performGetRequest($relativeUrl)
43
    {
44
        $this->response = $this->client->request('GET', $relativeUrl);
45
46
        return $this->getResponse();
47
    }
48
49
    protected function performPostRequest($relativeUrl)
50
    {
51
        $this->response = $this->client->request('POST', $relativeUrl, ['json'=> $this->data]);
52
53
        return $this->getResponse();
54
    }
55
56
    public function addBody($name, $value)
57
    {
58
        $this->data[$name] = $value;
59
60
        return $this;
61
    }
62
}
63