Conditions | 11 |
Paths | 23 |
Total Lines | 44 |
Code Lines | 27 |
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 |
||
23 | public static function log( $message, $start_time = null, $end_time = null ) { |
||
24 | if ( ! class_exists( 'WC_Logger' ) ) { |
||
25 | return; |
||
26 | } |
||
27 | |||
28 | if ( apply_filters( 'wc_stripe_logging', true, $message ) ) { |
||
29 | if ( empty( self::$logger ) ) { |
||
30 | if ( version_compare( WC_VERSION, '3.0.0', '>=' ) ) { |
||
31 | self::$logger = wc_get_logger(); |
||
32 | } else { |
||
33 | self::$logger = new WC_Logger(); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | $settings = get_option( 'woocommerce_stripe_settings' ); |
||
38 | |||
39 | if ( empty( $settings ) || isset( $settings['logging'] ) && 'yes' !== $settings['logging'] ) { |
||
40 | return; |
||
41 | } |
||
42 | |||
43 | if ( ! is_null( $start_time ) ) { |
||
44 | |||
45 | $formatted_start_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $start_time ); |
||
46 | $end_time = is_null( $end_time ) ? current_time( 'timestamp' ) : $end_time; |
||
47 | $formatted_end_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $end_time ); |
||
48 | $elapsed_time = round( abs( $end_time - $start_time ) / 60, 2 ); |
||
49 | |||
50 | $log_entry = "\n" . '====Stripe Version: ' . WC_STRIPE_VERSION . '====' . "\n"; |
||
51 | $log_entry .= '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
||
52 | $log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
||
53 | |||
54 | } else { |
||
55 | $log_entry = "\n" . '====Stripe Version: ' . WC_STRIPE_VERSION . '====' . "\n"; |
||
56 | $log_entry .= '====Start Log====' . "\n" . $message . "\n" . '====End Log====' . "\n\n"; |
||
57 | |||
58 | } |
||
59 | |||
60 | if ( version_compare( WC_VERSION, '3.0.0', '>=' ) ) { |
||
61 | self::$logger->debug( $log_entry, array( 'source' => self::WC_LOG_FILENAME ) ); |
||
62 | } else { |
||
63 | self::$logger->add( self::WC_LOG_FILENAME, $log_entry ); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 |