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/PaymentMethodGateway.php 1 location

@@ 293-305 (lines=13) @@
290
     * @param Optional $string $identifierType type of identifier supplied, default 'token'
291
     * @throws InvalidArgumentException
292
     */
293
    private function _validateId($identifier = null, $identifierType = 'token')
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

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/TransactionGateway.php 1 location

@@ 478-489 (lines=12) @@
475
     * @param string transaction id
476
     * @throws InvalidArgumentException
477
     */
478
    private function _validateId($id = null) {
479
        if (empty($id)) {
480
           throw new InvalidArgumentException(
481
                   'expected transaction id to be set'
482
                   );
483
        }
484
        if (!preg_match('/^[0-9a-z]+$/', $id)) {
485
            throw new InvalidArgumentException(
486
                    $id . ' is an invalid transaction id.'
487
                    );
488
        }
489
    }
490
491
    /**
492
     * generic method for validating incoming gateway responses