WC_Shipping_Rate::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
eloc 6
nc 4
nop 5
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit; // Exit if accessed directly
5
}
6
7
/**
8
 * WooCommerce Shipping Rate Class.
9
 *
10
 * Simple Class for storing rates.
11
 *
12
 * @class 		WC_Shipping_Rate
13
 * @version		2.6.0
14
 * @package		WooCommerce/Classes/Shipping
15
 * @category	Class
16
 * @author 		WooThemes
17
 */
18
class WC_Shipping_Rate {
19
20
	/** @var string Rate ID. */
21
	public $id        = '';
22
23
	/** @var string Label for the rate. */
24
	public $label     = '';
25
26
	/** @var float Cost for the rate. */
27
	public $cost      = 0;
28
29
	/** @var array Array of taxes for the rate. */
30
	public $taxes     = array();
31
32
	/** @var string Label for the rate. */
33
	public $method_id = '';
34
35
	/**
36
	 * Stores meta data for this rate
37
	 * @since 2.6.0
38
	 * @var array
39
	 */
40
	private $meta_data = array();
41
42
	/**
43
	 * Constructor.
44
	 *
45
	 * @param string $id
46
	 * @param string $label
47
	 * @param integer $cost
48
	 * @param array $taxes
49
	 * @param string $method_id
50
	 */
51
	public function __construct( $id = '', $label = '', $cost = 0, $taxes = array(), $method_id = '' ) {
52
		$this->id        = $id;
53
		$this->label     = $label;
54
		$this->cost      = $cost;
0 ignored issues
show
Documentation Bug introduced by
The property $cost was declared of type double, but $cost is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
55
		$this->taxes     = ! empty( $taxes ) && is_array( $taxes ) ? $taxes : array();
56
		$this->method_id = $method_id;
57
	}
58
59
	/**
60
	 * Get shipping tax.
61
	 *
62
	 * @return array
63
	 */
64
	public function get_shipping_tax() {
65
		return apply_filters( 'woocommerce_get_shipping_tax', sizeof( $this->taxes ) > 0 && ! WC()->customer->is_vat_exempt() ? array_sum( $this->taxes ) : 0, $this );
66
	}
67
68
	/**
69
	 * Get label.
70
	 *
71
	 * @return string
72
	 */
73
	public function get_label() {
74
		return apply_filters( 'woocommerce_shipping_rate_label', $this->label );
75
	}
76
77
	/**
78
	 * Add some meta data for this rate.
79
	 * @since 2.6.0
80
	 * @param string $key
81
	 * @param string $value
82
	 */
83
	public function add_meta_data( $key, $value ) {
84
		$this->meta_data[ wc_clean( $key ) ] = wc_clean( $value );
85
	}
86
87
	/**
88
	 * Get all meta data for this rate.
89
	 * @since 2.6.0
90
	 */
91
	public function get_meta_data() {
92
		return $this->meta_data;
93
	}
94
}
95