Completed
Pull Request — 23 (#612)
by Harald
05:38
created

PaymentMethodGateway::_doDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
    public function delete($token, $options=[])
94
    {
95
        Util::verifyKeys(self::deleteSignature(), $options);
96
        $this->_validateId($token);
97
        $queryString = "";
98
        if (!empty($options)) {
99
            $queryString = "?" . http_build_query(Util::camelCaseToDelimiterArray($options, '_'));
100
        }
101
        return $this->_doDelete('/payment_methods/any/' . $token  . $queryString);
102
    }
103
104
    public function grant($sharedPaymentMethodToken, $attribs=[])
105
    {
106
        if (is_bool($attribs) === true) {
107
            $attribs = ['allow_vaulting' => $attribs];
108
        }
109
        $options = [ 'shared_payment_method_token' => $sharedPaymentMethodToken ];
110
111
        return $this->_doCreate(
112
            '/payment_methods/grant',
113
            [
114
                'payment_method' => array_merge($attribs, $options)
115
            ]
116
        );
117
    }
118
119
    public function revoke($sharedPaymentMethodToken)
120
    {
121
        return $this->_doCreate(
122
            '/payment_methods/revoke',
123
            [
124
                'payment_method' => [
125
                    'shared_payment_method_token' => $sharedPaymentMethodToken
126
                ]
127
            ]
128
        );
129
    }
130
131
    private static function baseSignature()
132
    {
133
        $billingAddressSignature = AddressGateway::createSignature();
134
        $optionsSignature = [
135
            'failOnDuplicatePaymentMethod',
136
            'makeDefault',
137
            'verificationMerchantAccountId',
138
            'verifyCard',
139
            'verificationAmount'
140
        ];
141
        return [
142
            'billingAddressId',
143
            'cardholderName',
144
            'cvv',
145
            'deviceData',
146
            'expirationDate',
147
            'expirationMonth',
148
            'expirationYear',
149
            'number',
150
            'paymentMethodNonce',
151
            'token',
152
            ['options' => $optionsSignature],
153
            ['billingAddress' => $billingAddressSignature]
154
        ];
155
    }
156
157
    public static function createSignature()
158
    {
159
        $signature = array_merge(self::baseSignature(), ['customerId']);
160
        return $signature;
161
    }
162
163
    public static function updateSignature()
164
    {
165
        $billingAddressSignature = AddressGateway::updateSignature();
166
        array_push($billingAddressSignature, [
167
            'options' => [
168
                'updateExisting'
169
            ]
170
        ]);
171
        $signature = array_merge(self::baseSignature(), [
172
            'deviceSessionId',
173
            'venmoSdkPaymentMethodCode',
174
            'fraudMerchantId',
175
            ['billingAddress' => $billingAddressSignature]
176
        ]);
177
        return $signature;
178
    }
179
180
    private static function deleteSignature()
181
    {
182
        return ['revokeAllGrants'];
183
    }
184
185
    /**
186
     * sends the create request to the gateway
187
     *
188
     * @ignore
189
     * @param string $subPath
190
     * @param array $params
191
     * @return mixed
192
     */
193 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...
194
    {
195
        $fullPath = $this->_config->merchantPath() . $subPath;
196
        $response = $this->_http->post($fullPath, $params);
197
198
        return $this->_verifyGatewayResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->_http->post($fullPath, $params) on line 196 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...
199
    }
200
201
    /**
202
     * sends the update request to the gateway
203
     *
204
     * @ignore
205
     * @param string $subPath
206
     * @param array $params
207
     * @return mixed
208
     */
209 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...
210
    {
211
        $fullPath = $this->_config->merchantPath() . $subPath;
212
        $response = $this->_http->put($fullPath, $params);
213
214
        return $this->_verifyGatewayResponse($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->_http->put($fullPath, $params) on line 212 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...
215
    }
216
217
218
    /**
219
     * sends the delete request to the gateway
220
     *
221
     * @ignore
222
     * @param string $subPath
223
     * @return mixed
224
     */
225
    public function _doDelete($subPath)
226
    {
227
        $fullPath = $this->_config->merchantPath() . $subPath;
228
        $this->_http->delete($fullPath);
229
        return new Result\Successful();
230
    }
231
232
    /**
233
     * generic method for validating incoming gateway responses
234
     *
235
     * creates a new CreditCard or PayPalAccount object
236
     * and encapsulates it inside a Result\Successful object, or
237
     * encapsulates a Errors object inside a Result\Error
238
     * alternatively, throws an Unexpected exception if the response is invalid.
239
     *
240
     * @ignore
241
     * @param array $response gateway response values
242
     * @return Result\Successful|Result\Error
243
     * @throws Exception\Unexpected
244
     */
245
    private function _verifyGatewayResponse($response)
246
    {
247
        if (isset($response['creditCard'])) {
248
            return new Result\Successful(
249
                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...
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['paypalAccount'])) {
253
            return new Result\Successful(
254
                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...
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['coinbaseAccount'])) {
258
            return new Result\Successful(
259
                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...
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['applePayCard'])) {
263
            return new Result\Successful(
264
                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...
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
        } else if (isset($response['androidPayCard'])) {
268
            return new Result\Successful(
269
                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...
270
                "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...
271
            );
272
        } else if (isset($response['amexExpressCheckoutCard'])) {
273
            return new Result\Successful(
274
                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...
275
                "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...
276
            );
277
        } else if (isset($response['europeBankAccount'])) {
278
            return new Result\Successful(
279
                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...
280
                "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...
281
            );
282
        } else if (isset($response['usBankAccount'])) {
283
            return new Result\Successful(
284
                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...
285
                "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...
286
            );
287
        } else if (isset($response['venmoAccount'])) {
288
            return new Result\Successful(
289
                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...
290
                "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...
291
            );
292 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...
293
            return new Result\Successful(
294
                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...
295
                "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...
296
            );
297
        } else if (isset($response['apiErrorResponse'])) {
298
            return new Result\Error($response['apiErrorResponse']);
299
        } else if (is_array($response)) {
300
            return new Result\Successful(
301
                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...
302
                "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...
303
            );
304
        } else {
305
            throw new Exception\Unexpected(
306
            'Expected payment method or apiErrorResponse'
307
            );
308
        }
309
    }
310
311
    /**
312
     * verifies that a valid payment method identifier is being used
313
     * @ignore
314
     * @param string $identifier
315
     * @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...
316
     * @throws InvalidArgumentException
317
     */
318 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...
319
    {
320
        if (empty($identifier)) {
321
           throw new InvalidArgumentException(
322
                   'expected payment method id to be set'
323
                   );
324
        }
325
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $identifier)) {
326
            throw new InvalidArgumentException(
327
                    $identifier . ' is an invalid payment method ' . $identifierType . '.'
328
                    );
329
        }
330
    }
331
}
332
class_alias('Braintree\PaymentMethodGateway', 'Braintree_PaymentMethodGateway');
333