Completed
Pull Request — master (#10259)
by Mike
13:41
created

WC_Order_Item_Tax::get_rate_code()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Order Line Item (tax).
4
 *
5
 * @class 		WC_Order_Item_Tax
6
 * @version		2.6.0
7
 * @since       2.6.0
8
 * @package		WooCommerce/Classes
9
 * @author 		WooThemes
10
 */
11
class WC_Order_Item_Tax extends WC_Order_Item {
12
13
    /**
14
	 * Data properties of this order item object.
15
	 * @since 2.6.0
16
	 * @var array
17
	 */
18
    protected $_data = array(
19
        'order_id'           => 0,
20
		'order_item_id'      => 0,
21
        'rate_code'          => '',
22
        'rate_id'            => 0,
23
        'label'              => '',
24
        'compound'           => false,
25
        'tax_total'          => 0,
26
        'shipping_tax_total' => 0
27
    );
28
29
    /**
30
     * Read/populate data properties specific to this order item.
31
     */
32
    public function read( $id ) {
33
        parent::read( $id );
34
        if ( $this->get_order_item_id() ) {
35
            $this->set_rate_id( get_metadata( 'order_item', $this->get_order_item_id(), 'rate_id', true ) );
36
            $this->set_label( get_metadata( 'order_item', $this->get_order_item_id(), 'label', true ) );
0 ignored issues
show
Bug introduced by
The method set_label() does not seem to exist on object<WC_Order_Item_Tax>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
            $this->set_compound( get_metadata( 'order_item', $this->get_order_item_id(), 'compound', true ) );
38
            $this->set_tax_total( get_metadata( 'order_item', $this->get_order_item_id(), 'tax_amount', true ) );
0 ignored issues
show
Bug introduced by
The method set_tax_total() does not seem to exist on object<WC_Order_Item_Tax>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
            $this->set_shipping_tax_total( get_metadata( 'order_item', $this->get_order_item_id(), 'shipping_tax_amount', true ) );
0 ignored issues
show
Bug introduced by
The method set_shipping_tax_total() does not seem to exist on object<WC_Order_Item_Tax>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        }
41
    }
42
43
    /**
44
     * Save properties specific to this order item.
45
     */
46
    public function save() {
47
        parent::save();
48
        if ( $this->get_order_item_id() ) {
49
            wc_update_order_item_meta( $this->get_order_item_id(), 'rate_id', $this->get_rate_id() );
50
            wc_update_order_item_meta( $this->get_order_item_id(), 'label', $this->get_label() );
0 ignored issues
show
Bug introduced by
The method get_label() does not seem to exist on object<WC_Order_Item_Tax>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
            wc_update_order_item_meta( $this->get_order_item_id(), 'compound', $this->get_compound() );
52
            wc_update_order_item_meta( $this->get_order_item_id(), 'tax_amount', $this->get_tax_amount() );
53
            wc_update_order_item_meta( $this->get_order_item_id(), 'shipping_tax_amount', $this->get_shipping_tax_amount() );
54
        }
55
    }
56
57
    /**
58
     * Internal meta keys we don't want exposed as part of meta_data.
59
     * @return array()
0 ignored issues
show
Documentation introduced by
The doc-type array() could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
60
     */
61
    protected function get_internal_meta_keys() {
62
        return array( 'rate_id', 'label', 'compound', 'tax_amount', 'shipping_tax_amount' );
63
    }
64
65
    /*
66
	|--------------------------------------------------------------------------
67
	| Setters
68
	|--------------------------------------------------------------------------
69
	*/
70
71
    /**
72
     * Set order item name.
73
     * @param string $value
74
     */
75
    public function set_name( $value ) {
76
        $this->_data['rate_code'] = wc_clean( $value );
77
    }
78
79
    /**
80
     * Set item name.
81
     * @param string $value
82
     */
83
    public function set_rate_code( $value ) {
84
        $this->set_name( $value );
85
    }
86
87
    /**
88
     * Set tax rate id.
89
     * @param int $value
90
     */
91
    public function set_rate_id( $value ) {
92
        $this->_data['rate_id'] = absint( $value );
93
    }
94
95
    /**
96
     * Set tax_amount.
97
     * @param string $value
98
     */
99
    public function set_tax_amount( $value ) {
100
        $this->_data['tax_amount'] = wc_format_decimal( $value );
101
    }
102
103
    /**
104
     * Set shipping_tax_amount
105
     * @param string $value
106
     */
107
    public function set_shipping_tax_amount( $value ) {
108
        $this->_data['shipping_tax_amount'] = wc_format_decimal( $value );
109
    }
110
111
    /**
112
     * Set compound
113
     * @param bool $value
114
     */
115
    public function set_compound( $value ) {
116
        $this->_data['compound'] = (bool) $value;
117
    }
118
119
    /*
120
	|--------------------------------------------------------------------------
121
	| Getters
122
	|--------------------------------------------------------------------------
123
	*/
124
125
    /**
126
     * Get order item type.
127
     * @return string
128
     */
129
    public function get_type() {
130
        return 'tax';
131
    }
132
133
    /**
134
     * Get fee name.
135
     * @return string
136
     */
137
    public function get_rate_code() {
138
        return $this->get_name();
139
    }
140
141
    /**
142
     * Get tax rate ID.
143
     * @return int
144
     */
145
    public function get_rate_id() {
146
        return absint( $this->_data['rate_id'] );
147
    }
148
149
    /**
150
     * Get tax_amount
151
     * @return string
152
     */
153
    public function get_tax_amount() {
154
        return wc_format_decimal( $this->_data['tax_amount'] );
155
    }
156
157
    /**
158
     * Get shipping_tax_amount
159
     * @return string
160
     */
161
    public function get_shipping_tax_amount() {
162
        return wc_format_decimal( $this->_data['shipping_tax_amount'] );
163
    }
164
165
    /**
166
     * Get compound.
167
     * @return bool
168
     */
169
    public function get_compound() {
170
        return (bool) $this->_data['compound'];
171
    }
172
}
173