Fixed includes/class-wc-order-item.php PHPCS violations

This commit is contained in:
Claudio Sanches 2018-03-21 00:56:59 -03:00
parent 583378cf7b
commit a7692478b0
1 changed files with 47 additions and 31 deletions

View File

@ -1,23 +1,25 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Order Item * Order Item
* *
* A class which represents an item within an order and handles CRUD. * A class which represents an item within an order and handles CRUD.
* Uses ArrayAccess to be BW compatible with WC_Orders::get_items(). * Uses ArrayAccess to be BW compatible with WC_Orders::get_items().
* *
* @version 3.0.0 * @package WooCommerce/Classes
* @since 3.0.0 * @version 3.0.0
* @package WooCommerce/Classes * @since 3.0.0
* @author WooThemes */
defined( 'ABSPATH' ) || exit;
/**
* Order item class.
*/ */
class WC_Order_Item extends WC_Data implements ArrayAccess { class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Order Data array. This is the core order data exposed in APIs since 3.0.0. * Order Data array. This is the core order data exposed in APIs since 3.0.0.
*
* @since 3.0.0 * @since 3.0.0
* @var array * @var array
*/ */
@ -29,6 +31,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Stores meta in cache for future reads. * Stores meta in cache for future reads.
* A group must be set to to enable caching. * A group must be set to to enable caching.
*
* @var string * @var string
*/ */
protected $cache_group = 'order-items'; protected $cache_group = 'order-items';
@ -37,18 +40,22 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
* Meta type. This should match up with * Meta type. This should match up with
* the types available at https://codex.wordpress.org/Function_Reference/add_metadata. * the types available at https://codex.wordpress.org/Function_Reference/add_metadata.
* WP defines 'post', 'user', 'comment', and 'term'. * WP defines 'post', 'user', 'comment', and 'term'.
*
* @var string
*/ */
protected $meta_type = 'order_item'; protected $meta_type = 'order_item';
/** /**
* This is the name of this object type. * This is the name of this object type.
*
* @var string * @var string
*/ */
protected $object_type = 'order_item'; protected $object_type = 'order_item';
/** /**
* Constructor. * Constructor.
* @param int|object|array $item ID to load from the DB, or WC_Order_Item Object *
* @param int|object|array $item ID to load from the DB, or WC_Order_Item object.
*/ */
public function __construct( $item = 0 ) { public function __construct( $item = 0 ) {
parent::__construct( $item ); parent::__construct( $item );
@ -61,7 +68,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
$this->set_object_read( true ); $this->set_object_read( true );
} }
$type = 'line_item' === $this->get_type() ? 'product' : $this->get_type(); $type = 'line_item' === $this->get_type() ? 'product' : $this->get_type();
$this->data_store = WC_Data_Store::load( 'order-item-' . $type ); $this->data_store = WC_Data_Store::load( 'order-item-' . $type );
if ( $this->get_id() > 0 ) { if ( $this->get_id() > 0 ) {
$this->data_store->read( $this ); $this->data_store->read( $this );
@ -78,7 +85,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
*/ */
public function apply_changes() { public function apply_changes() {
if ( function_exists( 'array_replace' ) ) { if ( function_exists( 'array_replace' ) ) {
$this->data = array_replace( $this->data, $this->changes ); $this->data = array_replace( $this->data, $this->changes ); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replaceFound
} else { // PHP 5.2 compatibility. } else { // PHP 5.2 compatibility.
foreach ( $this->changes as $key => $change ) { foreach ( $this->changes as $key => $change ) {
$this->data[ $key ] = $change; $this->data[ $key ] = $change;
@ -96,7 +103,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Get order ID this meta belongs to. * Get order ID this meta belongs to.
* *
* @param string $context * @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return int * @return int
*/ */
public function get_order_id( $context = 'view' ) { public function get_order_id( $context = 'view' ) {
@ -106,7 +113,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Get order item name. * Get order item name.
* *
* @param string $context * @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return string * @return string
*/ */
public function get_name( $context = 'view' ) { public function get_name( $context = 'view' ) {
@ -119,11 +126,12 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
* @return string * @return string
*/ */
public function get_type() { public function get_type() {
return; return '';
} }
/** /**
* Get quantity. * Get quantity.
*
* @return int * @return int
*/ */
public function get_quantity() { public function get_quantity() {
@ -132,6 +140,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Get tax status. * Get tax status.
*
* @return string * @return string
*/ */
public function get_tax_status() { public function get_tax_status() {
@ -141,7 +150,6 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Get tax class. * Get tax class.
* *
* @param string $context
* @return string * @return string
*/ */
public function get_tax_class() { public function get_tax_class() {
@ -150,6 +158,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Get parent order object. * Get parent order object.
*
* @return WC_Order * @return WC_Order
*/ */
public function get_order() { public function get_order() {
@ -165,8 +174,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Set order ID. * Set order ID.
* *
* @param int $value * @param int $value Order ID.
* @throws WC_Data_Exception
*/ */
public function set_order_id( $value ) { public function set_order_id( $value ) {
$this->set_prop( 'order_id', absint( $value ) ); $this->set_prop( 'order_id', absint( $value ) );
@ -175,8 +183,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Set order item name. * Set order item name.
* *
* @param string $value * @param string $value Item name.
* @throws WC_Data_Exception
*/ */
public function set_name( $value ) { public function set_name( $value ) {
$this->set_prop( 'name', wc_clean( $value ) ); $this->set_prop( 'name', wc_clean( $value ) );
@ -191,11 +198,11 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/** /**
* Type checking. * Type checking.
* *
* @param string|array $type * @param string|array $type Type.
* @return boolean * @return boolean
*/ */
public function is_type( $type ) { public function is_type( $type ) {
return is_array( $type ) ? in_array( $this->get_type(), $type ) : $type === $this->get_type(); return is_array( $type ) ? in_array( $this->get_type(), $type, true ) : $type === $this->get_type();
} }
/** /**
@ -216,7 +223,12 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
if ( method_exists( $this, 'get_subtotal' ) ) { if ( method_exists( $this, 'get_subtotal' ) ) {
$subtotal_taxes = WC_Tax::calc_tax( $this->get_subtotal(), $tax_rates, false ); $subtotal_taxes = WC_Tax::calc_tax( $this->get_subtotal(), $tax_rates, false );
$this->set_taxes( array( 'total' => $taxes, 'subtotal' => $subtotal_taxes ) ); $this->set_taxes(
array(
'total' => $taxes,
'subtotal' => $subtotal_taxes,
)
);
} else { } else {
$this->set_taxes( array( 'total' => $taxes ) ); $this->set_taxes( array( 'total' => $taxes ) );
} }
@ -293,9 +305,10 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
*/ */
/** /**
* offsetSet for ArrayAccess * OffsetSet for ArrayAccess.
* @param string $offset *
* @param mixed $value * @param string $offset Offset.
* @param mixed $value Value.
*/ */
public function offsetSet( $offset, $value ) { public function offsetSet( $offset, $value ) {
if ( 'item_meta_array' === $offset ) { if ( 'item_meta_array' === $offset ) {
@ -317,8 +330,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
} }
/** /**
* offsetUnset for ArrayAccess * OffsetUnset for ArrayAccess.
* @param string $offset *
* @param string $offset Offset.
*/ */
public function offsetUnset( $offset ) { public function offsetUnset( $offset ) {
$this->maybe_read_meta_data(); $this->maybe_read_meta_data();
@ -340,8 +354,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
} }
/** /**
* offsetExists for ArrayAccess * OffsetExists for ArrayAccess.
* @param string $offset *
* @param string $offset Offset.
* @return bool * @return bool
*/ */
public function offsetExists( $offset ) { public function offsetExists( $offset ) {
@ -353,8 +368,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
} }
/** /**
* offsetGet for ArrayAccess * OffsetGet for ArrayAccess.
* @param string $offset *
* @param string $offset Offset.
* @return mixed * @return mixed
*/ */
public function offsetGet( $offset ) { public function offsetGet( $offset ) {