Conditions | 11 |
Paths | 16 |
Total Lines | 35 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
22 | public static function writeLog($message, $start_time = null, $end_time = null) |
||
23 | { |
||
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 | self::$logger = wc_get_logger(); |
||
31 | } |
||
32 | |||
33 | $settings = get_option('woocommerce_stripe_settings'); |
||
34 | |||
35 | if (empty($settings) || isset($settings['logging']) && 'yes' !== $settings['logging']) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | if (! is_null($start_time)) { |
||
40 | $formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time); |
||
41 | $end_time = is_null($end_time) ? current_time('timestamp') : $end_time; |
||
42 | $formatted_end_time = date_i18n(get_option('date_format') . ' g:ia', $end_time); |
||
43 | $elapsed_time = round(abs($end_time - $start_time) / 60, 2); |
||
44 | |||
45 | $log_entry = "\n" . '====Pagantis Version: ' . PAGANTIS_VERSION . '====' . "\n"; |
||
46 | $log_entry .= '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
||
47 | $log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
||
48 | } else { |
||
49 | $log_entry = "\n" . '====Pagantis Version: ' . PAGANTIS_VERSION . '====' . "\n"; |
||
50 | $log_entry .= '====Start Log====' . "\n" . $message . "\n" . '====End Log====' . "\n\n"; |
||
51 | } |
||
52 | if (defined('WP_DEBUG') && WP_DEBUG) { |
||
53 | error_log($log_entry); |
||
54 | } |
||
55 | print_r($log_entry); |
||
56 | self::$logger->debug($log_entry, array( 'source' => self::WC_LOG_FILENAME )); |
||
57 | } |
||
60 |