AbstractRequest::getHttpMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 2
cp 0.5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.125
1
<?php
2
3
namespace Omnipay\ZipPay\Message;
4
5
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
6
7
/**
8
 * Abstract Request
9
 *
10
 */
11
abstract class AbstractRequest extends BaseAbstractRequest
12
{
13
    protected $liveEndpoint = 'https://api.zipmoney.com.au/merchant/v1';
14
    protected $testEndpoint = 'https://api.sandbox.zipmoney.com.au/merchant/v1';
15
16 15
    protected $negativeAmountAllowed = true;
17
18 15
    public function getKey()
19
    {
20
        return $this->getParameter('key');
21 60
    }
22
23 60
    public function setKey($value)
24
    {
25
        return $this->setParameter('key', $value);
26 45
    }
27
28 45
    public function getApiKey()
29
    {
30
        return $this->getParameter('apiKey');
31 60
    }
32
33 60
    public function setApiKey($value)
34
    {
35
        return $this->setParameter('apiKey', $value);
36 30
    }
37
38
    public function getHeaders()
39 30
    {
40 30
        return [
41 30
            'Content-Type' => 'application/json',
42 10
            'Authorization' => 'Bearer ' . $this->getApiKey(),
43
            'Zip-Version' => '2017-03-01',
44
        ];
45 30
    }
46
47 30
    public function sendData($data)
48
    {
49 30
        $headers = $this->getHeaders();
50 30
51 30
        $url = $this->getEndpoint();
52
        $body = null;
53
        if ($this->getHttpMethod() === 'GET') {
54 30
            $url = $this->getEndpoint().'?'.http_build_query($data, '', '&');
55
        } else {
56
            $body = json_encode($data);
57 30
        }
58
59 30
        $response = $this->httpClient->request($this->getHttpMethod(), $url, $headers, $body);
60
61 30
        $responseHeaders = $response->getHeaders();
62
63 30
        $data = json_decode($response->getBody(), true);
64
65
        return $this->createResponse($data, $responseHeaders, $response->getStatusCode());
66
    }
67
68
    public function getHttpMethod()
69
    {
70
        return 'GET';
71 30
    }
72
73 30
    protected function getBaseData()
74
    {
75
        return [];
76 30
    }
77
78 30
    protected function getEndpoint()
79
    {
80
        return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
81
    }
82
83
    protected function createResponse($data, $headers = [], $status = 404)
84
    {
85
        return $this->response = new Response($this, $data, $headers);
0 ignored issues
show
Bug introduced by
The call to Response::__construct() misses a required argument $status.

This check looks for function calls that miss required arguments.

Loading history...
86
    }
87
}
88