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

Jetpack_Google_Analytics   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 4
A get_instance() 0 7 2
1
<?php
2
/*
3
    Copyright 2006 Aaron D. Campbell (email : [email protected])
4
5
    This program is free software; you can redistribute it and/or modify
6
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation; either version 2 of the License, or
8
    (at your option) any later version.
9
10
    This program is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU General Public License for more details.
14
15
    You should have received a copy of the GNU General Public License
16
    along with this program; if not, write to the Free Software
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
*/
19
20
/**
21
 * Jetpack_Google_Analytics is the class that handles ALL of the plugin functionality.
22
 * It helps us avoid name collisions
23
 * http://codex.wordpress.org/Writing_a_Plugin#Avoiding_Function_Name_Collisions
24
 */
25
26
if ( ! defined( 'ABSPATH' ) ) {
27
	exit;
28
}
29
30
require_once( plugin_basename( 'classes/wp-google-analytics-options.php' ) );
31
require_once( plugin_basename( 'classes/wp-google-analytics-legacy.php' ) );
32
require_once( plugin_basename( 'classes/wp-google-analytics-universal.php' ) );
33
34
class Jetpack_Google_Analytics {
35
36
	/**
37
	 * @var Jetpack_Google_Analytics - Static property to hold our singleton instance
38
	 */
39
	static $instance = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $instance.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
40
41
	/**
42
	 * @var Static property to hold concrete analytics impl that does the work (universal or legacy)
43
	 */
44
	static $analytics = false;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $analytics.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
45
46
	/**
47
	 * This is our constructor, which is private to force the use of get_instance()
48
	 *
49
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
50
	 */
51
	private function __construct() {
52
		if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
53
			error_log( print_r( Jetpack_Google_Analytics_Options::debug_dump(), true ) );
54
		}
55
56
		if ( Jetpack_Google_Analytics_Options::enhanced_ecommerce_tracking_is_enabled() ) {
57
			$analytics = new Jetpack_Google_Analytics_Universal();
0 ignored issues
show
Unused Code introduced by
$analytics is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
		} else {
59
			$analytics = new Jetpack_Google_Analytics_Legacy();
0 ignored issues
show
Unused Code introduced by
$analytics is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
		}
61
62
	}
63
64
	/**
65
	 * Function to instantiate our class and make it a singleton
66
	 */
67
	public static function get_instance() {
68
		if ( ! self::$instance ) {
69
			self::$instance = new self;
70
		}
71
72
		return self::$instance;
73
	}
74
}
75
76
global $jetpack_google_analytics;
77
$jetpack_google_analytics = Jetpack_Google_Analytics::get_instance();
78