| Conditions | 34 |
| Paths | 1728 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 20 |
| Ratio | 39.22 % |
| 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 |
||
| 102 | public function stripe_check_environment() { |
||
| 103 | $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
||
| 104 | $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
||
| 105 | $options = get_option( 'woocommerce_stripe_settings' ); |
||
| 106 | $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
||
| 107 | $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
||
| 108 | $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
||
| 109 | $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
||
| 110 | $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
||
| 111 | |||
| 112 | if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
||
| 113 | $secret = WC_Stripe_API::get_secret_key(); |
||
| 114 | |||
| 115 | if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
||
| 116 | $setting_link = $this->get_setting_link(); |
||
| 117 | /* translators: 1) link */ |
||
| 118 | $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
||
| 119 | } |
||
| 120 | |||
| 121 | // Check if keys are entered properly per live/test mode. |
||
| 122 | if ( $testmode ) { |
||
| 123 | View Code Duplication | if ( |
|
| 124 | ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
||
| 125 | || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
||
| 126 | && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
||
| 127 | { |
||
| 128 | $setting_link = $this->get_setting_link(); |
||
| 129 | /* translators: 1) link */ |
||
| 130 | $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
||
| 131 | } |
||
| 132 | View Code Duplication | } else { |
|
| 133 | if ( |
||
| 134 | ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
||
| 135 | || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
||
| 136 | && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
||
| 137 | { |
||
| 138 | $setting_link = $this->get_setting_link(); |
||
| 139 | /* translators: 1) link */ |
||
| 140 | $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
||
| 146 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
||
| 147 | if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
||
| 148 | /* translators: 1) link 2) link */ |
||
| 149 | $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 252 |
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.