From 8e9539b0c2d18db963ae4bd061335dd5634139c9 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 20 Jan 2015 09:53:33 +0000 Subject: [PATCH] scrutinizer issues in sales-by-category report --- .../class-wc-report-sales-by-category.php | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/includes/admin/reports/class-wc-report-sales-by-category.php b/includes/admin/reports/class-wc-report-sales-by-category.php index b09aa449e9e..42a676c5e0d 100644 --- a/includes/admin/reports/class-wc-report-sales-by-category.php +++ b/includes/admin/reports/class-wc-report-sales-by-category.php @@ -9,18 +9,17 @@ */ class WC_Report_Sales_By_Category extends WC_Admin_Report { - public $chart_colours = array(); - public $show_categories = array(); + public $chart_colours = array(); + public $show_categories = array(); + private $item_sales = array(); + private $item_sales_and_times = array(); /** * Constructor */ public function __construct() { - - if ( isset( $_GET['show_categories'] ) && is_array( $_GET['show_categories'] ) ) { - $this->show_categories = array_map( 'absint', $_GET['show_categories'] ); - } elseif ( isset( $_GET['show_categories'] ) ) { - $this->show_categories = array( absint( $_GET['show_categories'] ) ); + if ( isset( $_GET['show_categories'] ) ) { + $this->show_categories = is_array( $_GET['show_categories'] ) ? array_map( 'absint', $_GET['show_categories'] ) : array( absint( $_GET['show_categories'] ) ); } } @@ -129,17 +128,16 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report { $this->item_sales = array(); $this->item_sales_and_times = array(); - if ( $order_items ) { + if ( is_array( $order_items ) ) { foreach ( $order_items as $order_item ) { switch ( $this->chart_groupby ) { - case 'day' : $time = strtotime( date( 'Ymd', strtotime( $order_item->post_date ) ) ) * 1000; break; - case 'month' : + default : $time = strtotime( date( 'Ym', strtotime( $order_item->post_date ) ) . '01' ) * 1000; break; } @@ -274,12 +272,11 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report { $interval_total = 0; switch ( $this->chart_groupby ) { - case 'day' : $time = strtotime( date( 'Ymd', strtotime( "+{$i} DAY", $this->start_date ) ) ) * 1000; break; - case 'month' : + default : $time = strtotime( date( 'Ym', strtotime( "+{$i} MONTH", $this->start_date ) ) . '01' ) * 1000; break; }