Conditions | 37 |
Paths | > 20000 |
Total Lines | 109 |
Lines | 27 |
Ratio | 24.77 % |
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_style_notice = get_option( 'wc_stripe_show_style_notice' ); |
||
104 | $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
||
105 | $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
||
106 | $show_3ds_notice = get_option( 'wc_stripe_show_3ds_notice' ); |
||
107 | $show_phpver_notice = get_option( 'wc_stripe_show_phpver_notice' ); |
||
108 | $show_wcver_notice = get_option( 'wc_stripe_show_wcver_notice' ); |
||
109 | $show_curl_notice = get_option( 'wc_stripe_show_curl_notice' ); |
||
110 | $show_sca_notice = get_option( 'wc_stripe_show_sca_notice' ); |
||
111 | $changed_keys_notice = get_option( 'wc_stripe_show_changed_keys_notice' ); |
||
112 | $options = get_option( 'woocommerce_stripe_settings' ); |
||
113 | $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
||
114 | $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
||
115 | $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
||
116 | $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
||
117 | $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
||
118 | $three_d_secure = isset( $options['three_d_secure'] ) && 'yes' === $options['three_d_secure']; |
||
119 | |||
120 | if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
||
121 | if ( empty( $show_3ds_notice ) && $three_d_secure ) { |
||
122 | $url = 'https://stripe.com/docs/payments/3d-secure#three-ds-radar'; |
||
123 | |||
124 | /* translators: 1) A URL that explains Stripe Radar. */ |
||
125 | $message = __( 'WooCommerce Stripe - We see that you had the "Require 3D secure when applicable" setting turned on. This setting is not available here anymore, because it is now replaced by Stripe Radar. You can learn more about it <a href="%s" target="_blank">here</a>.', 'woocommerce-gateway-stripe' ); |
||
126 | |||
127 | $this->add_admin_notice( '3ds', 'notice notice-warning', sprintf( $message, $url ), true ); |
||
128 | } |
||
129 | |||
130 | View Code Duplication | if ( empty( $show_style_notice ) ) { |
|
|
|||
131 | /* translators: 1) int version 2) int version */ |
||
132 | $message = __( 'WooCommerce Stripe - We recently made changes to Stripe that may impact the appearance of your checkout. If your checkout has changed unexpectedly, please follow these <a href="https://docs.woocommerce.com/document/stripe/#styling" target="_blank">instructions</a> to fix.', 'woocommerce-gateway-stripe' ); |
||
133 | |||
134 | $this->add_admin_notice( 'style', 'notice notice-warning', $message, true ); |
||
135 | |||
136 | return; |
||
137 | } |
||
138 | |||
139 | if ( empty( $show_phpver_notice ) ) { |
||
140 | if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
||
141 | /* translators: 1) int version 2) int version */ |
||
142 | $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
||
143 | |||
144 | $this->add_admin_notice( 'phpver', 'error', sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ), true ); |
||
145 | |||
146 | return; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | if ( empty( $show_wcver_notice ) ) { |
||
151 | if ( WC_Stripe_Helper::is_wc_lt( WC_STRIPE_FUTURE_MIN_WC_VER ) ) { |
||
152 | /* translators: 1) int version 2) int version */ |
||
153 | $message = __( 'WooCommerce Stripe - This is the last version of the plugin compatible with WooCommerce %1$s. All furture versions of the plugin will require WooCommerce %2$s or greater.', 'woocommerce-gateway-stripe' ); |
||
154 | $this->add_admin_notice( 'wcver', 'notice notice-warning', sprintf( $message, WC_VERSION, WC_STRIPE_FUTURE_MIN_WC_VER ), true ); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | if ( empty( $show_curl_notice ) ) { |
||
159 | if ( ! function_exists( 'curl_init' ) ) { |
||
160 | $this->add_admin_notice( 'curl', 'notice notice-warning', __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ), true ); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | if ( empty( $show_keys_notice ) ) { |
||
165 | $secret = WC_Stripe_API::get_secret_key(); |
||
166 | |||
167 | if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
||
168 | $setting_link = $this->get_setting_link(); |
||
169 | /* translators: 1) link */ |
||
170 | $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 ); |
||
171 | } |
||
172 | |||
173 | // Check if keys are entered properly per live/test mode. |
||
174 | if ( $testmode ) { |
||
175 | View Code Duplication | if ( |
|
176 | ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
||
177 | || ! empty( $test_secret_key ) && ! preg_match( '/^[rs]k_test_/', $test_secret_key ) ) { |
||
178 | $setting_link = $this->get_setting_link(); |
||
179 | /* translators: 1) link */ |
||
180 | $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 ); |
||
181 | } |
||
182 | View Code Duplication | } else { |
|
183 | if ( |
||
184 | ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
||
185 | || ! empty( $live_secret_key ) && ! preg_match( '/^[rs]k_live_/', $live_secret_key ) ) { |
||
186 | $setting_link = $this->get_setting_link(); |
||
187 | /* translators: 1) link */ |
||
188 | $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your live 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 ); |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | |||
193 | if ( empty( $show_ssl_notice ) ) { |
||
194 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
||
195 | if ( ! wc_checkout_is_https() ) { |
||
196 | /* translators: 1) link */ |
||
197 | $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
||
198 | } |
||
199 | } |
||
200 | |||
201 | View Code Duplication | if ( empty( $show_sca_notice ) ) { |
|
202 | $this->add_admin_notice( 'sca', 'notice notice-success', sprintf( __( 'Stripe is now ready for Strong Customer Authentication (SCA) and 3D Secure 2! <a href="%1$s" target="_blank">Read about SCA</a>', 'woocommerce-gateway-stripe' ), 'https://woocommerce.com/posts/introducing-strong-customer-authentication-sca/' ), true ); |
||
203 | } |
||
204 | |||
205 | if ( 'yes' === $changed_keys_notice ) { |
||
206 | // translators: %s is a the URL for the link. |
||
207 | $this->add_admin_notice( 'changed_keys', 'notice notice-warning', sprintf( __( 'The public and/or secret keys for the Stripe gateway have been changed. This might cause errors for existing customers and saved payment methods. <a href="%s" target="_blank">Click here to learn more</a>.', 'woocommerce-gateway-stripe' ), 'https://docs.woocommerce.com/document/stripe-fixing-customer-errors/' ), true ); |
||
208 | } |
||
209 | } |
||
210 | } |
||
211 | |||
343 |
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.