Completed
Push — master ( a179cf...590e45 )
by Claude
04:15
created

AbstractGateway::getDefaultHttpClient()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.5923

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 20
ccs 10
cts 15
cp 0.6667
rs 9.2
cc 4
eloc 14
nc 8
nop 0
crap 4.5923
1
<?php
2
3
/*
4
 * WebMoney driver for the Omnipay PHP payment processing library
5
 *
6
 * @link      https://github.com/ck-developer/omnipay-payline
7
 * @package   omnipay-payline
8
 * @license   MIT
9
 * @copyright Copyright (c) 2016 Claude Khedhiri <[email protected]>
10
 */
11
12
namespace Omnipay\Payline;
13
14
use Symfony\Component\HttpFoundation\Request as HttpRequest;
15
16
abstract class AbstractGateway extends \Omnipay\Common\AbstractGateway
17
{
18
    protected $liveEndpoint = 'http://www.payline.com/wsdl/v4_0/production';
19
    protected $testEndpoint = 'http://www.payline.com/wsdl/v4_0/homologation';
20
21
    abstract public function getEndPoint();
22
23
    /**
24
     * AbstractGateway constructor.
25
     *
26
     * @param \SoapClient|null $httpClient
27
     * @param HttpRequest|null $httpRequest
28
     */
29 90
    public function __construct(\SoapClient $httpClient = null, HttpRequest $httpRequest = null)
30
    {
31 90
        $this->httpClient = $httpClient;
0 ignored issues
show
Documentation Bug introduced by
It seems like $httpClient can also be of type object<SoapClient>. However, the property $httpClient is declared as type object<Guzzle\Http\ClientInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
32 90
        $this->httpRequest = $httpRequest;
33 90
        $this->initialize();
34 90
    }
35
36 33
    protected function createRequest($class, array $parameters)
37
    {
38 33
        $this->httpClient = $this->httpClient ?: $this->getDefaultHttpClient();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->httpClient ?: $th...>getDefaultHttpClient() can also be of type object<SoapClient>. However, the property $httpClient is declared as type object<Guzzle\Http\ClientInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
39 33
        $this->httpRequest = $this->httpRequest ?: $this->getDefaultHttpRequest();
40
41 33
        $obj = new $class($this->httpClient, $this->httpRequest);
42
43 33
        return $obj->initialize(array_replace($this->getParameters(), $parameters));
44
    }
45
46 90
    public function getDefaultParameters()
47
    {
48
        return array(
49 90
            'merchantId' => '',
50 60
            'accessKey' => '',
51 60
            'proxyHost' => '',
52 60
            'proxyPort' => '',
53 60
            'proxyLogin' => '',
54 60
            'proxyPassword' => '',
55 60
            'contractNumber' => '',
56 60
            'testMode' => true,
57 60
        );
58
    }
59
60
    /**
61
     * @return string
62
     */
63 6
    public function getMerchantId()
64
    {
65 6
        return $this->getParameter('merchantId');
66
    }
67
68
    /**
69
     * @param string $merchantId
70
     *
71
     * @return $this
72
     */
73 90
    public function setMerchantId($merchantId)
74
    {
75 90
        return $this->setParameter('merchantId', $merchantId);
76
    }
77
78
    /**
79
     * @return string
80
     */
81 6
    public function getAccessKey()
82
    {
83 6
        return $this->getParameter('accessKey');
84
    }
85
86
    /**
87
     * @param string $accessKey
88
     *
89
     * @return $this
90
     */
91 90
    public function setAccessKey($accessKey)
92
    {
93 90
        return $this->setParameter('accessKey', $accessKey);
94
    }
95
96
    /**
97
     * @return string
98
     */
99 3
    public function getContractNumber()
100
    {
101 3
        return $this->getParameter('contractNumber');
102
    }
103
104
    /**
105
     * @param string $contractNumber
106
     *
107
     * @return $this
108
     */
109 90
    public function setContractNumber($contractNumber)
110
    {
111 90
        return $this->setParameter('contractNumber', $contractNumber);
112
    }
113
114
    /**
115
     * @return string
116
     */
117 6
    public function getProxyHost()
118
    {
119 6
        return $this->getParameter('proxyHost');
120
    }
121
122
    /**
123
     * @param string $proxyHost
124
     *
125
     * @return $this
126
     */
127 15
    public function setProxyHost($proxyHost)
128
    {
129 15
        return $this->setParameter('proxyHost', $proxyHost);
130
    }
131
132
    /**
133
     * @return string
134
     */
135 3
    public function getProxyPort()
136
    {
137 3
        return $this->getParameter('proxyPort');
138
    }
139
140
    /**
141
     * @param string $proxyPort
142
     *
143
     * @return $this
144
     */
145 15
    public function setProxyPort($proxyPort)
146
    {
147 15
        return $this->setParameter('proxyPort', $proxyPort);
148
    }
149
150
    /**
151
     * @return string
152
     */
153 3
    public function getProxyLogin()
154
    {
155 3
        return $this->getParameter('proxyLogin');
156
    }
157
158
    /**
159
     * @param string $proxyLogin
160
     *
161
     * @return $this
162
     */
163 15
    public function setProxyLogin($proxyLogin)
164
    {
165 15
        return $this->setParameter('proxyLogin', $proxyLogin);
166
    }
167
168
    /**
169
     * @return string
170
     */
171 3
    public function getProxyPassword()
172
    {
173 3
        return $this->getParameter('proxyPassword');
174
    }
175
176
    /**
177
     * @param string $proxyPassword
178
     *
179
     * @return $this
180
     */
181 15
    public function setProxyPassword($proxyPassword)
182
    {
183 15
        return $this->setParameter('proxyPassword', $proxyPassword);
184
    }
185
186
    /**
187
     * @return \SoapClient
188
     */
189 3
    public function getDefaultHttpClient()
190
    {
191
        $header = array(
192 3
            'Content-Type' => 'text/xml; charset=utf-8',
193 3
            'login' => $this->getMerchantId(),
194 3
            'password' => $this->getAccessKey(),
195 3
            'style' => defined(SOAP_DOCUMENT) ? SOAP_DOCUMENT : 2,
196 3
            'use' => defined(SOAP_LITERAL) ? SOAP_LITERAL : 2,
197 3
            'connection_timeout' => 5,
198 2
        );
199
200 3
        if ($this->getProxyHost()) {
201
            $header['proxy_host'] = $this->getProxyHost();
202
            $header['proxy_port'] = $this->getProxyPort();
203
            $header['proxy_login'] = $this->getProxyLogin();
204
            $header['proxy_password'] = $this->getProxyPassword();
205
        }
206
207 3
        return new \SoapClient($this->getEndPoint(), $header);
208
    }
209
}
210