From 16870a30e77b18032acdcfbd4e50bdb401649711 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 11 Jan 2018 12:32:58 +0000 Subject: [PATCH] phpcs --- includes/class-wc-structured-data.php | 54 +++++++++++++++------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/includes/class-wc-structured-data.php b/includes/class-wc-structured-data.php index 91c5b3208be..49d662d1a3a 100644 --- a/includes/class-wc-structured-data.php +++ b/includes/class-wc-structured-data.php @@ -1,22 +1,25 @@ + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +/** + * WC_Structured_Data class. */ class WC_Structured_Data { /** - * @var array $_data + * Stores the structured data. + * + * @var array $_data Array of structured data. */ private $_data = array(); @@ -128,9 +131,9 @@ class WC_Structured_Data { /** * Makes sure email structured data only outputs on non-plain text versions. * - * @param WP_Order $order Order data. - * @param bool $sent_to_admin Send to admin (default: false). - * @param bool $plain_text Plain text email (default: false). + * @param WP_Order $order Order data. + * @param bool $sent_to_admin Send to admin (default: false). + * @param bool $plain_text Plain text email (default: false). */ public function output_email_structured_data( $order, $sent_to_admin = false, $plain_text = false ) { if ( $plain_text ) { @@ -149,8 +152,9 @@ class WC_Structured_Data { */ public function output_structured_data() { $types = $this->get_data_type_for_page(); + $data = wc_clean( $this->get_structured_data( $types ) ); - if ( $data = wc_clean( $this->get_structured_data( $types ) ) ) { + if ( $data ) { echo ''; } } @@ -213,8 +217,8 @@ class WC_Structured_Data { if ( '' !== $product->get_price() ) { if ( $product->is_type( 'variable' ) ) { - $prices = $product->get_variation_prices(); - $lowest = reset( $prices['price'] ); + $prices = $product->get_variation_prices(); + $lowest = reset( $prices['price'] ); $highest = end( $prices['price'] ); if ( $lowest === $highest ) { @@ -279,18 +283,20 @@ class WC_Structured_Data { '@type' => 'Product', 'name' => get_the_title( $comment->comment_post_ID ), ); - if ( $rating = get_comment_meta( $comment->comment_ID, 'rating', true ) ) { - $markup['reviewRating'] = array( + + // Skip replies unless they have a rating. + $rating = get_comment_meta( $comment->comment_ID, 'rating', true ); + + if ( $rating ) { + $markup['reviewRating'] = array( '@type' => 'rating', 'ratingValue' => $rating, ); - - // Skip replies unless they have a rating. } elseif ( $comment->comment_parent ) { return; } - $markup['author'] = array( + $markup['author'] = array( '@type' => 'Person', 'name' => get_comment_author( $comment->comment_ID ), ); @@ -325,7 +331,7 @@ class WC_Structured_Data { ), ); - if ( ! empty( $crumb[1] ) && sizeof( $crumbs ) !== $key + 1 ) { + if ( ! empty( $crumb[1] ) && count( $crumbs ) !== $key + 1 ) { $markup['itemListElement'][ $key ]['item'] += array( '@id' => $crumb[1] ); } } @@ -357,9 +363,9 @@ class WC_Structured_Data { * * Hooked into `woocommerce_email_order_details` action hook. * - * @param WP_Order $order Order data. - * @param bool $sent_to_admin Send to admin (default: false). - * @param bool $plain_text Plain text email (default: false). + * @param WP_Order $order Order data. + * @param bool $sent_to_admin Send to admin (default: false). + * @param bool $plain_text Plain text email (default: false). */ public function generate_order_data( $order, $sent_to_admin = false, $plain_text = false ) { if ( $plain_text || ! is_a( $order, 'WC_Order' ) ) { @@ -389,7 +395,7 @@ class WC_Structured_Data { $product_exists = is_object( $product ); $is_visible = $product_exists && $product->is_visible(); - $markup_offers[] = array( + $markup_offers[] = array( '@type' => 'Offer', 'price' => $order->get_line_subtotal( $item ), 'priceCurrency' => $order->get_currency(),