Passed
Push — master ( 2b14f3...10836f )
by Brian
04:07
created
includes/class-getpaid-tax.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Class GetPaid_Tax
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22 22
 	 * @return array                       Array of tax name => tax amount.
23 23
 	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
24
+	public static function calc_tax($price, $rates, $price_includes_tax = false) {
25 25
 
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
26
+		if ($price_includes_tax) {
27
+			$taxes = self::calc_inclusive_tax($price, $rates);
28 28
 		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
29
+			$taxes = self::calc_exclusive_tax($price, $rates);
30 30
 		}
31 31
 
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
32
+		return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax);
33 33
 
34 34
 	}
35 35
 
@@ -40,22 +40,22 @@  discard block
 block discarded – undo
40 40
 	 * @param  array $rates Array of tax rates.
41 41
 	 * @return array
42 42
 	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
43
+	public static function calc_inclusive_tax($price, $rates) {
44 44
 		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
45
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
46 46
 
47 47
 		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
48
+		$tax_rate  = 1 + (array_sum($tax_rates) / 100);
49 49
 
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
50
+		foreach ($tax_rates as $name => $rate) {
51
+			$the_rate       = ($rate / 100) / $tax_rate;
52
+			$net_price      = $price - ($the_rate * $price);
53
+			$tax_amount     = apply_filters('getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price);
54
+			$taxes[$name] = $tax_amount;
55 55
 		}
56 56
 
57 57
 		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
58
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
59 59
 
60 60
 		return $taxes;
61 61
 	}
@@ -67,19 +67,19 @@  discard block
 block discarded – undo
67 67
 	 * @param  array $rates Array of tax rates.
68 68
 	 * @return array
69 69
 	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
70
+	public static function calc_exclusive_tax($price, $rates) {
71 71
 		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
72
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
73 73
 
74
-		foreach ( $tax_rates as $name => $rate ) {
74
+		foreach ($tax_rates as $name => $rate) {
75 75
 
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
76
+			$tax_amount     = $price * ($rate / 100);
77
+			$taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price);
78 78
 
79 79
 		}
80 80
 
81 81
 		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
82
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
83 83
 
84 84
 		return $taxes;
85 85
 	}
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function get_all_tax_rates() {
93 93
 
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
94
+		$rates = get_option('wpinv_tax_rates', array());
95 95
 
96 96
 		return apply_filters(
97 97
 			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
98
+			array_filter(wpinv_parse_list($rates))
99 99
 		);
100 100
 
101 101
 	}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 					'state'     => wpinv_get_default_state(),
116 116
 					'global'    => true,
117 117
 					'rate'      => wpinv_get_default_tax_rate(),
118
-					'name'      => __( 'Base Tax', 'invoicing' ),
118
+					'name'      => __('Base Tax', 'invoicing'),
119 119
 				)
120 120
 			)
121 121
 		);
@@ -129,24 +129,24 @@  discard block
 block discarded – undo
129 129
 	 * @param string $state
130 130
 	 * @return array
131 131
 	 */
132
-	public static function get_address_tax_rates( $country, $state ) {
132
+	public static function get_address_tax_rates($country, $state) {
133 133
 
134 134
 		$all_tax_rates  = self::get_all_tax_rates();
135 135
 		$matching_rates = array_merge(
136
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
136
+			wp_list_filter($all_tax_rates, array('country' => $country)),
137
+			wp_list_filter($all_tax_rates, array('country' => ''))
138 138
 		);
139 139
 
140
-		foreach ( $matching_rates as $i => $rate ) {
140
+		foreach ($matching_rates as $i => $rate) {
141 141
 
142
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
143
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
144
-				unset( $matching_rates[ $i ] );
142
+			$states = array_filter(wpinv_clean(explode(',', strtolower($rate['state']))));
143
+			if (empty($rate['global']) && !in_array(strtolower($state), $states)) {
144
+				unset($matching_rates[$i]);
145 145
 			}
146 146
 
147 147
 		}
148 148
 
149
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
149
+		return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state);
150 150
 
151 151
 	}
152 152
 
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 	 * @param  array $taxes Array of taxes.
157 157
 	 * @return float
158 158
 	 */
159
-	public static function get_tax_total( $taxes ) {
160
-		return self::round( array_sum( $taxes ) );
159
+	public static function get_tax_total($taxes) {
160
+		return self::round(array_sum($taxes));
161 161
 	}
162 162
 
163 163
 	/**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 	 * @param float|int $in Value to round.
174 174
 	 * @return float
175 175
 	 */
176
-	public static function round( $in ) {
177
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
176
+	public static function round($in) {
177
+		return apply_filters('getpaid_tax_round', round($in, 4), $in);
178 178
 	}
179 179
 
180 180
 }
Please login to merge, or discard this patch.