Completed
Push — master ( 409d21...32c778 )
by
unknown
12:55
created

wps_statistics_ctr   C

Complexity

Total Complexity 56

Size/Duplication

Total Lines 339
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 339
rs 6.5957
c 0
b 0
f 0
wmc 56
lcom 1
cbo 2

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A add_scripts() 0 15 3
B wps_statistics_meta_box_content() 0 13 5
B wps_statistics_save_customer_infos() 0 12 8
A register_stats_menu() 0 4 1
D wps_display_statistics() 0 39 10
A get_average_time_between_orders() 0 18 3
B check_current_time_since_last_order() 0 26 4
B wps_display_main_statistics() 0 39 3
C wps_display_custom_statistics() 0 74 13
B wps_statistics_custom_date_view() 0 23 5

How to fix   Complexity   

Complex Class

Complex classes like wps_statistics_ctr often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use wps_statistics_ctr, and based on these observations, apply Extract Interface, too.

1
<?php if ( ! defined( 'ABSPATH' ) ) { exit;
2
}
3
4
class wps_statistics_ctr {
5
6
7
	private $wps_stats_mdl;
8
9
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
10
11
		// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
12
		add_action( 'admin_menu', array( &$this, 'register_stats_menu' ), 250 );
13
		add_action( 'save_post', array( &$this, 'wps_statistics_save_customer_infos' ), 10, 2 );
14
		add_action( 'post_submitbox_misc_actions', array( $this, 'wps_statistics_meta_box_content' ) );
15
16
		// Add Javascript Files & CSS File in admin
17
		add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
18
19
		add_action( 'wp_ajax_wps_statistics_custom_date_view', array( $this, 'wps_statistics_custom_date_view' ) );
20
21
		$this->wps_stats_mdl = new wps_statistics_mdl();
22
	}
23
24
	/**
25
	 * Add Javascript & CSS files
26
	 */
27
	function add_scripts( $hook ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
29
		global $current_screen;
30
		if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) && $hook != 'wpshop_shop_order_page_wpshop_statistics' ) {
31
			return;
32
		}
33
34
		wp_enqueue_script( 'wps_statistics_js_chart', WPSHOP_JS_URL . 'Chart.js' );
35
		wp_enqueue_script( 'jquery' );
36
		wp_enqueue_script( 'jquery-ui-datepicker' );
37
		 wp_enqueue_script( 'jquery-form' );
38
39
		 wp_register_style( 'jquery-ui-wpsstats', '//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css', '', WPSHOP_VERSION );
40
		wp_enqueue_style( 'jquery-ui-wpsstats' );
41
	}
42
43
	/**
44
	 * Meta box content to exclude customers of statistics
45
	 *
46
	 * @param  WP_Post $post    Définition complète du post actuellement en cours de modification / Current edited post entire definition.
47
	 */
48
	function wps_statistics_meta_box_content( $post ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
		if ( ! empty( $post ) && WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS !== $post->post_type ) {
50
			return;
51
		}
52
		$user_meta = '';
53
		if ( ! empty( $post ) && ! empty( $post->post_author ) ) {
54
			$user_meta = get_user_meta( $post->post_author, 'wps_statistics_exclude_customer', true );
55
		}
56
		$output = '<span class="misc-pub-section" ><input type="checkbox" name="wps_statistics_exclude_customer" id="wps_statistics_exclude_customer" ' . checked( $user_meta, true, false ) . '/> <label for="wps_statistics_exclude_customer">' . __( 'Exclude this customer from WPShop Statistics', 'wpshop' ) . '</label></span>';
57
58
		echo $output;
59
		// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
	}
61
62
	/**
63
	 * Save action to exclude customer of statistics
64
	 *
65
	 * @param  integer $post_id L'identifiant du post actuellement en cours de modification / Current edited post identifier.
66
	 * @param  WP_Post $post    Définition complète du post actuellement en cours de modification / Current edited post entire definition.
67
	 */
68
	function wps_statistics_save_customer_infos( $post_id, $post ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
69
70
		$action = ! empty( $_POST['action'] ) ? sanitize_text_field( $_POST['action'] ) : '';
71
		// WPCS: CSRF ok.
72
		$wps_statistics_exclude_customer = isset( $_POST['wps_statistics_exclude_customer'] ) && ( 'on' === $_POST['wps_statistics_exclude_customer'] ) ? true : false;
73
		// WPCS: CSRF ok.
74
		if ( ( ! empty( $action ) && ( 'autosave' !== $action ) ) && ( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS === get_post_type( $post_id ) ) ) {
75
			if ( isset( $wps_statistics_exclude_customer ) ) {
76
				update_user_meta( $post->post_author, 'wps_statistics_exclude_customer', $wps_statistics_exclude_customer );
77
			}
78
		}
79
	}
80
81
	/**
82
	 * Register statistics Menu
83
	 */
84
	function register_stats_menu() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
85
86
		add_submenu_page( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, __( 'Statistics', 'wpshop' ), __( 'Statistics', 'wpshop' ), 'wpshop_view_statistics', 'wpshop_statistics', array( $this, 'wps_display_statistics' ) );
87
	}
88
89
	/**
90
	 * Display Statistics Interface
91
	 */
92
	function wps_display_statistics() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
93
94
		$shop_orders = $this->wps_stats_mdl->wps_orders_all( );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $shop_orders is correct as $this->wps_stats_mdl->wps_orders_all() (which targets wps_statistics_mdl::wps_orders_all()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
95
96
		$main_stats_count = 5;
97
98
		$ordered_customers = array();
99
		foreach ( $shop_orders as $order ) {
0 ignored issues
show
Bug introduced by
The expression $shop_orders of type null is not traversable.
Loading history...
100
			 $user_id = $order['order_postmeta']['customer_id'];
101
			$wps_statistics_exclude_customer = get_user_meta( $user_id, 'wps_statistics_exclude_customer', true );
102
			$excluded_from_statistics = ( ! empty( $wps_statistics_exclude_customer ) ) ? true : false;
103
104
			if ( false === $excluded_from_statistics ) {
105
				$customer_id = null;
106
				$args = array(
107
					'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
108
					'author' => $user_id,
109
					'orderby' => 'post_date',
110
					'order' => 'ASC',
111
					'post_status' => 'all',
112
					'posts_per_page' => 1,
113
				);
114
				$customer = new WP_Query( $args );
115
116
				if ( ! isset( $ordered_customers[ $user_id ]['count'] ) ) {
117
					$ordered_customers[ $user_id ]['count'] = 0;
118
					$ordered_customers[ $user_id ]['total_amount'] = 0;
119
				}
120
					$ordered_customers[ $user_id ]['count']++;
121
					$ordered_customers[ $user_id ]['id'] = $user_id;
122
					$ordered_customers[ $user_id ]['post_id'] = $customer->post->ID;
123
					$ordered_customers[ $user_id ]['name'] = ( ! empty( $order['order_info'] ) && ! empty( $order['order_info']['billing'] ) && ! empty( $order['order_info']['billing']['address'] ) && ! empty( $order['order_info']['billing']['address']['address_last_name'] ) && ! empty( $order['order_info']['billing']['address']['address_first_name'] ) ) ? $order['order_info']['billing']['address']['address_first_name'] . ' ' . $order['order_info']['billing']['address']['address_last_name'] : '';
124
					;
125
					$ordered_customers[ $user_id ]['total_amount'] += $order['order_postmeta']['order_grand_total'];
126
			}
127
		}
128
129
		require( wpshop_tools::get_template_part( WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, 'backend', 'wps-statistics' ) );
130
	}
131
132
	/**
133
	 * Get the average duration between
134
	 *
135
	 * @param  [type] $order_list [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
136
	 *
137
	 * @return [type]             [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
138
	 */
139
	function get_average_time_between_orders( $order_list ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
140
141
		$time_between_orders = 0;
142
		$last_date = null;
143
		foreach ( $order_list as $order ) {
144
			if ( null !== $last_date ) {
145
				$last_order = new DateTime( $last_date );
146
				$current_order = new DateTime( $order['order_postmeta']['order_date'] );
147
				$time_between_orders += $last_order->getTimestamp() - $current_order->getTimestamp();
148
			} else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
149
150
			}
151
152
			$last_date = $order['order_postmeta']['order_date'];
153
		}
154
155
		return round( $time_between_orders / count( $order_list ) );
156
	}
157
158
	/**
159
	 * Check if the shop is out of bounds for time since last order
160
	 *
161
	 * @return boolean The boolean state allowing to know if the shop is out of bounds for time since last order
162
	 */
163
	function check_current_time_since_last_order( $list_orders ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
164
165
		$average_check = array(
166
			'status' => false,
167
			'last_date' => null,
168
			'average' => null,
169
			'duration' => null,
170
		);
171
		$current_date = new DateTime( current_time( 'Y-m-d H:i:s', 0 ) );
172
173
		if ( ! empty( $list_orders ) ) {
174
			  $last_order = array_slice( $list_orders, 0, 1 );
175
			foreach ( $last_order as $order ) {
176
				$average_check['last_date'] = $order['order_postmeta']['order_date'];
177
			}
178
			 $last_order_dateTime = new DateTime( $average_check['last_date'] );
179
180
			  $duration_since_last_order = $current_date->getTimestamp() - $last_order_dateTime->getTimestamp();
181
			$average_check['duration'] = $duration_since_last_order;
182
			  $average_check['average'] = $this->get_average_time_between_orders( $list_orders );
183
184
			  $average_check['status'] = ( $average_check['duration'] > $average_check['average'] ? true : false );
185
		}
186
187
		return $average_check;
188
	}
189
190
	/**
191
	 * Main Statistics output
192
	 */
193
	function wps_display_main_statistics( $shop_orders = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
194
195
		global $current_month_offset;
196
197
		if ( null === $shop_orders ) {
198
			$shop_orders = $this->wps_stats_mdl->wps_orders_all();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $shop_orders is correct as $this->wps_stats_mdl->wps_orders_all() (which targets wps_statistics_mdl::wps_orders_all()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$shop_orders 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...
199
		}
200
201
		$current_month_offset = (int) current_time( 'm' );
202
		$current_month_offset = isset( $_GET['month'] ) ? (int) $_GET['month'] : $current_month_offset;
203
204
		$current_month_start = date( 'Y-m-d 00:00:00', strtotime( 'first day of this month', time() ) );
205
		$current_month_end = date( 'Y-m-d 23:59:59', strtotime( 'last day of this month', time() ) );
206
207
		$last_month_start = date( 'Y-m-d 00:00:00', strtotime( 'first day of last month', time() ) );
208
		$last_month_end = date( 'Y-m-d 23:59:59', strtotime( 'last day of last month', time() ) );
209
		$one_month_ago = date( 'Y-m-d 23:59:59', strtotime( '-1 month', time() ) );
210
211
		$dates = array(
0 ignored issues
show
Unused Code introduced by
$dates 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...
212
			__( 'Current month', 'wpshop' ) => array(
213
				'after' => $current_month_start,
214
				'before' => $current_month_end,
215
				'inclusive' => true,
216
			),
217
			sprintf( __( 'One month ago (%s)', 'wpshop' ), mysql2date( get_option( 'date_format' ), $one_month_ago, true ) ) => array(
218
				'after' => $last_month_start,
219
				'before' => $one_month_ago,
220
				'inclusive' => true,
221
			),
222
			__( 'Last month', 'wpshop' ) => array(
223
				'after' => $last_month_start,
224
				'before' => $last_month_end,
225
				'inclusive' => true,
226
			),
227
			__( 'From the beginning', 'wpshop' ) => null,
228
		);
229
230
		require_once( wpshop_tools::get_template_part( WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, 'backend', 'wps_statistics_main' ) );
231
	}
232
233
	/**
234
	 * Display custom Statistics area. Allows to choose date for stats displaying
235
	 *
236
	 * @param array  $shop_orders The list of orders to use for stats.
237
	 * @param string $start      Optionnal. The start date to get stats for.
238
	 * @param string $end        Optionnal. The end date to get stats for.
239
	 */
240
	function wps_display_custom_statistics( $shop_orders, $start = null, $end = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
241
242
		$current_month_start = date( 'Y-m-d', strtotime( 'first day of this month', time() ) );
243
		$current_month_end = date( 'Y-m-d', strtotime( 'last day of this month', time() ) );
244
245
		$last_month_start = date( 'Y-m-d', strtotime( 'first day of last month', time() ) );
246
		$last_month_end = date( 'Y-m-d', strtotime( 'last day of last month', time() ) );
247
248
		$date_start = null !== $start ? $start : $current_month_start;
249
		$date_end = null !== $end ? $end : $current_month_end;
250
251
		$stats_translations = array(
252
			'numberOfSales' => __( 'Number of sales', 'wpshop' ),
253
			'sales' => __( 'sales', 'wpshop' ),
254
			'salesAmount' => __( 'Sales amount', 'wpshop' ),
255
			'wpshopCurrency' => wpshop_tools::wpshop_get_currency(),
256
		);
257
258
		$orders_total_amount = $orders_total_shipping_cost = $order_count = 0;
259
		$orders_number_stats = $orders_amount_stats = array();
260
		if ( ! empty( $shop_orders ) ) {
261
			foreach ( $shop_orders as $order ) {
262
				$order_data = $order['order_postmeta'];
263
				if ( ( $date_start <= $order_data['order_date'] ) && ( $date_end >= $order_data['order_date'] ) ) {
264
					$orders_total_amount += $order_data['order_grand_total'];
265
					$order_count++;
266
267
					$time = strtotime( date( 'Ymd', strtotime( $order_data['order_date'] ) ) ) . '000';
268
					if ( ! isset( $orders_number_stats[ $time ] ) ) {
269
						$orders_number_stats[ $time ] = 0;
270
					}
271
					$orders_number_stats[ $time ]++;
272
273
					if ( ! isset( $orders_amount_stats[ $time ] ) ) {
274
						$orders_amount_stats[ $time ] = 0;
275
					}
276
					$orders_amount_stats[ $time ] += $order_data['order_grand_total'];
277
278
					$orders_total_shipping_cost += $order_data['order_shipping_cost'];
279
				}
280
			}
281
		}
282
283
		$orders_number_for_stats = null;
284
		if ( ! empty( $orders_number_stats ) ) {
285
			$orders_numbers = array();
286
			foreach ( $orders_number_stats as $time => $number ) {
287
				$orders_numbers[] = "[$time, $number]";
288
			}
289
			$orders_number_for_stats = implode( ',', $orders_numbers );
290
		}
291
292
		$orders_amount_for_stats = null;
293
		if ( ! empty( $orders_amount_stats ) ) {
294
			$orders_amounts = array();
295
			foreach ( $orders_amount_stats as $time => $amount ) {
296
				$orders_amounts[] = "[$time, $amount]";
297
			}
298
			$orders_amount_for_stats = implode( ',', $orders_amounts );
299
		}
300
301
		$user_subscription_number = new WP_User_Query( array(
302
			'date_query' => array(
303
				array(
304
					'after' => $date_start,
305
					'before' => $date_end,
306
					'inclusive' => true,
307
				),
308
			),
309
			'count_total' => true,
310
		) );
311
312
		require( wpshop_tools::get_template_part( WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, 'backend', 'wps_statistics_custom' ) );
313
	}
314
315
	/**
316
	 * Ajax callback - Display custom statistics for given date
317
	 */
318
	function wps_statistics_custom_date_view() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
319
320
		check_ajax_referer( 'wps_statistics_custom_date_view' );
321
322
		$start_date = ! empty( $_POST ) && ! empty( $_POST['wps_statistics_start_date'] ) ? sanitize_text_field( $_POST['wps_statistics_start_date'] ) : date( 'Y-m-d', strtotime( 'first day of this month', time() ) );
323
		$end_date = ! empty( $_POST ) && ! empty( $_POST['wps_statistics_end_date'] ) ? sanitize_text_field( $_POST['wps_statistics_end_date'] ) : date( 'Y-m-d', strtotime( 'last day of this month', time() ) );
324
325
		$order_list = $this->wps_stats_mdl->wps_orders_all( array(
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $order_list is correct as $this->wps_stats_mdl->wp...'inclusive' => true)))) (which targets wps_statistics_mdl::wps_orders_all()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
326
			'date_query' => array(
327
				array(
328
					'after' => $date_start,
0 ignored issues
show
Bug introduced by
The variable $date_start does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
329
					'before' => $date_end,
0 ignored issues
show
Bug introduced by
The variable $date_end does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
330
					'inclusive' => true,
331
				),
332
			),
333
		) );
334
335
		ob_start();
336
		$this->wps_display_custom_statistics( $order_list, $start_date, $end_date );
0 ignored issues
show
Documentation introduced by
$order_list is of type null, but the function expects a array.

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...
337
		$output = ob_get_clean();
338
339
		wp_die( $output );
340
	}
341
342
}
343