Completed
Push — add/8181-enhanced-google-analy... ( 492986...fd7aed )
by
unknown
36:24 queued 28:55
created

Jetpack_Google_Analytics_Options   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 79
rs 10
c 0
b 0
f 0
wmc 17
lcom 1
cbo 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A get_option() 0 4 2
A get_tracking_code() 0 3 1
A has_tracking_code() 0 4 1
A anonymize_ip_is_enabled() 0 3 1
A track_purchases_is_enabled() 0 3 1
A track_add_to_cart_is_enabled() 0 3 1
A enhanced_ecommerce_tracking_is_enabled() 0 3 1
A track_remove_from_cart_is_enabled() 0 3 1
A track_product_impressions_is_enabled() 0 3 1
A track_product_clicks_is_enabled() 0 3 1
A track_product_detail_view_is_enabled() 0 3 1
A track_checkout_started_is_enabled() 0 3 1
B debug_dump() 0 24 4
1
<?php
2
3
4
/**
5
* Jetpack_Google_Analytics_Options provides a single interface to module options
6
*
7
* @author allendav 
8
*/
9
10
/**
11
* Bail if accessed directly
12
*/
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
class Jetpack_Google_Analytics_Options {
18
	public static function get_option( $option_name, $default = false ) {
19
		$o = get_option( 'jetpack_wga' );
20
		return isset( $o[ $option_name ] ) ? $o[ $option_name ] : $default;
21
	}
22
23
	public static function get_tracking_code() {
24
		return self::get_option( 'code', '' );
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
	}
26
27
	public static function has_tracking_code() {
28
		$code = self::get_tracking_code();
29
		return ! empty( $code );
30
	}
31
32
	// Options used by both legacy and universal analytics
33
	public static function anonymize_ip_is_enabled() {
34
		return self::get_option( 'anonymize_ip' );
35
	}
36
37
	// eCommerce options used by both legacy and universal analytics
38
	public static function track_purchases_is_enabled() {
39
		return self::get_option( 'ec_track_purchases' );
40
	}
41
42
	public static function track_add_to_cart_is_enabled() {
43
		return self::get_option( 'ec_track_add_to_cart' );
44
	}
45
46
	// Enhanced eCommerce options
47
	public static function enhanced_ecommerce_tracking_is_enabled() {
48
		return self::get_option( 'enh_ec_tracking' );
49
	}
50
51
	public static function track_remove_from_cart_is_enabled() {
52
		return self::get_option( 'enh_ec_track_remove_from_cart' );
53
	}
54
55
	public static function track_product_impressions_is_enabled() {
56
		return self::get_option( 'enh_ec_track_prod_impression' );
57
	}
58
59
	public static function track_product_clicks_is_enabled() {
60
		return self::get_option( 'enh_ec_track_prod_click' );
61
	}
62
63
	public static function track_product_detail_view_is_enabled() {
64
		return self::get_option( 'enh_ec_track_prod_detail_view' );
65
	}
66
67
	public static function track_checkout_started_is_enabled() {
68
		return self::get_option( 'enh_ec_track_checkout_started' );
69
	}
70
71
	public static function debug_dump() {
72
		$messages = array( 'Jetpack_Google_Analytics_Options' );
73
		$tracking_code = self::has_tracking_code() ? self::get_tracking_code() : '(empty)';
74
		array_push( $messages, "get_tracking_code: $tracking_code" );
75
76
		$flags = array(
77
			'anonymize_ip_is_enabled',
78
			'track_purchases_is_enabled',
79
			'track_add_to_cart_is_enabled',
80
			'enhanced_ecommerce_tracking_is_enabled',
81
			'track_remove_from_cart_is_enabled',
82
			'track_product_impressions_is_enabled',
83
			'track_product_clicks_is_enabled',
84
			'track_product_detail_view_is_enabled',
85
			'track_checkout_started_is_enabled',
86
		);
87
88
		foreach( $flags as $flag ) {
89
			$value = call_user_func( 'Jetpack_Google_Analytics_Options::' . $flag ) ? 'true' : 'false';
90
			array_push( $messages, "$flag: $value" );
91
		}
92
93
		return $messages;
94
	}
95
}