Fix some PHPCS violations in includes/data-stores/abstract-wc-order-data-store-cpt.php

This commit is contained in:
Rodrigo Primo 2017-11-23 12:43:20 -02:00
parent 5e43d92e07
commit 3d6bd30d8a
1 changed files with 29 additions and 19 deletions

View File

@ -1,4 +1,10 @@
<?php
/**
* Abstract_WC_Order_Data_Store_CPT class file.
*
* @package WooCommerce/Classes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -47,7 +53,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Method to create a new order in the database.
*
* @param WC_Order $order
* @param WC_Order $order Order object.
*/
public function create( &$order ) {
$order->set_version( WC_VERSION );
@ -84,14 +90,15 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Method to read an order from the database.
*
* @param WC_Data $order
* @param WC_Data $order Order object.
*
* @throws Exception
* @throws Exception If passed order is invalid.
*/
public function read( &$order ) {
$order->set_defaults();
$post_object = get_post( $order->get_id() );
if ( ! $order->get_id() || ! ( $post_object = get_post( $order->get_id() ) ) || ! in_array( $post_object->post_type, wc_get_order_types() ) ) {
if ( ! $order->get_id() || ! $post_object || ! in_array( $post_object->post_type, wc_get_order_types() ) ) {
throw new Exception( __( 'Invalid order.', 'woocommerce' ) );
}
@ -121,7 +128,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Method to update an order in the database.
*
* @param WC_Order $order
* @param WC_Order $order Order object.
*/
public function update( &$order ) {
$order->save_meta_data();
@ -165,8 +172,10 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Method to delete an order from the database.
*
* @param WC_Order $order
* @param WC_Order $order Order object.
* @param array $args Array of args to pass to the delete method.
*
* @return void
*/
public function delete( &$order, $args = array() ) {
$id = $order->get_id();
@ -201,7 +210,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Excerpt for post.
*
* @param WC_order $order
* @param WC_order $order Order object.
* @return string
*/
protected function get_post_excerpt( $order ) {
@ -223,8 +232,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Read order data. Can be overridden by child classes to load other props.
*
* @param WC_Order $order
* @param object $post_object
* @param WC_Order $order Order object.
* @param object $post_object Post object.
* @since 3.0.0
*/
protected function read_order_data( &$order, $post_object ) {
@ -256,7 +265,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
*
* @param $order WC_Order
* @param WC_Order $order Order object.
* @since 3.0.0
*/
protected function update_post_meta( &$order ) {
@ -293,7 +302,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Clear any caches.
*
* @param WC_Order $order
* @param WC_Order $order Order object.
* @since 3.0.0
*/
protected function clear_caches( &$order ) {
@ -305,8 +314,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Read order items of a specific type from the database for this order.
*
* @param WC_Order $order
* @param string $type
* @param WC_Order $order Order object.
* @param string $type Order item type.
* @return array
*/
public function read_items( $order, $type ) {
@ -316,8 +325,9 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
$items = wp_cache_get( 'order-items-' . $order->get_id(), 'orders' );
if ( false === $items ) {
$get_items_sql = $wpdb->prepare( "SELECT order_item_type, order_item_id, order_id, order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d ORDER BY order_item_id;", $order->get_id() );
$items = $wpdb->get_results( $get_items_sql );
$items = $wpdb->get_results(
$wpdb->prepare( "SELECT order_item_type, order_item_id, order_id, order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d ORDER BY order_item_id;", $order->get_id() )
);
foreach ( $items as $item ) {
wp_cache_set( 'item-' . $item->order_item_id, $item, 'order-items' );
}
@ -338,7 +348,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Remove all line items (products, coupons, shipping, taxes) from the order.
*
* @param WC_Order $order
* @param WC_Order $order Order object.
* @param string $type Order item type. Default null.
*/
public function delete_items( $order, $type = null ) {
@ -356,7 +366,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Get token ids for an order.
*
* @param WC_Order $order
* @param WC_Order $order Order object.
* @return array
*/
public function get_payment_token_ids( $order ) {
@ -367,8 +377,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
/**
* Update token ids for an order.
*
* @param WC_Order $order
* @param array $token_ids
* @param WC_Order $order Order object.
* @param array $token_ids Payment token ids.
*/
public function update_payment_token_ids( $order, $token_ids ) {
update_post_meta( $order->get_id(), '_payment_tokens', $token_ids );