| Conditions | 16 |
| Paths | 97 |
| Total Lines | 178 |
| 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 |
||
| 33 | function give_stripe_credit_card_form( $form_id, $args, $echo = true ) { |
||
| 34 | |||
| 35 | // No CC or billing fields for Stripe Checkout. |
||
| 36 | if ( give_stripe_is_checkout_enabled() ) { |
||
| 37 | return false; |
||
| 38 | } |
||
| 39 | |||
| 40 | $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
||
| 41 | |||
| 42 | $fallback_option = give_get_option( 'stripe_js_fallback' ); |
||
| 43 | $stripe_js_fallback = ! empty( $fallback_option ); |
||
|
|
|||
| 44 | |||
| 45 | $stripe_cc_field_format = give_get_option( 'stripe_cc_fields_format', 'multi' ); |
||
| 46 | |||
| 47 | // Get User Agent. |
||
| 48 | $user_agent = give_get_user_agent(); |
||
| 49 | |||
| 50 | ob_start(); |
||
| 51 | |||
| 52 | do_action( 'give_before_cc_fields', $form_id ); ?> |
||
| 53 | |||
| 54 | <fieldset id="give_cc_fields" class="give-do-validate"> |
||
| 55 | <legend> |
||
| 56 | <?php esc_attr_e( 'Credit Card Info', 'give' ); ?> |
||
| 57 | </legend> |
||
| 58 | |||
| 59 | <?php |
||
| 60 | if ( is_ssl() ) { |
||
| 61 | ?> |
||
| 62 | <div id="give_secure_site_wrapper"> |
||
| 63 | <span class="give-icon padlock"></span> |
||
| 64 | <span> |
||
| 65 | <?php esc_attr_e( 'This is a secure SSL encrypted payment.', 'give' ); ?> |
||
| 66 | </span> |
||
| 67 | </div> |
||
| 68 | <?php |
||
| 69 | } |
||
| 70 | |||
| 71 | if ( |
||
| 72 | ( |
||
| 73 | ! is_ssl() && |
||
| 74 | ! give_is_test_mode() && |
||
| 75 | ( |
||
| 76 | empty( give_stripe_get_publishable_key() ) || |
||
| 77 | empty( give_stripe_get_secret_key() ) |
||
| 78 | ) |
||
| 79 | ) |
||
| 80 | ) { |
||
| 81 | Give()->notices->print_frontend_notice( |
||
| 82 | sprintf( |
||
| 83 | '<strong>%1$s</strong> %2$s', |
||
| 84 | esc_html__( 'Notice:', 'give' ), |
||
| 85 | esc_html__( 'Credit card fields are disabled because Stripe is not connected and your site is not running securely over HTTPS.', 'give' ) |
||
| 86 | ) |
||
| 87 | ); |
||
| 88 | } elseif ( |
||
| 89 | empty( give_stripe_get_publishable_key() ) || |
||
| 90 | empty( give_stripe_get_secret_key() ) |
||
| 91 | ) { |
||
| 92 | Give()->notices->print_frontend_notice( |
||
| 93 | sprintf( |
||
| 94 | '<strong>%1$s</strong> %2$s', |
||
| 95 | esc_html__( 'Notice:', 'give' ), |
||
| 96 | esc_html__( 'Credit card fields are disabled because Stripe is not connected.', 'give' ) |
||
| 97 | ) |
||
| 98 | ); |
||
| 99 | } elseif ( ! is_ssl() && ! give_is_test_mode() ) { |
||
| 100 | Give()->notices->print_frontend_notice( |
||
| 101 | sprintf( |
||
| 102 | '<strong>%1$s</strong> %2$s', |
||
| 103 | esc_html__( 'Notice:', 'give' ), |
||
| 104 | esc_html__( 'Credit card fields are disabled because your site is not running securely over HTTPS.', 'give' ) |
||
| 105 | ) |
||
| 106 | ); |
||
| 107 | } else { |
||
| 108 | if ( 'single' === $stripe_cc_field_format ) { |
||
| 109 | |||
| 110 | // Display the stripe container which can be occupied by Stripe for CC fields. |
||
| 111 | echo '<div id="give-stripe-single-cc-fields-' . esc_html( $id_prefix ) . '" class="give-stripe-single-cc-field-wrap"></div>'; |
||
| 112 | |||
| 113 | } elseif ( 'multi' === $stripe_cc_field_format ) { |
||
| 114 | ?> |
||
| 115 | <div id="give-card-number-wrap" class="form-row form-row-two-thirds form-row-responsive give-stripe-cc-field-wrap"> |
||
| 116 | <div> |
||
| 117 | <label for="give-card-number-field-<?php echo esc_html( $id_prefix ); ?>" class="give-label"> |
||
| 118 | <?php esc_attr_e( 'Card Number', 'give' ); ?> |
||
| 119 | <span class="give-required-indicator">*</span> |
||
| 120 | <span class="give-tooltip give-icon give-icon-question" |
||
| 121 | data-tooltip="<?php esc_attr_e( 'The (typically) 16 digits on the front of your credit card.', 'give' ); ?>"></span> |
||
| 122 | <span class="card-type"></span> |
||
| 123 | </label> |
||
| 124 | <div id="give-card-number-field-<?php echo esc_html( $id_prefix ); ?>" class="input empty give-stripe-cc-field give-stripe-card-number-field"></div> |
||
| 125 | </div> |
||
| 126 | </div> |
||
| 127 | |||
| 128 | <div id="give-card-cvc-wrap" class="form-row form-row-one-third form-row-responsive give-stripe-cc-field-wrap"> |
||
| 129 | <div> |
||
| 130 | <label for="give-card-cvc-field-<?php echo esc_html( $id_prefix ); ?>" class="give-label"> |
||
| 131 | <?php esc_attr_e( 'CVC', 'give' ); ?> |
||
| 132 | <span class="give-required-indicator">*</span> |
||
| 133 | <span class="give-tooltip give-icon give-icon-question" |
||
| 134 | data-tooltip="<?php esc_attr_e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ); ?>"></span> |
||
| 135 | </label> |
||
| 136 | <div id="give-card-cvc-field-<?php echo esc_html( $id_prefix ); ?>" class="input empty give-stripe-cc-field give-stripe-card-cvc-field"></div> |
||
| 137 | </div> |
||
| 138 | </div> |
||
| 139 | |||
| 140 | <div id="give-card-name-wrap" class="form-row form-row-two-thirds form-row-responsive"> |
||
| 141 | <label for="card_name" class="give-label"> |
||
| 142 | <?php esc_attr_e( 'Cardholder Name', 'give' ); ?> |
||
| 143 | <span class="give-required-indicator">*</span> |
||
| 144 | <span class="give-tooltip give-icon give-icon-question" |
||
| 145 | data-tooltip="<?php esc_attr_e( 'The name of the credit card account holder.', 'give' ); ?>"></span> |
||
| 146 | </label> |
||
| 147 | <input |
||
| 148 | type="text" |
||
| 149 | autocomplete="off" |
||
| 150 | id="card_name" |
||
| 151 | name="card_name" |
||
| 152 | class="card-name give-input required" |
||
| 153 | placeholder="<?php esc_attr_e( 'Cardholder Name', 'give' ); ?>" |
||
| 154 | /> |
||
| 155 | </div> |
||
| 156 | |||
| 157 | <?php do_action( 'give_before_cc_expiration' ); ?> |
||
| 158 | |||
| 159 | <div id="give-card-expiration-wrap" class="card-expiration form-row form-row-one-third form-row-responsive give-stripe-cc-field-wrap"> |
||
| 160 | <div> |
||
| 161 | <label for="give-card-expiration-field-<?php echo esc_html( $id_prefix ); ?>" class="give-label"> |
||
| 162 | <?php esc_attr_e( 'Expiration', 'give' ); ?> |
||
| 163 | <span class="give-required-indicator">*</span> |
||
| 164 | <span class="give-tooltip give-icon give-icon-question" |
||
| 165 | data-tooltip="<?php esc_attr_e( 'The date your credit card expires, typically on the front of the card.', 'give' ); ?>"></span> |
||
| 166 | </label> |
||
| 167 | |||
| 168 | <div id="give-card-expiration-field-<?php echo esc_html( $id_prefix ); ?>" class="input empty give-stripe-cc-field give-stripe-card-expiration-field"></div> |
||
| 169 | </div> |
||
| 170 | </div> |
||
| 171 | <?php |
||
| 172 | } // End if(). |
||
| 173 | |||
| 174 | /** |
||
| 175 | * This action hook is used to display content after the Credit Card expiration field. |
||
| 176 | * |
||
| 177 | * Note: Kept this hook as it is. |
||
| 178 | * |
||
| 179 | * @param int $form_id Donation Form ID. |
||
| 180 | * @param array $args List of additional arguments. |
||
| 181 | */ |
||
| 182 | do_action( 'give_after_cc_expiration', $form_id, $args ); |
||
| 183 | |||
| 184 | /** |
||
| 185 | * This action hook is used to display content after the Credit Card expiration field. |
||
| 186 | * |
||
| 187 | * @param int $form_id Donation Form ID. |
||
| 188 | * @param array $args List of additional arguments. |
||
| 189 | */ |
||
| 190 | do_action( 'give_stripe_after_cc_expiration', $form_id, $args ); |
||
| 191 | } |
||
| 192 | ?> |
||
| 193 | </fieldset> |
||
| 194 | <?php |
||
| 195 | // Remove Address Fields if user has option enabled. |
||
| 196 | $billing_fields_enabled = give_get_option( 'stripe_collect_billing' ); |
||
| 197 | if ( ! $billing_fields_enabled ) { |
||
| 198 | remove_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
||
| 199 | } |
||
| 200 | |||
| 201 | do_action( 'give_after_cc_fields', $form_id, $args ); |
||
| 202 | |||
| 203 | $form = ob_get_clean(); |
||
| 204 | |||
| 205 | if ( false !== $echo ) { |
||
| 206 | echo $form; |
||
| 207 | } |
||
| 208 | |||
| 209 | return $form; |
||
| 210 | } |
||
| 211 | |||
| 230 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.