| Conditions | 2 |
| Paths | 4 |
| Total Lines | 264 |
| 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 |
||
| 59 | function woocommerce_gateway_stripe_init() { |
||
| 60 | load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
||
| 61 | |||
| 62 | if ( ! class_exists( 'WooCommerce' ) ) { |
||
| 63 | add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' ); |
||
| 64 | return; |
||
| 65 | } |
||
| 66 | |||
| 67 | if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
||
| 68 | add_action( 'admin_notices', 'woocommerce_stripe_wc_not_supported' ); |
||
| 69 | return; |
||
| 70 | } |
||
| 71 | |||
| 72 | if ( ! class_exists( 'WC_Stripe' ) ) : |
||
| 73 | |||
| 74 | class WC_Stripe { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var Singleton The reference the *Singleton* instance of this class |
||
| 78 | */ |
||
| 79 | private static $instance; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Returns the *Singleton* instance of this class. |
||
| 83 | * |
||
| 84 | * @return Singleton The *Singleton* instance. |
||
| 85 | */ |
||
| 86 | public static function get_instance() { |
||
| 87 | if ( null === self::$instance ) { |
||
| 88 | self::$instance = new self(); |
||
|
|
|||
| 89 | } |
||
| 90 | return self::$instance; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Private clone method to prevent cloning of the instance of the |
||
| 95 | * *Singleton* instance. |
||
| 96 | * |
||
| 97 | * @return void |
||
| 98 | */ |
||
| 99 | private function __clone() {} |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Private unserialize method to prevent unserializing of the *Singleton* |
||
| 103 | * instance. |
||
| 104 | * |
||
| 105 | * @return void |
||
| 106 | */ |
||
| 107 | private function __wakeup() {} |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Protected constructor to prevent creating a new instance of the |
||
| 111 | * *Singleton* via the `new` operator from outside of this class. |
||
| 112 | */ |
||
| 113 | private function __construct() { |
||
| 114 | add_action( 'admin_init', array( $this, 'install' ) ); |
||
| 115 | $this->init(); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Init the plugin after plugins_loaded so environment variables are set. |
||
| 120 | * |
||
| 121 | * @since 1.0.0 |
||
| 122 | * @version 4.0.0 |
||
| 123 | */ |
||
| 124 | public function init() { |
||
| 125 | if ( is_admin() ) { |
||
| 126 | require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php'; |
||
| 127 | } |
||
| 128 | |||
| 129 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php'; |
||
| 130 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php'; |
||
| 131 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php'; |
||
| 132 | include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php'; |
||
| 133 | require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; |
||
| 134 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php'; |
||
| 135 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php'; |
||
| 136 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php'; |
||
| 137 | require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; |
||
| 138 | require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php'; |
||
| 139 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; |
||
| 140 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; |
||
| 141 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; |
||
| 142 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'; |
||
| 143 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'; |
||
| 144 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'; |
||
| 145 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'; |
||
| 146 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'; |
||
| 147 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'; |
||
| 148 | require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; |
||
| 149 | require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php'; |
||
| 150 | require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'; |
||
| 151 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php'; |
||
| 152 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php'; |
||
| 153 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php'; |
||
| 154 | require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php'; |
||
| 155 | |||
| 156 | if ( is_admin() ) { |
||
| 157 | require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php'; |
||
| 158 | } |
||
| 159 | |||
| 160 | // REMOVE IN THE FUTURE. |
||
| 161 | require_once dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php'; |
||
| 162 | |||
| 163 | add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
||
| 164 | add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
||
| 165 | add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
||
| 166 | |||
| 167 | // Modify emails emails. |
||
| 168 | add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 ); |
||
| 169 | |||
| 170 | if ( version_compare( WC_VERSION, '3.4', '<' ) ) { |
||
| 171 | add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Updates the plugin version in db |
||
| 177 | * |
||
| 178 | * @since 3.1.0 |
||
| 179 | * @version 4.0.0 |
||
| 180 | */ |
||
| 181 | public function update_plugin_version() { |
||
| 182 | delete_option( 'wc_stripe_version' ); |
||
| 183 | update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Handles upgrade routines. |
||
| 188 | * |
||
| 189 | * @since 3.1.0 |
||
| 190 | * @version 3.1.0 |
||
| 191 | */ |
||
| 192 | public function install() { |
||
| 193 | if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
||
| 194 | return; |
||
| 195 | } |
||
| 196 | |||
| 197 | if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
||
| 198 | do_action( 'woocommerce_stripe_updated' ); |
||
| 199 | |||
| 200 | if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
||
| 201 | define( 'WC_STRIPE_INSTALLING', true ); |
||
| 202 | } |
||
| 203 | |||
| 204 | $this->update_plugin_version(); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Add plugin action links. |
||
| 210 | * |
||
| 211 | * @since 1.0.0 |
||
| 212 | * @version 4.0.0 |
||
| 213 | */ |
||
| 214 | public function plugin_action_links( $links ) { |
||
| 215 | $plugin_links = array( |
||
| 216 | '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
||
| 217 | ); |
||
| 218 | return array_merge( $plugin_links, $links ); |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Add plugin action links. |
||
| 223 | * |
||
| 224 | * @since 4.3.4 |
||
| 225 | * @param array $links Original list of plugin links. |
||
| 226 | * @param string $file Name of current file. |
||
| 227 | * @return array $links Update list of plugin links. |
||
| 228 | */ |
||
| 229 | public function plugin_row_meta( $links, $file ) { |
||
| 230 | if ( plugin_basename( __FILE__ ) === $file ) { |
||
| 231 | $row_meta = array( |
||
| 232 | 'docs' => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_docs_url', 'https://docs.woocommerce.com/document/stripe/' ) ) . '" title="' . esc_attr( __( 'View Documentation', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
||
| 233 | 'support' => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_support_url', 'https://woocommerce.com/my-account/create-a-ticket?select=18627' ) ) . '" title="' . esc_attr( __( 'Open a support request at WooCommerce.com', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
||
| 234 | ); |
||
| 235 | return array_merge( $links, $row_meta ); |
||
| 236 | } |
||
| 237 | return (array) $links; |
||
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Add the gateways to WooCommerce. |
||
| 242 | * |
||
| 243 | * @since 1.0.0 |
||
| 244 | * @version 4.0.0 |
||
| 245 | */ |
||
| 246 | public function add_gateways( $methods ) { |
||
| 247 | if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
||
| 248 | $methods[] = 'WC_Stripe_Subs_Compat'; |
||
| 249 | $methods[] = 'WC_Stripe_Sepa_Subs_Compat'; |
||
| 250 | } else { |
||
| 251 | $methods[] = 'WC_Gateway_Stripe'; |
||
| 252 | $methods[] = 'WC_Gateway_Stripe_Sepa'; |
||
| 253 | } |
||
| 254 | |||
| 255 | $methods[] = 'WC_Gateway_Stripe_Bancontact'; |
||
| 256 | $methods[] = 'WC_Gateway_Stripe_Sofort'; |
||
| 257 | $methods[] = 'WC_Gateway_Stripe_Giropay'; |
||
| 258 | $methods[] = 'WC_Gateway_Stripe_Eps'; |
||
| 259 | $methods[] = 'WC_Gateway_Stripe_Ideal'; |
||
| 260 | $methods[] = 'WC_Gateway_Stripe_P24'; |
||
| 261 | $methods[] = 'WC_Gateway_Stripe_Alipay'; |
||
| 262 | $methods[] = 'WC_Gateway_Stripe_Multibanco'; |
||
| 263 | |||
| 264 | return $methods; |
||
| 265 | } |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Modifies the order of the gateways displayed in admin. |
||
| 269 | * |
||
| 270 | * @since 4.0.0 |
||
| 271 | * @version 4.0.0 |
||
| 272 | */ |
||
| 273 | public function filter_gateway_order_admin( $sections ) { |
||
| 274 | unset( $sections['stripe'] ); |
||
| 275 | unset( $sections['stripe_bancontact'] ); |
||
| 276 | unset( $sections['stripe_sofort'] ); |
||
| 277 | unset( $sections['stripe_giropay'] ); |
||
| 278 | unset( $sections['stripe_eps'] ); |
||
| 279 | unset( $sections['stripe_ideal'] ); |
||
| 280 | unset( $sections['stripe_p24'] ); |
||
| 281 | unset( $sections['stripe_alipay'] ); |
||
| 282 | unset( $sections['stripe_sepa'] ); |
||
| 283 | unset( $sections['stripe_multibanco'] ); |
||
| 284 | |||
| 285 | $sections['stripe'] = 'Stripe'; |
||
| 286 | $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
||
| 287 | $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
||
| 288 | $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
||
| 289 | $sections['stripe_eps'] = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
||
| 290 | $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
||
| 291 | $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
||
| 292 | $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
||
| 293 | $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
||
| 294 | $sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' ); |
||
| 295 | |||
| 296 | return $sections; |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Adds the failed SCA auth email to WooCommerce. |
||
| 301 | * |
||
| 302 | * @param WC_Email[] $email_classes All existing emails. |
||
| 303 | * @return WC_Email[] |
||
| 304 | */ |
||
| 305 | public function add_emails( $email_classes ) { |
||
| 306 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php'; |
||
| 307 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php'; |
||
| 308 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php'; |
||
| 309 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php'; |
||
| 310 | |||
| 311 | // Add all emails, generated by the gateway. |
||
| 312 | $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes ); |
||
| 313 | $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes ); |
||
| 314 | $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes ); |
||
| 315 | |||
| 316 | return $email_classes; |
||
| 317 | } |
||
| 318 | } |
||
| 319 | |||
| 320 | WC_Stripe::get_instance(); |
||
| 321 | endif; |
||
| 322 | } |
||
| 323 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..