Conditions | 11 |
Paths | 16 |
Total Lines | 36 |
Code Lines | 24 |
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 writeLog($message, $start_time = null, $end_time = null) |
||
24 | { |
||
25 | if (! class_exists('WC_Logger')) { |
||
26 | return; |
||
27 | } |
||
28 | |||
29 | if ($message) { |
||
30 | if (empty(self::$logger)) { |
||
31 | self::$logger = wc_get_logger(); |
||
32 | } |
||
33 | |||
34 | $isDebugLogEnabled = 'yes' === WC_Admin_Settings::get_option('debug', 'no'); |
||
35 | $settings = get_option('woocommerce_pagantis_settings'); |
||
36 | |||
37 | if (empty($settings) || isset($settings['debug']) && $isDebugLogEnabled) { |
||
38 | return; |
||
39 | } |
||
40 | |||
41 | if (! is_null($start_time)) { |
||
42 | $formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time); |
||
43 | $end_time = is_null($end_time) ? current_time('timestamp') : $end_time; |
||
44 | $formatted_end_time = date_i18n(get_option('date_format') . ' g:ia', $end_time); |
||
45 | $elapsed_time = round(abs($end_time - $start_time) / 60, 2); |
||
46 | |||
47 | $log_entry = "\n" . '====Pagantis Version: ' . PAGANTIS_VERSION . '====' . "\n"; |
||
48 | $log_entry .= '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
||
49 | $log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
||
50 | } else { |
||
51 | $log_entry = "\n" . '====Pagantis Version: ' . PAGANTIS_VERSION . '====' . "\n"; |
||
52 | $log_entry .= '====Start Log====' . "\n" . $message . "\n" . '====End Log====' . "\n\n"; |
||
53 | } |
||
54 | if (defined('WP_DEBUG') && WP_DEBUG) { |
||
55 | error_log($log_entry); |
||
56 | } |
||
57 | print_r($log_entry); |
||
58 | self::$logger->debug($log_entry, array( 'source' => self::WC_LOG_FILENAME )); |
||
59 | } |
||
94 |