Fixed includes/class-wc-cart-totals.php PHPCS violations

This commit is contained in:
Claudio Sanches 2018-03-16 14:47:18 -03:00
parent 8effbb11bd
commit 67cd6b8fbf
1 changed files with 24 additions and 24 deletions

View File

@ -9,8 +9,8 @@
* - if something is being stored e.g. item total, store unrounded. This is so taxes can be recalculated later accurately. * - if something is being stored e.g. item total, store unrounded. This is so taxes can be recalculated later accurately.
* - if calculating a total, round (if settings allow). * - if calculating a total, round (if settings allow).
* *
* @author Automattic
* @package WooCommerce/Classes * @package WooCommerce/Classes
* @version 3.2.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
@ -102,16 +102,16 @@ final class WC_Cart_Totals {
* @var array * @var array
*/ */
protected $totals = array( protected $totals = array(
'fees_total' => 0, 'fees_total' => 0,
'fees_total_tax' => 0, 'fees_total_tax' => 0,
'items_subtotal' => 0, 'items_subtotal' => 0,
'items_subtotal_tax' => 0, 'items_subtotal_tax' => 0,
'items_total' => 0, 'items_total' => 0,
'items_total_tax' => 0, 'items_total_tax' => 0,
'total' => 0, 'total' => 0,
'shipping_total' => 0, 'shipping_total' => 0,
'shipping_tax_total' => 0, 'shipping_tax_total' => 0,
'discounts_total' => 0, 'discounts_total' => 0,
); );
/** /**
@ -212,7 +212,7 @@ final class WC_Cart_Totals {
* into the same format for use by this class. * into the same format for use by this class.
* *
* Each item is made up of the following props, in addition to those returned by get_default_item_props() for totals. * Each item is made up of the following props, in addition to those returned by get_default_item_props() for totals.
* - key: An identifier for the item (cart item key or line item ID). * - key: An identifier for the item (cart item key or line item ID).
* - cart_item: For carts, the cart item from the cart which may include custom data. * - cart_item: For carts, the cart item from the cart which may include custom data.
* - quantity: The qty for this line. * - quantity: The qty for this line.
* - price: The line price in cents. * - price: The line price in cents.
@ -312,13 +312,12 @@ final class WC_Cart_Totals {
$fee->taxes = wc_array_merge_recursive_numeric( $fee->taxes, WC_Tax::calc_tax( $fee->total * $proportion, WC_Tax::get_rates( $tax_class ) ) ); $fee->taxes = wc_array_merge_recursive_numeric( $fee->taxes, WC_Tax::calc_tax( $fee->total * $proportion, WC_Tax::get_rates( $tax_class ) ) );
} }
} }
} elseif ( $fee->object->taxable ) { } elseif ( $fee->object->taxable ) {
$fee->taxes = WC_Tax::calc_tax( $fee->total, WC_Tax::get_rates( $fee->tax_class, $this->cart->get_customer() ), false ); $fee->taxes = WC_Tax::calc_tax( $fee->total, WC_Tax::get_rates( $fee->tax_class, $this->cart->get_customer() ), false );
} }
} }
$fee->taxes = apply_filters( 'woocommerce_cart_totals_get_fees_from_cart_taxes', $fee->taxes, $fee, $this ); $fee->taxes = apply_filters( 'woocommerce_cart_totals_get_fees_from_cart_taxes', $fee->taxes, $fee, $this );
$fee->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $fee->taxes ) ); $fee->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $fee->taxes ) );
// Set totals within object. // Set totals within object.
@ -366,13 +365,13 @@ final class WC_Cart_Totals {
foreach ( $this->coupons as $coupon ) { foreach ( $this->coupons as $coupon ) {
switch ( $coupon->get_discount_type() ) { switch ( $coupon->get_discount_type() ) {
case 'fixed_product' : case 'fixed_product':
$coupon->sort = 1; $coupon->sort = 1;
break; break;
case 'percent' : case 'percent':
$coupon->sort = 2; $coupon->sort = 2;
break; break;
case 'fixed_cart' : case 'fixed_cart':
$coupon->sort = 3; $coupon->sort = 3;
break; break;
default: default:
@ -391,7 +390,7 @@ final class WC_Cart_Totals {
* Sort coupons so discounts apply consistently across installs. * Sort coupons so discounts apply consistently across installs.
* *
* In order of priority; * In order of priority;
* - sort param * - sort param
* - usage restriction * - usage restriction
* - coupon value * - coupon value
* - ID * - ID
@ -422,10 +421,10 @@ final class WC_Cart_Totals {
*/ */
protected function remove_item_base_taxes( $item ) { protected function remove_item_base_taxes( $item ) {
if ( $item->price_includes_tax && $item->taxable ) { if ( $item->price_includes_tax && $item->taxable ) {
$base_tax_rates = WC_Tax::get_base_tax_rates( $item->product->get_tax_class( 'unfiltered' ) ); $base_tax_rates = WC_Tax::get_base_tax_rates( $item->product->get_tax_class( 'unfiltered' ) );
// Work out a new base price without the shop's base tax. // Work out a new base price without the shop's base tax.
$taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true ); $taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true );
// Now we have a new item price (excluding TAX). // Now we have a new item price (excluding TAX).
$item->price = round( $item->price - array_sum( $taxes ) ); $item->price = round( $item->price - array_sum( $taxes ) );
@ -452,8 +451,8 @@ final class WC_Cart_Totals {
if ( $item->tax_rates !== $base_tax_rates ) { if ( $item->tax_rates !== $base_tax_rates ) {
// Work out a new base price without the shop's base tax. // Work out a new base price without the shop's base tax.
$taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true ); $taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true );
$new_taxes = WC_Tax::calc_tax( $item->price - array_sum( $taxes ), $item->tax_rates, false ); $new_taxes = WC_Tax::calc_tax( $item->price - array_sum( $taxes ), $item->tax_rates, false );
// Now we have a new item price. // Now we have a new item price.
$item->price = round( $item->price - array_sum( $taxes ) + array_sum( $new_taxes ) ); $item->price = round( $item->price - array_sum( $taxes ) + array_sum( $new_taxes ) );
@ -551,7 +550,8 @@ final class WC_Cart_Totals {
* Get taxes merged by type. * Get taxes merged by type.
* *
* @since 3.2.0 * @since 3.2.0
* @param array|string $types Types to merge and return. Defaults to all. * @param bool $in_cents If returned value should be in cents.
* @param array|string $types Types to merge and return. Defaults to all.
* @return array * @return array
*/ */
protected function get_merged_taxes( $in_cents = false, $types = array( 'items', 'fees', 'shipping' ) ) { protected function get_merged_taxes( $in_cents = false, $types = array( 'items', 'fees', 'shipping' ) ) {
@ -584,7 +584,7 @@ final class WC_Cart_Totals {
* Combine item taxes into a single array, preserving keys. * Combine item taxes into a single array, preserving keys.
* *
* @since 3.2.0 * @since 3.2.0
* @param array $taxes Taxes to combine. * @param array $item_taxes Taxes to combine.
* @return array * @return array
*/ */
protected function combine_item_taxes( $item_taxes ) { protected function combine_item_taxes( $item_taxes ) {