AbstractRequest::getHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Omnipay\Myfatoorah\Message;
4
5
use Guzzle\Http\Exception\ClientErrorResponseException;
0 ignored issues
show
Bug introduced by
The type Guzzle\Http\Exception\ClientErrorResponseException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest {
8
9
    protected $sandboxEndpoint    = "https://apitest.myfatoorah.com";
10
    protected $productionEndpoint = "https://api.myfatoorah.com";
11
12
    public function getApiKey() {
13
        return $this->getParameter('apiKey');
14
    }
15
16
    public function setApiKey($value) {
17
        return $this->setParameter('apiKey', $value);
18
    }
19
20
    /**
21
     * Get the gateway Test mode
22
     *
23
     * @return string
24
     */
25
    public function getTestMode() {
26
        return $this->getParameter('testMode');
27
    }
28
29
    /**
30
     * Set the gateway Test mode
31
     *
32
     * @param  string $value
33
     * @return Gateway provides a fluent interface.
0 ignored issues
show
Bug introduced by
The type Omnipay\Myfatoorah\Message\Gateway was not found. Did you mean Gateway? If so, make sure to prefix the type with \.
Loading history...
34
     */
35
    public function setTestMode($value) {
36
        return $this->setParameter('testMode', $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->setParameter('testMode', $value) returns the type Omnipay\Myfatoorah\Message\AbstractRequest which is incompatible with the documented return type Omnipay\Myfatoorah\Message\Gateway.
Loading history...
37
    }
38
39
    public function getAmount() {
40
        return $this->getParameter('Amount');
41
    }
42
43
    public function setAmount($value) {
44
        return $this->setParameter('Amount', $value);
45
    }
46
47
    public function getCurrency() {
48
        return $this->getParameter('Currency');
49
    }
50
51
    public function setCurrency($value) {
52
        return $this->setParameter('Currency', $value);
53
    }
54
55
    public function getCard() {
56
        return $this->getParameter('Card');
57
    }
58
59
    public function setCard($value) {
60
        return $this->setParameter('Card', $value);
61
    }
62
63
    public function getFirstName() {
64
        $card = $this->getCard();
65
        return $card['firstName'];
66
    }
67
68
    public function setFirstName($value) {
69
        $card              = $this->getCard();
70
        return $card['firstName'] = $value;
71
    }
72
73
    public function getLastName() {
74
        $card = $this->getCard();
75
        return $card['lastName'];
76
    }
77
78
    public function setLastName($value) {
79
        $card             = $this->getCard();
80
        return $card['lastName'] = $value;
81
    }
82
83
    public function getEmail() {
84
        $card = $this->getCard();
85
        return $card['email'];
86
    }
87
88
    public function setEmail($value) {
89
        $card          = $this->getCard();
90
        return $card['email'] = $value;
91
    }
92
93
    public function getPhone() {
94
        $card = $this->getCard();
95
        return $card['phone'];
96
    }
97
98
    public function setPhone($value) {
99
        $card          = $this->getCard();
100
        return $card['phone'] = $value;
101
    }
102
103
    public function getCallBackUrl() {
104
        return $this->getParameter('returnUrl');
105
    }
106
107
    public function setCallBackUrl($value) {
108
        return $this->getParameter('returnUrl', $value);
0 ignored issues
show
Unused Code introduced by
The call to Omnipay\Common\Message\A...Request::getParameter() has too many arguments starting with $value. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
        return $this->/** @scrutinizer ignore-call */ getParameter('returnUrl', $value);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
109
    }
110
111
    public function getOrderRef() {
112
        return $this->getParameter('OrderRef');
113
    }
114
115
    public function setOrderRef($value) {
116
        return $this->setParameter('OrderRef', $value);
117
    }
118
119
    public function getHeaders() {
120
        $headers = [];
121
122
        return $headers;
123
    }
124
125
    public function send() {
126
        $data    = $this->getData();
127
        $headers = array_merge(
128
                $this->getHeaders(),
129
                ['Authorization' => 'Bearer ' . $this->getApiKey(), 'Content-Type' => ' application/json']
130
        );
131
132
        return $this->sendData($data, $headers);
133
    }
134
135
    public function sendData($data, array $headers = null) {
136
        if (sizeof($data) == 0) {
137
            $postFields = null;
138
        } else {
139
            $postFields = json_encode($data);
140
        }
141
        try {
142
            $httpResponse = $this->httpClient->request(
143
                    $this->getHttpMethod(),
144
                    $this->getEndpoint(),
145
                    $headers,
0 ignored issues
show
Bug introduced by
It seems like $headers can also be of type null; however, parameter $headers of Omnipay\Common\Http\ClientInterface::request() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
                    /** @scrutinizer ignore-type */ $headers,
Loading history...
146
                    $postFields
147
            );
148
        } catch (ClientErrorResponseException $e) {
149
            $httpResponse = $e->getResponse();
150
        }
151
//                print_r($httpResponse->getBody()->getContents()); die;
152
153
        return (new Response($this, $httpResponse));
154
    }
155
156
    public function getHttpMethod() {
157
        return 'POST';
158
    }
159
160
    abstract public function getEndpoint();
161
}
162