| Conditions | 4 |
| Paths | 4 |
| Total Lines | 80 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 79 | public function render() { |
||
| 80 | // Page validation. |
||
| 81 | if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
||
| 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'] ) ); |
||
| 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 | } |
||
| 161 | Give_Donation_Detail_Page::get_instance(); |
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.