Completed
Push — php-7-testing ( df32ff...3863c5 )
by Danail
10:44 queued 05:03
created

AbstractRequest::getThreatmetrix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Omnipay\Emp\Message;
4
5
use Omnipay\Emp\Threatmetrix;
6
7
/**
8
 * @author    Ivan Kerin <[email protected]>
9
 * @copyright 2014, Clippings Ltd.
10
 * @license   http://spdx.org/licenses/BSD-3-Clause
11
 */
12
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
13
{
14
    /**
15
     * @return string
16
     */
17
    abstract function getEndpoint();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getEndpoint.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
18
19
    /**
20
     * @return string
21
     */
22 3
    public function getClientId()
23
    {
24 3
        return $this->getParameter('clientId');
25
    }
26
27
    /**
28
     * @param string $value
29
     */
30 5
    public function setClientId($value)
31
    {
32 5
        return $this->setParameter('clientId', $value);
33
    }
34
35
    /**
36
     * @return string
37
     */
38 3
    public function getApiKey()
39
    {
40 3
        return $this->getParameter('apiKey');
41
    }
42
43
    /**
44
     * @param string $value
45
     */
46 5
    public function setApiKey($value)
47
    {
48 5
        return $this->setParameter('apiKey', $value);
49
    }
50
51
    /**
52
     * @return string
53
     */
54 1
    public function getProxy()
55
    {
56 1
        return $this->getParameter('proxy');
57
    }
58
59
    /**
60
     * @param string $value
61
     */
62 5
    public function setProxy($value)
63
    {
64 5
        return $this->setParameter('proxy', $value);
65
    }
66
67
    /**
68
     * @return Threatmetrix
69
     */
70 1
    public function getThreatmetrix()
71
    {
72 1
        return $this->getParameter('threatmetrix');
73
    }
74
75
    /**
76
     * @param Threatmetrix $value
77
     */
78 1
    public function setThreatmetrix(Threatmetrix $value)
79
    {
80 1
        return $this->setParameter('threatmetrix', $value);
81
    }
82
83
    /**
84
     * Base "getData" should be extended by other requests
85
     *
86
     * @return array
87
     */
88 2
    public function getData()
89
    {
90 2
        $data = array();
91
92 2
        if ($this->getTestMode()) {
93 1
            $data['test_transaction'] = '1';
94 1
        }
95
96 2
        if ($this->getThreatmetrix()) {
97 1
            $data['thm_session_id'] = $this->getThreatmetrix()->getSessionId();
98 1
        }
99
100 2
        $data['client_id'] = $this->getClientId();
101 2
        $data['api_key'] = $this->getApiKey();
102
103 2
        return $data;
104
    }
105
106
    /**
107
     * @param  mixed $data
108
     * @return array
109
     */
110 1
    public function sendData($data)
111
    {
112 1
        $httpRequest = $this->httpClient->post(
113 1
            $this->getEndpoint(),
114 1
            null,
115 1
            $data,
116 1
            $this->getProxy() ? array('proxy' => $this->getProxy()) : array()
117 1
        );
118
119 1
        $httpResponse = $httpRequest->send();
120
121 1
        return json_decode(json_encode($httpResponse->xml()), true);
122
    }
123
}
124