Code Duplication    Length = 12-14 lines in 8 locations

catalog/includes/apps/braintree/lib/Braintree/AddressGateway.php 2 locations

@@ 220-232 (lines=13) @@
217
     * @param string $id address id
218
     * @throws InvalidArgumentException
219
     */
220
    private function _validateId($id = null)
221
    {
222
        if (empty($id) || trim($id) == "") {
223
            throw new InvalidArgumentException(
224
            'expected address id to be set'
225
            );
226
        }
227
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
228
            throw new InvalidArgumentException(
229
            $id . ' is an invalid address id.'
230
            );
231
        }
232
    }
233
234
    /**
235
     * verifies that a valid customer id is being used
@@ 240-253 (lines=14) @@
237
     * @param string $id customer id
238
     * @throws InvalidArgumentException
239
     */
240
    private function _validateCustomerId($id = null)
241
    {
242
        if (empty($id) || trim($id) == "") {
243
            throw new InvalidArgumentException(
244
            'expected customer id to be set'
245
            );
246
        }
247
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
248
            throw new InvalidArgumentException(
249
            $id . ' is an invalid customer id.'
250
            );
251
        }
252
253
    }
254
255
    /**
256
     * determines if a string id or Customer object was passed

catalog/includes/apps/braintree/lib/Braintree/CreditCardGateway.php 1 location

@@ 429-441 (lines=13) @@
426
     * @param Optional $string $identifierType type of identifier supplied, default "token"
427
     * @throws InvalidArgumentException
428
     */
429
    private function _validateId($identifier = null, $identifierType = "token")
430
    {
431
        if (empty($identifier)) {
432
           throw new InvalidArgumentException(
433
                   'expected credit card id to be set'
434
                   );
435
        }
436
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $identifier)) {
437
            throw new InvalidArgumentException(
438
                    $identifier . ' is an invalid credit card ' . $identifierType . '.'
439
                    );
440
        }
441
    }
442
443
    /**
444
     * sends the update request to the gateway

catalog/includes/apps/braintree/lib/Braintree/CustomerGateway.php 1 location

@@ 565-576 (lines=12) @@
562
     * @param string customer id
563
     * @throws InvalidArgumentException
564
     */
565
    private function _validateId($id = null) {
566
        if (is_null($id)) {
567
            throw new InvalidArgumentException(
568
                'expected customer id to be set'
569
            );
570
        }
571
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
572
            throw new InvalidArgumentException(
573
                $id . ' is an invalid customer id.'
574
            );
575
        }
576
    }
577
578
579
    /* private class methods */

catalog/includes/apps/braintree/lib/Braintree/PayPalAccountGateway.php 1 location

@@ 166-178 (lines=13) @@
163
     * @param Optional $string $identifierType type of identifier supplied, default 'token'
164
     * @throws InvalidArgumentException
165
     */
166
    private function _validateId($identifier = null, $identifierType = 'token')
167
    {
168
        if (empty($identifier)) {
169
           throw new InvalidArgumentException(
170
                   'expected paypal account id to be set'
171
                   );
172
        }
173
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $identifier)) {
174
            throw new InvalidArgumentException(
175
                    $identifier . ' is an invalid paypal account ' . $identifierType . '.'
176
                    );
177
        }
178
    }
179
}
180
class_alias('Braintree\PayPalAccountGateway', 'Braintree_PayPalAccountGateway');
181

catalog/includes/apps/braintree/lib/Braintree/SubscriptionGateway.php 1 location

@@ 179-190 (lines=12) @@
176
    /**
177
     * @ignore
178
     */
179
    private function _validateId($id = null) {
180
        if (empty($id)) {
181
           throw new InvalidArgumentException(
182
                   'expected subscription id to be set'
183
                   );
184
        }
185
        if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
186
            throw new InvalidArgumentException(
187
                    $id . ' is an invalid subscription id.'
188
                    );
189
        }
190
    }
191
192
    /**
193
     * @ignore

catalog/includes/apps/braintree/lib/Braintree/PaymentMethodGateway.php 1 location

@@ 318-330 (lines=13) @@
315
     * @param Optional $string $identifierType type of identifier supplied, default 'token'
316
     * @throws InvalidArgumentException
317
     */
318
    private function _validateId($identifier = null, $identifierType = 'token')
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

catalog/includes/apps/braintree/lib/Braintree/TransactionGateway.php 1 location

@@ 488-499 (lines=12) @@
485
     * @param string transaction id
486
     * @throws InvalidArgumentException
487
     */
488
    private function _validateId($id = null) {
489
        if (empty($id)) {
490
           throw new InvalidArgumentException(
491
                   'expected transaction id to be set'
492
                   );
493
        }
494
        if (!preg_match('/^[0-9a-z]+$/', $id)) {
495
            throw new InvalidArgumentException(
496
                    $id . ' is an invalid transaction id.'
497
                    );
498
        }
499
    }
500
501
    /**
502
     * generic method for validating incoming gateway responses