Test Failed
Push — refactor/donation-detail-page ( 60fbd3 )
by Ravinder
05:30
created

Give_Donation_Detail_Page::render()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 80
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 34
nc 4
nop 0
dl 0
loc 80
rs 8.5454
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * View Donation Details
4
 *
5
 * @package     Give
6
 * @subpackage  Admin/Payments
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17 View Code Duplication
if ( ! current_user_can( 'view_give_payments' ) ) {
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...
18
	wp_die(
19
		__( 'Sorry, you are not allowed to access this page.', 'give' ), __( 'Error', 'give' ), array(
20
			'response' => 403,
21
		)
22
	);
23
}
24
25
class Give_Donation_Detail_Page {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
26
27
	/**
28
	 * Donation onbect.
29
	 *
30
	 * @since  2.1.0
31
	 * @access private
32
	 *
33
	 * @var Give_Payment
34
	 */
35
	private $donation;
36
37
	/**
38
	 * Instance.
39
	 *
40
	 * @since  2.1.0
41
	 * @access private
42
	 * @var
43
	 */
44
	static private $instance;
45
46
	/**
47
	 * Singleton pattern.
48
	 *
49
	 * @since  2.1.0
50
	 * @access private
51
	 */
52
	private function __construct() {
53
	}
54
55
56
	/**
57
	 * Get instance.
58
	 *
59
	 * @since  2.1.0
60
	 * @access static
61
	 * @return Give_Donation_Detail_Page
62
	 */
63
	public static function get_instance() {
64
		if ( null === static::$instance ) {
65
			self::$instance = new static();
66
67
			self::$instance->render();
68
		}
69
70
		return self::$instance;
71
	}
72
73
	/**
74
	 * Render donation detail page
75
	 *
76
	 * @since  2.1.0
77
	 * @access public
78
	 */
79
	public function render() {
80
		// Page validation.
81
		if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
82
			wp_die(
83
				__( 'Donation ID not supplied. Please try again.', 'give' ),
84
				__( 'Error', 'give' ),
85
				array( 'response' => 400 )
86
			);
87
		}
88
89
		$this->donation = new Give_Payment( absint( $_GET['id'] ) );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
90
91
		// Verify Donation.
92
		if ( ! $this->donation->ID ) {
93
			wp_die(
94
				__( 'The specified ID does not belong to a donation. Please try again.', 'give' ),
95
				__( 'Error', 'give' ),
96
				array( 'response' => 400 )
97
			);
98
		}
99
		?>
100
		<div class="wrap give-wrap">
101
102
			<?php include_once 'view/header.php'; ?>
103
104
			<form id="give-edit-order-form" method="post">
105
106
				<?php
107
				/**
108
				 * Fires in donation details page, in the form before the order details.
109
				 *
110
				 * @since 1.0
111
				 *
112
				 * @param int $payment_id Payment id.
113
				 */
114
				do_action( 'give_view_donation_details_form_top', $this->donation->ID );
115
				?>
116
117
				<div id="poststuff">
118
					<div id="give-dashboard-widgets-wrap">
119
						<div id="post-body" class="metabox-holder columns-2">
120
							<?php include_once 'view/sidebar.php'; ?>
121
							<?php include_once 'view/main-content.php'; ?>
122
						</div>
123
						<!-- /#post-body -->
124
					</div>
125
					<!-- #give-dashboard-widgets-wrap -->
126
				</div>
127
				<!-- /#post-stuff -->
128
129
				<?php
130
				/**
131
				 * Fires in donation details page, in the form after the order details.
132
				 *
133
				 * @since 1.0
134
				 *
135
				 * @param int $payment_id Payment id.
136
				 */
137
				do_action( 'give_view_donation_details_form_bottom', $this->donation->ID );
138
139
				wp_nonce_field( 'give_update_payment_details_nonce' );
140
				?>
141
142
				<input type="hidden" name="give_payment_id" value="<?php echo esc_attr( $this->donation->ID ); ?>"/>
143
				<input type="hidden" name="give_action" value="update_payment_details"/>
144
			</form>
145
146
			<?php
147
			/**
148
			 * Fires in donation details page, after the order form.
149
			 *
150
			 * @since 1.0
151
			 *
152
			 * @param int $payment_id Payment id.
153
			 */
154
			do_action( 'give_view_donation_details_after', $this->donation->ID );
155
			?>
156
		</div><!-- /.wrap -->
157
		<?php
158
	}
159
}
160
161
Give_Donation_Detail_Page::get_instance();