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
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Order Item
*
* A class which represents an item within an order and handles CRUD.
* Uses ArrayAccess to be BW compatible with WC_Orders::get_items().
*
* @package WooCommerce/Classes
* @version 3.0.0
* @since 3.0.0
* @package WooCommerce/Classes
* @author WooThemes
*/
defined( 'ABSPATH' ) || exit;
/**
* Order item class.
*/
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.
*
* @since 3.0.0
* @var array
*/
@ -29,6 +31,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/**
* Stores meta in cache for future reads.
* A group must be set to to enable caching.
*
* @var string
*/
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
* the types available at https://codex.wordpress.org/Function_Reference/add_metadata.
* WP defines 'post', 'user', 'comment', and 'term'.
*
* @var string
*/
protected $meta_type = 'order_item';
/**
* This is the name of this object type.
*
* @var string
*/
protected $object_type = 'order_item';
/**
* 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 ) {
parent::__construct( $item );
@ -78,7 +85,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
*/
public function apply_changes() {
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.
foreach ( $this->changes as $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.
*
* @param string $context
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return int
*/
public function get_order_id( $context = 'view' ) {
@ -106,7 +113,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/**
* Get order item name.
*
* @param string $context
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return string
*/
public function get_name( $context = 'view' ) {
@ -119,11 +126,12 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
* @return string
*/
public function get_type() {
return;
return '';
}
/**
* Get quantity.
*
* @return int
*/
public function get_quantity() {
@ -132,6 +140,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/**
* Get tax status.
*
* @return string
*/
public function get_tax_status() {
@ -141,7 +150,6 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/**
* Get tax class.
*
* @param string $context
* @return string
*/
public function get_tax_class() {
@ -150,6 +158,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/**
* Get parent order object.
*
* @return WC_Order
*/
public function get_order() {
@ -165,8 +174,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/**
* Set order ID.
*
* @param int $value
* @throws WC_Data_Exception
* @param int $value Order ID.
*/
public function set_order_id( $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.
*
* @param string $value
* @throws WC_Data_Exception
* @param string $value Item name.
*/
public function set_name( $value ) {
$this->set_prop( 'name', wc_clean( $value ) );
@ -191,11 +198,11 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
/**
* Type checking.
*
* @param string|array $type
* @param string|array $type Type.
* @return boolean
*/
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' ) ) {
$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 {
$this->set_taxes( array( 'total' => $taxes ) );
}
@ -293,9 +305,10 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
*/
/**
* offsetSet for ArrayAccess
* @param string $offset
* @param mixed $value
* OffsetSet for ArrayAccess.
*
* @param string $offset Offset.
* @param mixed $value Value.
*/
public function offsetSet( $offset, $value ) {
if ( 'item_meta_array' === $offset ) {
@ -317,8 +330,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
}
/**
* offsetUnset for ArrayAccess
* @param string $offset
* OffsetUnset for ArrayAccess.
*
* @param string $offset Offset.
*/
public function offsetUnset( $offset ) {
$this->maybe_read_meta_data();
@ -340,8 +354,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
}
/**
* offsetExists for ArrayAccess
* @param string $offset
* OffsetExists for ArrayAccess.
*
* @param string $offset Offset.
* @return bool
*/
public function offsetExists( $offset ) {
@ -353,8 +368,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
}
/**
* offsetGet for ArrayAccess
* @param string $offset
* OffsetGet for ArrayAccess.
*
* @param string $offset Offset.
* @return mixed
*/
public function offsetGet( $offset ) {