Completed
Push — master ( 2318a7...46571d )
by Claude
03:22
created

AbstractGateway::createRequest()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
nc 4
cc 3
eloc 5
nop 2
crap 3
1
<?php
2
3
namespace Omnipay\Payline;
4
5
use Symfony\Component\HttpFoundation\Request as HttpRequest;
6
7
abstract class AbstractGateway extends \Omnipay\Common\AbstractGateway
8
{
9
    protected $liveEndpoint = 'http://www.payline.com/wsdl/v4_0/production';
10
    protected $testEndpoint = 'http://www.payline.com/wsdl/v4_0/homologation';
11
12
    abstract public function getEndPoint();
13
14
    /**
15
     * AbstractGateway constructor.
16
     * @param \SoapClient|null $httpClient
17
     * @param HttpRequest|null $httpRequest
18
     */
19 87
    public function __construct(\SoapClient $httpClient = null, HttpRequest $httpRequest = null)
20
    {
21 87
        $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...
22 87
        $this->httpRequest = $httpRequest;
23 87
        $this->initialize();
24 87
    }
25
26 24
    protected function createRequest($class, array $parameters)
27
    {
28 24
        $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...
29 24
        $this->httpRequest = $this->httpRequest ?: $this->getDefaultHttpRequest();
30
31 24
        $obj = new $class($this->httpClient, $this->httpRequest);
32
33 24
        return $obj->initialize(array_replace($this->getParameters(), $parameters));
34
    }
35
36 87
    public function getDefaultParameters()
37
    {
38
        return array(
39 87
            'merchantId' => '',
40 87
            'accessKey' => '',
41 87
            'proxyHost' => '',
42 87
            'proxyPort' => '',
43 87
            'proxyLogin' => '',
44 87
            'proxyPassword' => '',
45 87
            'contractNumber' => '',
46 87
            'testMode' => true,
47 87
        );
48
    }
49
50
    /**
51
     * @return string
52
     */
53 6
    public function getMerchantId()
54
    {
55 6
        return $this->getParameter('merchantId');
56
    }
57
58
    /**
59
     * @param string $merchantId
60
     * @return $this
61
     */
62 87
    public function setMerchantId($merchantId)
63
    {
64 87
        return $this->setParameter('merchantId', $merchantId);
65
    }
66
67
    /**
68
     * @return string
69
     */
70 6
    public function getAccessKey()
71
    {
72 6
        return $this->getParameter('accessKey');
73
    }
74
75
    /**
76
     * @param string $accessKey
77
     * @return $this
78
     */
79 87
    public function setAccessKey($accessKey)
80
    {
81 87
        return $this->setParameter('accessKey', $accessKey);
82
    }
83
84
    /**
85
     * @return string
86
     */
87 3
    public function getContractNumber()
88
    {
89 3
        return $this->getParameter('contractNumber');
90
    }
91
92
    /**
93
     * @param string $contractNumber
94
     * @return $this
95
     */
96 87
    public function setContractNumber($contractNumber)
97
    {
98 87
        return $this->setParameter('contractNumber', $contractNumber);
99
    }
100
101
    /**
102
     * @return string
103
     */
104 6
    public function getProxyHost()
105
    {
106 6
        return $this->getParameter('proxyHost');
107
    }
108
109
    /**
110
     * @param string $proxyHost
111
     * @return $this
112
     */
113 87
    public function setProxyHost($proxyHost)
114
    {
115 87
        return $this->setParameter('proxyHost', $proxyHost);
116
    }
117
118
    /**
119
     * @return string
120
     */
121 6
    public function getProxyPort()
122
    {
123 6
        return $this->getParameter('proxyPort');
124
    }
125
126
    /**
127
     * @param string $proxyPort
128
     * @return $this
129
     */
130 87
    public function setProxyPort($proxyPort)
131
    {
132 87
        return $this->setParameter('proxyPort', $proxyPort);
133
    }
134
135
    /**
136
     * @return string
137
     */
138 6
    public function getProxyLogin()
139
    {
140 6
        return $this->getParameter('proxyLogin');
141
    }
142
143
    /**
144
     * @param string $proxyLogin
145
     * @return $this
146
     */
147 87
    public function setProxyLogin($proxyLogin)
148
    {
149 87
        return $this->setParameter('proxyLogin', $proxyLogin);
150
    }
151
152
    /**
153
     * @return string
154
     */
155 6
    public function getProxyPassword()
156
    {
157 6
        return $this->getParameter('proxyPassword');
158
    }
159
160
    /**
161
     * @param string $proxyPassword
162
     * @return $this
163
     */
164 87
    public function setProxyPassword($proxyPassword)
165
    {
166 87
        return $this->setParameter('proxyPassword', $proxyPassword);
167
    }
168
169
    /**
170
     * @return \SoapClient
171
     */
172 3
    public function getDefaultHttpClient()
173
    {
174
        $header = [
175 3
            'Content-Type' => 'text/xml; charset=utf-8',
176 3
            'login' => $this->getMerchantId(),
177 3
            'password' => $this->getAccessKey(),
178 3
            'style' => defined(SOAP_DOCUMENT) ? SOAP_DOCUMENT : 2,
179 3
            'use' => defined(SOAP_LITERAL) ? SOAP_LITERAL : 2,
180
            'connection_timeout' => 5
181 3
        ];
182
183 3
        if($this->getProxyHost())
184 3
        {
185 3
            $header['proxy_host'] = $this->getProxyHost();
186 3
            $header['proxy_port'] = $this->getProxyPort();
187 3
            $header['proxy_login'] = $this->getProxyLogin();
188 3
            $header['proxy_password'] = $this->getProxyPassword();
189 3
        }
190
191 3
        return new \SoapClient($this->getEndPoint(), $header);
192
    }
193
}
194