Completed
Pull Request — 23 (#431)
by Harald
10:27
created

PaymentMethodGateway   C

Complexity

Total Complexity 39

Size/Duplication

Total Lines 282
Duplicated Lines 18.09 %

Coupling/Cohesion

Components 1
Dependencies 18

Importance

Changes 0
Metric Value
dl 51
loc 282
rs 6.1543
c 0
b 0
f 0
wmc 39
lcom 1
cbo 18

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A create() 0 5 1
C find() 0 33 12
A update() 0 5 1
A delete() 7 7 1
A grant() 0 12 1
A revoke() 0 11 1
B baseSignature() 0 25 1
A createSignature() 0 5 1
A updateSignature() 0 16 1
A _doCreate() 7 7 1
A _doUpdate() 7 7 1
C _verifyGatewayResponse() 17 65 13
A _validateId() 13 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Braintree;
3
4
use InvalidArgumentException;
5
6
/**
7
 * Braintree PaymentMethodGateway module
8
 *
9
 * @package    Braintree
10
 * @category   Resources
11
 * @copyright  2015 Braintree, a division of PayPal, Inc.
12
 */
13
14
/**
15
 * Creates and manages Braintree PaymentMethods
16
 *
17
 * <b>== More information ==</b>
18
 *
19
 *
20
 * @package    Braintree
21
 * @category   Resources
22
 * @copyright  2015 Braintree, a division of PayPal, Inc.
23
 *
24
 */
25
class PaymentMethodGateway
26
{
27
    private $_gateway;
28
    private $_config;
29
    private $_http;
30
31
    public function __construct($gateway)
32
    {
33
        $this->_gateway = $gateway;
34
        $this->_config = $gateway->config;
35
        $this->_config->assertHasAccessTokenOrKeys();
36
        $this->_http = new Http($gateway->config);
37
    }
38
39
40
    public function create($attribs)
41
    {
42
        Util::verifyKeys(self::createSignature(), $attribs);
43
        return $this->_doCreate('/payment_methods', ['payment_method' => $attribs]);
44
    }
45
46
    /**
47
     * find a PaymentMethod by token
48
     *
49
     * @param string $token payment method unique id
50
     * @return CreditCard|PayPalAccount
51
     * @throws Exception\NotFound
52
     */
53
    public function find($token)
54
    {
55
        $this->_validateId($token);
56
        try {
57
            $path = $this->_config->merchantPath() . '/payment_methods/any/' . $token;
58
            $response = $this->_http->get($path);
59
            if (isset($response['creditCard'])) {
60
                return CreditCard::factory($response['creditCard']);
61
            } else if (isset($response['paypalAccount'])) {
62
                return PayPalAccount::factory($response['paypalAccount']);
63
            } else if (isset($response['coinbaseAccount'])) {
64
                return CoinbaseAccount::factory($response['coinbaseAccount']);
65
            } else if (isset($response['applePayCard'])) {
66
                return ApplePayCard::factory($response['applePayCard']);
67
            } else if (isset($response['androidPayCard'])) {
68
                return AndroidPayCard::factory($response['androidPayCard']);
69
            } else if (isset($response['amexExpressCheckoutCard'])) {
70
                return AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']);
71
            } else if (isset($response['europeBankAccount'])) {
72
                return EuropeBankAccount::factory($response['europeBankAccount']);
73
            } else if (isset($response['usBankAccount'])) {
74
                return UsBankAccount::factory($response['usBankAccount']);
75
            } else if (isset($response['venmoAccount'])) {
76
                return VenmoAccount::factory($response['venmoAccount']);
77
            } else if (is_array($response)) {
78
                return UnknownPaymentMethod::factory($response);
79
            }
80
        } catch (Exception\NotFound $e) {
81
            throw new Exception\NotFound(
82
                'payment method with token ' . $token . ' not found'
83
            );
84
        }
85
    }
86
87
    public function update($token, $attribs)
88
    {
89
        Util::verifyKeys(self::updateSignature(), $attribs);
90
        return $this->_doUpdate('/payment_methods/any/' . $token, ['payment_method' => $attribs]);
91
    }
92
93 View Code Duplication
    public function delete($token)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $this->_validateId($token);
96
        $path = $this->_config->merchantPath() . '/payment_methods/any/' . $token;
97
        $this->_http->delete($path);
98
        return new Result\Successful();
99
    }
100
101
    public function grant($sharedPaymentMethodToken, $allowVaulting)
102
    {
103
        return $this->_doCreate(
104
            '/payment_methods/grant',
105
            [
106
                'payment_method' => [
107
                    'shared_payment_method_token' => $sharedPaymentMethodToken,
108
                    'allow_vaulting' => $allowVaulting
109
                ]
110
            ]
111
        );
112
    }
113
114
    public function revoke($sharedPaymentMethodToken)
115
    {
116
        return $this->_doCreate(
117
            '/payment_methods/revoke',
118
            [
119
                'payment_method' => [
120
                    'shared_payment_method_token' => $sharedPaymentMethodToken
121
                ]
122
            ]
123
        );
124
    }
125
126
    private static function baseSignature()
127
    {
128
        $billingAddressSignature = AddressGateway::createSignature();
129
        $optionsSignature = [
130
            'failOnDuplicatePaymentMethod',
131
            'makeDefault',
132
            'verificationMerchantAccountId',
133
            'verifyCard',
134
            'verificationAmount'
135
        ];
136
        return [
137
            'billingAddressId',
138
            'cardholderName',
139
            'cvv',
140
            'deviceData',
141
            'expirationDate',
142
            'expirationMonth',
143
            'expirationYear',
144
            'number',
145
            'paymentMethodNonce',
146
            'token',
147
            ['options' => $optionsSignature],
148
            ['billingAddress' => $billingAddressSignature]
149
        ];
150
    }
151
152
    public static function createSignature()
153
    {
154
        $signature = array_merge(self::baseSignature(), ['customerId']);
155
        return $signature;
156
    }
157
158
    public static function updateSignature()
159
    {
160
        $billingAddressSignature = AddressGateway::updateSignature();
161
        array_push($billingAddressSignature, [
162
            'options' => [
163
                'updateExisting'
164
            ]
165
        ]);
166
        $signature = array_merge(self::baseSignature(), [
167
            'deviceSessionId',
168
            'venmoSdkPaymentMethodCode',
169
            'fraudMerchantId',
170
            ['billingAddress' => $billingAddressSignature]
171
        ]);
172
        return $signature;
173
    }
174
175
    /**
176
     * sends the create request to the gateway
177
     *
178
     * @ignore
179
     * @param string $subPath
180
     * @param array $params
181
     * @return mixed
182
     */
183 View Code Duplication
    public function _doCreate($subPath, $params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
184
    {
185
        $fullPath = $this->_config->merchantPath() . $subPath;
186
        $response = $this->_http->post($fullPath, $params);
187
188
        return $this->_verifyGatewayResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->_http->post($fullPath, $params) on line 186 can also be of type null; however, Braintree\PaymentMethodG...verifyGatewayResponse() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
189
    }
190
191
    /**
192
     * sends the update request to the gateway
193
     *
194
     * @ignore
195
     * @param string $subPath
196
     * @param array $params
197
     * @return mixed
198
     */
199 View Code Duplication
    public function _doUpdate($subPath, $params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
200
    {
201
        $fullPath = $this->_config->merchantPath() . $subPath;
202
        $response = $this->_http->put($fullPath, $params);
203
204
        return $this->_verifyGatewayResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->_http->put($fullPath, $params) on line 202 can also be of type null; however, Braintree\PaymentMethodG...verifyGatewayResponse() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
205
    }
206
207
    /**
208
     * generic method for validating incoming gateway responses
209
     *
210
     * creates a new CreditCard or PayPalAccount object
211
     * and encapsulates it inside a Result\Successful object, or
212
     * encapsulates a Errors object inside a Result\Error
213
     * alternatively, throws an Unexpected exception if the response is invalid.
214
     *
215
     * @ignore
216
     * @param array $response gateway response values
217
     * @return Result\Successful|Result\Error
218
     * @throws Exception\Unexpected
219
     */
220
    private function _verifyGatewayResponse($response)
221
    {
222
        if (isset($response['creditCard'])) {
223
            return new Result\Successful(
224
                CreditCard::factory($response['creditCard']),
0 ignored issues
show
Documentation introduced by
\Braintree\CreditCard::f...response['creditCard']) is of type object<Braintree\CreditCard>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
225
                'paymentMethod'
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
226
            );
227
        } else if (isset($response['paypalAccount'])) {
228
            return new Result\Successful(
229
                PayPalAccount::factory($response['paypalAccount']),
0 ignored issues
show
Documentation introduced by
\Braintree\PayPalAccount...ponse['paypalAccount']) is of type object<Braintree\PayPalAccount>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
230
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
231
            );
232
        } else if (isset($response['coinbaseAccount'])) {
233
            return new Result\Successful(
234
                CoinbaseAccount::factory($response['coinbaseAccount']),
0 ignored issues
show
Documentation introduced by
\Braintree\CoinbaseAccou...nse['coinbaseAccount']) is of type object<Braintree\CoinbaseAccount>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
235
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
236
            );
237
        } else if (isset($response['applePayCard'])) {
238
            return new Result\Successful(
239
                ApplePayCard::factory($response['applePayCard']),
0 ignored issues
show
Documentation introduced by
\Braintree\ApplePayCard:...sponse['applePayCard']) is of type object<Braintree\ApplePayCard>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
240
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
241
            );
242
        } else if (isset($response['androidPayCard'])) {
243
            return new Result\Successful(
244
                AndroidPayCard::factory($response['androidPayCard']),
0 ignored issues
show
Documentation introduced by
\Braintree\AndroidPayCar...onse['androidPayCard']) is of type object<Braintree\AndroidPayCard>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
245
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
246
            );
247
        } else if (isset($response['amexExpressCheckoutCard'])) {
248
            return new Result\Successful(
249
                AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']),
0 ignored issues
show
Documentation introduced by
\Braintree\AmexExpressCh...xExpressCheckoutCard']) is of type object<Braintree\AmexExpressCheckoutCard>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
250
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
251
            );
252
        } else if (isset($response['europeBankAccount'])) {
253
            return new Result\Successful(
254
                EuropeBankAccount::factory($response['europeBankAccount']),
0 ignored issues
show
Documentation introduced by
\Braintree\EuropeBankAcc...e['europeBankAccount']) is of type object<Braintree\EuropeBankAccount>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
255
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
256
            );
257
        } else if (isset($response['usBankAccount'])) {
258
            return new Result\Successful(
259
                UsBankAccount::factory($response['usBankAccount']),
0 ignored issues
show
Documentation introduced by
\Braintree\UsBankAccount...ponse['usBankAccount']) is of type object<Braintree\UsBankAccount>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
260
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
261
            );
262
        } else if (isset($response['venmoAccount'])) {
263
            return new Result\Successful(
264
                VenmoAccount::factory($response['venmoAccount']),
0 ignored issues
show
Documentation introduced by
\Braintree\VenmoAccount:...sponse['venmoAccount']) is of type object<Braintree\VenmoAccount>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
265
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
266
            );
267 View Code Duplication
        } else if (isset($response['paymentMethodNonce'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
            return new Result\Successful(
269
                PaymentMethodNonce::factory($response['paymentMethodNonce']),
0 ignored issues
show
Documentation introduced by
\Braintree\PaymentMethod...['paymentMethodNonce']) is of type object<Braintree\PaymentMethodNonce>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
270
                "paymentMethodNonce"
0 ignored issues
show
Documentation introduced by
'paymentMethodNonce' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
271
            );
272
        } else if (isset($response['apiErrorResponse'])) {
273
            return new Result\Error($response['apiErrorResponse']);
274
        } else if (is_array($response)) {
275
            return new Result\Successful(
276
                UnknownPaymentMethod::factory($response),
0 ignored issues
show
Documentation introduced by
\Braintree\UnknownPaymen...hod::factory($response) is of type object<Braintree\UnknownPaymentMethod>, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
277
                "paymentMethod"
0 ignored issues
show
Documentation introduced by
'paymentMethod' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
278
            );
279
        } else {
280
            throw new Exception\Unexpected(
281
            'Expected payment method or apiErrorResponse'
282
            );
283
        }
284
    }
285
286
    /**
287
     * verifies that a valid payment method identifier is being used
288
     * @ignore
289
     * @param string $identifier
290
     * @param Optional $string $identifierType type of identifier supplied, default 'token'
0 ignored issues
show
Bug introduced by
There is no parameter named $string. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
291
     * @throws InvalidArgumentException
292
     */
293 View Code Duplication
    private function _validateId($identifier = null, $identifierType = 'token')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
294
    {
295
        if (empty($identifier)) {
296
           throw new InvalidArgumentException(
297
                   'expected payment method id to be set'
298
                   );
299
        }
300
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $identifier)) {
301
            throw new InvalidArgumentException(
302
                    $identifier . ' is an invalid payment method ' . $identifierType . '.'
303
                    );
304
        }
305
    }
306
}
307
class_alias('Braintree\PaymentMethodGateway', 'Braintree_PaymentMethodGateway');
308