Test Failed
Push — master ( 315839...9b266f )
by Devin
05:39
created

Give_Stripe_Invoice   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 72.97 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 27
loc 37
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A retrieve() 27 27 2

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
/**
3
 * Give - Stripe Core Gateway
4
 *
5
 * @since 2.5.0
6
 *
7
 * @package    Give
8
 * @subpackage Stripe Core
9
 * @copyright  Copyright (c) 2019, GiveWP
10
 * @license    https://opensource.org/licenses/gpl-license GNU Public License
11
 */
12
13
// Exit, if accessed directly.
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit;
16
}
17
18
/**
19
 * Check for class Give_Stripe_Invoices exists.
20
 *
21
 * @since 2.5.0
22
 */
23
if ( ! class_exists( 'Give_Stripe_Invoice' ) ) {
24
25
	class Give_Stripe_Invoice {
26
27
		/**
28
		 * Retrieve Invoice/
29
		 *
30
		 * @param string $id Invoice ID.
31
		 *
32
		 * @return \Stripe\Invoice
33
		 */
34 View Code Duplication
		public function retrieve( $id ) {
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...
35
			try {
36
37
				// Set Application Information.
38
				give_stripe_set_app_info();
39
40
				// Retrieve Invoice by ID.
41
				$invoice = \Stripe\Invoice::retrieve( $id );
42
			} catch( Exception $e ) {
43
44
				// Something went wrong outside of Stripe.
45
				give_record_gateway_error(
46
					__( 'Stripe - Invoices Error', 'give' ),
47
					sprintf(
48
						/* translators: %s Exception Message. */
49
						__( 'An error while retrieving invoice. Details: %s', 'give' ),
50
						$e->getMessage()
51
					)
52
				);
53
				give_set_error( 'Stripe Error', __( 'An error occurred while retrieving invoice. Please try again.', 'give' ) );
54
				give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) );
55
56
				 return false;
57
			}
58
59
			return $invoice;
60
		}
61
	}
62
}
63