Merge pull request #19992 from woocommerce/fix/phpcs-class-wc-report-customers

Fix PHPCS violations in includes/admin/reports/class-wc-report-customers.php
This commit is contained in:
Rodrigo Primo 2018-05-07 17:57:57 -03:00 committed by GitHub
commit 3644f8c220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 38 deletions

View File

@ -1,14 +1,17 @@
<?php <?php
/**
* Class WC_Report_Customers file.
*
* @package WooCommerce\Reports
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly exit; // Exit if accessed directly.
} }
/** /**
* WC_Report_Customers * WC_Report_Customers
* *
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Reports * @package WooCommerce/Admin/Reports
* @version 2.1.0 * @version 2.1.0
*/ */
@ -38,7 +41,7 @@ class WC_Report_Customers extends WC_Admin_Report {
$legend[] = array( $legend[] = array(
/* translators: %s: signups amount */ /* translators: %s: signups amount */
'title' => sprintf( __( '%s signups in this period', 'woocommerce' ), '<strong>' . sizeof( $this->customers ) . '</strong>' ), 'title' => sprintf( __( '%s signups in this period', 'woocommerce' ), '<strong>' . count( $this->customers ) . '</strong>' ),
'color' => $this->chart_colours['signups'], 'color' => $this->chart_colours['signups'],
'highlight_series' => 2, 'highlight_series' => 2,
); );
@ -110,8 +113,8 @@ class WC_Report_Customers extends WC_Admin_Report {
<div class="chart-container"> <div class="chart-container">
<div class="chart-placeholder customers_vs_guests pie-chart" style="height:200px"></div> <div class="chart-placeholder customers_vs_guests pie-chart" style="height:200px"></div>
<ul class="pie-chart-legend"> <ul class="pie-chart-legend">
<li style="border-color: <?php echo $this->chart_colours['customers']; ?>"><?php _e( 'Customer sales', 'woocommerce' ); ?></li> <li style="border-color: <?php echo esc_attr( $this->chart_colours['customers'] ); ?>"><?php esc_html_e( 'Customer sales', 'woocommerce' ); ?></li>
<li style="border-color: <?php echo $this->chart_colours['guests']; ?>"><?php _e( 'Guest sales', 'woocommerce' ); ?></li> <li style="border-color: <?php echo esc_attr( $this->chart_colours['guests'] ); ?>"><?php esc_html_e( 'Guest sales', 'woocommerce' ); ?></li>
</ul> </ul>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
@ -120,14 +123,14 @@ class WC_Report_Customers extends WC_Admin_Report {
jQuery('.chart-placeholder.customers_vs_guests'), jQuery('.chart-placeholder.customers_vs_guests'),
[ [
{ {
label: '<?php _e( 'Customer orders', 'woocommerce' ); ?>', label: '<?php esc_html_e( 'Customer orders', 'woocommerce' ); ?>',
data: "<?php echo $customer_order_totals->total_orders; ?>", data: "<?php echo esc_html( $customer_order_totals->total_orders ); ?>",
color: '<?php echo $this->chart_colours['customers']; ?>' color: '<?php echo esc_html( $this->chart_colours['customers'] ); ?>'
}, },
{ {
label: '<?php _e( 'Guest orders', 'woocommerce' ); ?>', label: '<?php esc_html_e( 'Guest orders', 'woocommerce' ); ?>',
data: "<?php echo $guest_order_totals->total_orders; ?>", data: "<?php echo esc_html( $guest_order_totals->total_orders ); ?>",
color: '<?php echo $this->chart_colours['guests']; ?>' color: '<?php echo esc_html( $this->chart_colours['guests'] ); ?>'
} }
], ],
{ {
@ -144,7 +147,7 @@ class WC_Report_Customers extends WC_Admin_Report {
} }
}, },
enable_tooltip: true, enable_tooltip: true,
append_tooltip: "<?php echo ' ' . __( 'orders', 'woocommerce' ); ?>", append_tooltip: "<?php echo esc_html( ' ' . __( 'orders', 'woocommerce' ) ); ?>",
}, },
legend: { legend: {
show: false show: false
@ -176,9 +179,9 @@ class WC_Report_Customers extends WC_Admin_Report {
'guests' => '#8fdece', 'guests' => '#8fdece',
); );
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day'; $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day';
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) { if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ), true ) ) {
$current_range = '7day'; $current_range = '7day';
} }
@ -222,17 +225,17 @@ class WC_Report_Customers extends WC_Admin_Report {
*/ */
public function get_export_button() { public function get_export_button() {
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day'; $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day';
?> ?>
<a <a
href="#" href="#"
download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo date_i18n( 'Y-m-d', current_time( 'timestamp' ) ); ?>.csv" download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo esc_attr( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ); ?>.csv"
class="export_csv" class="export_csv"
data-export="chart" data-export="chart"
data-xaxes="<?php esc_attr_e( 'Date', 'woocommerce' ); ?>" data-xaxes="<?php esc_attr_e( 'Date', 'woocommerce' ); ?>"
data-groupby="<?php echo $this->chart_groupby; ?>" data-groupby="<?php echo esc_attr( $this->chart_groupby ); ?>"
> >
<?php _e( 'Export CSV', 'woocommerce' ); ?> <?php esc_html_e( 'Export CSV', 'woocommerce' ); ?>
</a> </a>
<?php <?php
} }
@ -303,13 +306,10 @@ class WC_Report_Customers extends WC_Admin_Report {
$customer_orders = $this->prepare_chart_data( $customer_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby ); $customer_orders = $this->prepare_chart_data( $customer_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby );
$guest_orders = $this->prepare_chart_data( $guest_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby ); $guest_orders = $this->prepare_chart_data( $guest_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby );
// Encode in json format $chart_data = array(
$chart_data = json_encode( 'signups' => array_values( $signups ),
array( 'customer_orders' => array_values( $customer_orders ),
'signups' => array_values( $signups ), 'guest_orders' => array_values( $guest_orders ),
'customer_orders' => array_values( $customer_orders ),
'guest_orders' => array_values( $guest_orders ),
)
); );
?> ?>
<div class="chart-container"> <div class="chart-container">
@ -319,39 +319,39 @@ class WC_Report_Customers extends WC_Admin_Report {
var main_chart; var main_chart;
jQuery(function(){ jQuery(function(){
var chart_data = jQuery.parseJSON( '<?php echo $chart_data; ?>' ); var chart_data = jQuery.parseJSON( '<?php echo wp_json_encode( $chart_data ); ?>' );
var drawGraph = function( highlight ) { var drawGraph = function( highlight ) {
var series = [ var series = [
{ {
label: "<?php echo esc_js( __( 'Customer orders', 'woocommerce' ) ); ?>", label: "<?php echo esc_js( __( 'Customer orders', 'woocommerce' ) ); ?>",
data: chart_data.customer_orders, data: chart_data.customer_orders,
color: '<?php echo $this->chart_colours['customers']; ?>', color: '<?php echo esc_html( $this->chart_colours['customers'] ); ?>',
bars: { fillColor: '<?php echo $this->chart_colours['customers']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' }, bars: { fillColor: '<?php echo esc_html( $this->chart_colours['customers'] ); ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo esc_html( $this->barwidth ); ?> * 0.5, align: 'center' },
shadowSize: 0, shadowSize: 0,
enable_tooltip: true, enable_tooltip: true,
append_tooltip: "<?php echo ' ' . __( 'customer orders', 'woocommerce' ); ?>", append_tooltip: "<?php echo esc_html( ' ' . __( 'customer orders', 'woocommerce' ) ); ?>",
stack: true, stack: true,
}, },
{ {
label: "<?php echo esc_js( __( 'Guest orders', 'woocommerce' ) ); ?>", label: "<?php echo esc_js( __( 'Guest orders', 'woocommerce' ) ); ?>",
data: chart_data.guest_orders, data: chart_data.guest_orders,
color: '<?php echo $this->chart_colours['guests']; ?>', color: '<?php echo esc_html( $this->chart_colours['guests'] ); ?>',
bars: { fillColor: '<?php echo $this->chart_colours['guests']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' }, bars: { fillColor: '<?php echo esc_html( $this->chart_colours['guests'] ); ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo esc_html( $this->barwidth ); ?> * 0.5, align: 'center' },
shadowSize: 0, shadowSize: 0,
enable_tooltip: true, enable_tooltip: true,
append_tooltip: "<?php echo ' ' . __( 'guest orders', 'woocommerce' ); ?>", append_tooltip: "<?php echo esc_html( ' ' . __( 'guest orders', 'woocommerce' ) ); ?>",
stack: true, stack: true,
}, },
{ {
label: "<?php echo esc_js( __( 'Signups', 'woocommerce' ) ); ?>", label: "<?php echo esc_js( __( 'Signups', 'woocommerce' ) ); ?>",
data: chart_data.signups, data: chart_data.signups,
color: '<?php echo $this->chart_colours['signups']; ?>', color: '<?php echo esc_html( $this->chart_colours['signups'] ); ?>',
points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true }, points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true },
lines: { show: true, lineWidth: 4, fill: false }, lines: { show: true, lineWidth: 4, fill: false },
shadowSize: 0, shadowSize: 0,
enable_tooltip: true, enable_tooltip: true,
append_tooltip: "<?php echo ' ' . __( 'new users', 'woocommerce' ); ?>", append_tooltip: "<?php echo esc_html( ' ' . __( 'new users', 'woocommerce' ) ); ?>",
stack: false stack: false
}, },
]; ];
@ -388,10 +388,10 @@ class WC_Report_Customers extends WC_Admin_Report {
tickColor: 'transparent', tickColor: 'transparent',
mode: "time", mode: "time",
timeformat: "<?php echo ( 'day' === $this->chart_groupby ) ? '%d %b' : '%b'; ?>", timeformat: "<?php echo ( 'day' === $this->chart_groupby ) ? '%d %b' : '%b'; ?>",
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ); ?>, monthNames: <?php echo wp_json_encode( array_values( $wp_locale->month_abbrev ) ); ?>,
tickLength: 1, tickLength: 1,
minTickSize: [1, "<?php echo $this->chart_groupby; ?>"], minTickSize: [1, "<?php echo esc_html( $this->chart_groupby ); ?>"],
tickSize: [1, "<?php echo $this->chart_groupby; ?>"], tickSize: [1, "<?php echo esc_html( $this->chart_groupby ); ?>"],
font: { font: {
color: "#aaa" color: "#aaa"
} }