Passed
Pull Request — master (#48)
by
unknown
04:00
created

WCPagantisLogger   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 11

1 Method

Rating   Name   Duplication   Size   Complexity  
B writeLog() 0 35 11
1
<?php
2
3
if (!defined('ABSPATH')) {
4
    exit; // Exit if accessed directly
5
}
6
7
8
class WCPagantisLogger
9
{
10
11
    public static $logger;
12
    const WC_LOG_FILENAME = 'pagantis-wc';
13
14
    /**
15
     * Utilize WC logger class
16
     *
17
     * @param $message
18
     * @param null $start_time
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $start_time is correct as it would always require null to be passed?
Loading history...
19
     * @param null $end_time
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $end_time is correct as it would always require null to be passed?
Loading history...
20
     * @since 8.6.7
21
     */
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)) {
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        if (/** @scrutinizer ignore-call */ apply_filters('wc_stripe_logging', true, $message)) {
Loading history...
29
            if (empty(self::$logger)) {
30
                    self::$logger = wc_get_logger();
0 ignored issues
show
Bug introduced by
The function wc_get_logger was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
                    self::$logger = /** @scrutinizer ignore-call */ wc_get_logger();
Loading history...
31
            }
32
33
            $settings = get_option('woocommerce_stripe_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_stripe_settings');
Loading history...
34
35
            if (empty($settings) || isset($settings['logging']) && 'yes' !== $settings['logging']) {
36
                return;
37
            }
38
39
            if (! is_null($start_time)) {
0 ignored issues
show
introduced by
The condition is_null($start_time) is always true.
Loading history...
40
                $formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time);
0 ignored issues
show
Bug introduced by
The function date_i18n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
                $formatted_start_time = /** @scrutinizer ignore-call */ date_i18n(get_option('date_format') . ' g:ia', $start_time);
Loading history...
41
                $end_time             = is_null($end_time) ? current_time('timestamp') : $end_time;
0 ignored issues
show
Bug introduced by
The function current_time was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
                $end_time             = is_null($end_time) ? /** @scrutinizer ignore-call */ current_time('timestamp') : $end_time;
Loading history...
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) {
0 ignored issues
show
Bug introduced by
The constant WP_DEBUG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
                error_log($log_entry);
54
            }
55
                print_r($log_entry);
56
                self::$logger->debug($log_entry, array( 'source' => self::WC_LOG_FILENAME ));
57
        }
58
    }
59
}
60