Completed
Push — add/8181-enhanced-google-analy... ( e5de7b...de9980 )
by
unknown
08:23 queued 29s
created

Jetpack_Google_Analytics_Options   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 0

8 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 debug_dump() 0 19 4
1
<?php
2
3
/**
4
* Jetpack_Google_Analytics_Options provides a single interface to module options
5
*
6
* @author allendav 
7
*/
8
9
/**
10
* Bail if accessed directly
11
*/
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit;
14
}
15
16
class Jetpack_Google_Analytics_Options {
17
	public static function get_option( $option_name, $default = false ) {
18
		$o = get_option( 'jetpack_wga' );
19
		return isset( $o[ $option_name ] ) ? $o[ $option_name ] : $default;
20
	}
21
22
	public static function get_tracking_code() {
23
		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...
24
	}
25
26
	public static function has_tracking_code() {
27
		$code = self::get_tracking_code();
28
		return ! empty( $code );
29
	}
30
31
	// Options used by both legacy and universal analytics
32
	public static function anonymize_ip_is_enabled() {
33
		return self::get_option( 'anonymize_ip' );
34
	}
35
36
	// eCommerce options used by both legacy and universal analytics
37
	public static function track_purchases_is_enabled() {
38
		return self::get_option( 'ec_track_purchases' );
39
	}
40
41
	public static function track_add_to_cart_is_enabled() {
42
		return self::get_option( 'ec_track_add_to_cart' );
43
	}
44
45
	// Enhanced eCommerce options
46
	public static function enhanced_ecommerce_tracking_is_enabled() {
47
		return self::get_option( 'enh_ec_tracking' );
48
	}
49
50
	public static function debug_dump() {
51
		$messages = array( 'Jetpack_Google_Analytics_Options' );
52
		$tracking_code = self::has_tracking_code() ? self::get_tracking_code() : '(empty)';
53
		array_push( $messages, "get_tracking_code: $tracking_code" );
54
55
		$flags = array(
56
			'anonymize_ip_is_enabled',
57
			'track_purchases_is_enabled',
58
			'track_add_to_cart_is_enabled',
59
			'enhanced_ecommerce_tracking_is_enabled',
60
		);
61
62
		foreach( $flags as $flag ) {
63
			$value = call_user_func( 'Jetpack_Google_Analytics_Options::' . $flag ) ? 'true' : 'false';
64
			array_push( $messages, "$flag: $value" );
65
		}
66
67
		return $messages;
68
	}
69
}