Completed
Pull Request — master (#11613)
by Mike
08:58
created

WC_Legacy_Customer   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 227
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 227
rs 10
wmc 28
lcom 0
cbo 1

23 Methods

Rating   Name   Duplication   Size   Complexity  
A __isset() 0 8 1
A __get() 0 8 3
A __set() 0 6 1
A filter_legacy_key() 0 11 3
A is_vat_exempt() 0 4 1
A has_calculated_shipping() 0 4 1
A get_default_country() 0 5 1
A get_default_state() 0 5 1
A set_to_base() 0 4 1
A set_shipping_to_base() 0 4 1
A calculated_shipping() 0 4 1
A set_default_data() 0 3 1
A is_paying_customer() 0 7 2
A get_country() 0 4 1
A get_state() 0 4 1
A get_postcode() 0 4 1
A get_city() 0 4 1
A set_country() 0 4 1
A set_state() 0 4 1
A set_postcode() 0 4 1
A set_city() 0 4 1
A set_address() 0 4 1
A set_address_2() 0 4 1
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * Legacy Customer.
8
 *
9
 * @version  2.7.0
10
 * @package  WooCommerce/Classes
11
 * @category Class
12
 * @author   WooThemes
13
 */
14
abstract class WC_Legacy_Customer extends WC_Data {
15
16
	/**
17
	 * __isset legacy.
18
	 * @param mixed $key
19
	 * @return bool
20
	 */
21
	public function __isset( $key ) {
22
		$legacy_keys = array(
23
			'country', 'state', 'postcode' ,'city', 'address_1', 'address', 'address_2', 'shipping_country', 'shipping_state',
24
			'shipping_postcode', 'shipping_city', 'shipping_address_1', 'shipping_address', 'shipping_address_2', 'is_vat_exempt', 'calculated_shipping',
25
		);
26
		$key = $this->filter_legacy_key( $key );
27
		return in_array( $key, $legacy_keys );
28
	}
29
30
	/**
31
	 * __get function.
32
	 * @todo use get_* methods
33
	 * @param string $key
34
	 * @return string
35
	 */
36
	public function __get( $key ) {
37
		_doing_it_wrong( $key, 'Customer properties should not be accessed directly.', '2.7' );
38
		$key = $this->filter_legacy_key( $key );
39
		if ( in_array( $key, array( 'country', 'state', 'postcode' ,'city', 'address_1', 'address', 'address_2' ) ) ) {
40
			$key = 'billing_' . $key;
41
		}
42
		return isset( $this->_data[ $key ] ) ? $this->_data[ $key ] : '';
43
	}
44
45
	/**
46
	 * __set function.
47
	 * @todo use set_* methods
48
	 * @param mixed $property
0 ignored issues
show
Bug introduced by
There is no parameter named $property. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
49
	 * @param mixed $key
50
	 */
51
	public function __set( $key, $value ) {
52
		_doing_it_wrong( $key, 'Customer properties should not be set directly.', '2.7' );
53
		$key = $this->filter_legacy_key( $key );
54
		$this->_data[ $key ] = $value;
55
		$this->_changed = true;
56
	}
57
58
	/**
59
	 * Address and shipping_address are aliased, so we want to get the 'real' key name.
60
	 * For all other keys, we can just return it.
61
	 * @since 2.7.0
62
	 * @param  string $key
63
	 * @return string
64
	 */
65
	private function filter_legacy_key( $key ) {
66
		if ( 'address' === $key ) {
67
			$key = 'address_1';
68
		}
69
		if ( 'shipping_address' === $key ) {
70
			$key = 'shipping_address_1';
71
		}
72
73
74
		return $key;
75
	}
76
77
	/**
78
	 * Is customer VAT exempt?
79
	 * @return bool
80
	 */
81
	public function is_vat_exempt() {
82
		_deprecated_function( 'WC_Customer::is_vat_exempt', '2.7', 'WC_Customer::get_is_vat_exempt' );
83
		return $this->get_is_vat_exempt();
0 ignored issues
show
Bug introduced by
The method get_is_vat_exempt() does not exist on WC_Legacy_Customer. Did you maybe mean is_vat_exempt()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
84
	}
85
86
	/**
87
	 * Has calculated shipping?
88
	 * @return bool
89
	 */
90
	public function has_calculated_shipping() {
91
		_deprecated_function( 'WC_Customer::has_calculated_shipping', '2.7', 'WC_Customer::get_calculated_shipping' );
92
		return $this->get_calculated_shipping();
0 ignored issues
show
Bug introduced by
The method get_calculated_shipping() does not exist on WC_Legacy_Customer. Did you maybe mean calculated_shipping()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
93
	}
94
95
	/**
96
	 * Get default country for a customer.
97
	 * @return string
98
	 */
99
	public function get_default_country() {
100
		_deprecated_function( 'WC_Customer::get_default_country', '2.7', 'wc_get_customer_default_location' );
101
		$default = wc_get_customer_default_location();
102
		return $default['country'];
103
	}
104
105
	/**
106
	 * Get default state for a customer.
107
	 * @return string
108
	 */
109
	public function get_default_state() {
110
		_deprecated_function( 'WC_Customer::get_default_state', '2.7', 'wc_get_customer_default_location' );
111
		$default = wc_get_customer_default_location();
112
		return $default['state'];
113
	}
114
115
	/**
116
	 * Set customer address to match shop base address.
117
	 */
118
	public function set_to_base() {
119
		_deprecated_function( 'WC_Customer::set_to_base', '2.7', 'WC_Customer::set_billing_address_to_base' );
120
		$this->set_billing_address_to_base();
121
	}
122
123
	/**
124
	 * Set customer shipping address to base address.
125
	 */
126
	public function set_shipping_to_base() {
127
		_deprecated_function( 'WC_Customer::set_shipping_to_base', '2.7', 'WC_Customer::set_shipping_address_to_base' );
128
		$this->set_shipping_address_to_base();
129
	}
130
131
	/**
132
	 * Calculated shipping.
133
	 * @param boolean $calculated
134
	 */
135
	public function calculated_shipping( $calculated = true ) {
136
		_deprecated_function( 'WC_Customer::calculated_shipping', '2.7', 'WC_Customer::set_calculated_shipping' );
137
		$this->set_calculated_shipping( $calculated );
0 ignored issues
show
Bug introduced by
The method set_calculated_shipping() does not exist on WC_Legacy_Customer. Did you maybe mean calculated_shipping()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
138
	}
139
140
	/**
141
	 * Set default data for a customer.
142
	 */
143
	public function set_default_data() {
144
		_deprecated_function( 'WC_Customer::set_default_data', '2.7', '' );
145
	}
146
147
	/**
148
	 * Is the user a paying customer?
149
	 * @todo should this be moved to a get_ readonly?
150
	 * @return bool
151
	 */
152
	function is_paying_customer( $user_id = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
153
		_deprecated_function( 'WC_Customer::is_paying_customer', '2.7', 'WC_Customer::get_is_paying_customer' );
154
		if ( ! empty( $user_id ) ) {
155
			$user_id = get_current_user_id();
156
		}
157
		return '1' === get_user_meta( $user_id, 'paying_customer', true );
158
	}
159
160
	/**
161
	 * Legacy get country.
162
	 */
163
	function get_country() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
164
		_deprecated_function( 'WC_Customer::get_country', '2.7', 'WC_Customer::get_billing_country' );
165
		return $this->get_billing_country();
166
	}
167
168
	/**
169
	 * Legacy get state.
170
	 */
171
	function get_state() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
172
		_deprecated_function( 'WC_Customer::get_state', '2.7', 'WC_Customer::get_billing_state' );
173
		return $this->get_billing_state();
174
	}
175
176
	/**
177
	 * Legacy get postcode.
178
	 */
179
	function get_postcode() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
180
		_deprecated_function( 'WC_Customer::get_postcode', '2.7', 'WC_Customer::get_billing_postcode' );
181
		return $this->get_billing_postcode();
182
	}
183
184
	/**
185
	 * Legacy get city.
186
	 */
187
	function get_city() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
188
		_deprecated_function( 'WC_Customer::get_city', '2.7', 'WC_Customer::get_billing_city' );
189
		return $this->get_billing_city();
190
	}
191
192
	/**
193
	 * Legacy set country.
194
	 */
195
	function set_country( $country ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
196
		_deprecated_function( 'WC_Customer::set_country', '2.7', 'WC_Customer::set_billing_country' );
197
		$this->set_billing_country( $country );
198
	}
199
200
	/**
201
	 * Legacy set state.
202
	 */
203
	function set_state( $state ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
204
		_deprecated_function( 'WC_Customer::set_state', '2.7', 'WC_Customer::set_billing_state' );
205
		$this->set_billing_state( $state );
206
	}
207
208
	/**
209
	 * Legacy set postcode.
210
	 */
211
	function set_postcode( $postcode ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
212
		_deprecated_function( 'WC_Customer::set_postcode', '2.7', 'WC_Customer::set_billing_postcode' );
213
		$this->set_billing_postcode( $postcode );
214
	}
215
216
	/**
217
	 * Legacy set city.
218
	 */
219
	function set_city( $city ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
220
		_deprecated_function( 'WC_Customer::set_city', '2.7', 'WC_Customer::set_billing_city' );
221
		$this->set_billing_city( $city );
222
	}
223
224
	/**
225
	 * Legacy set address.
226
	 */
227
	function set_address( $address ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
228
		_deprecated_function( 'WC_Customer::set_address', '2.7', 'WC_Customer::set_billing_address' );
229
		$this->set_billing_address( $address );
230
	}
231
232
	/**
233
	 * Legacy set address.
234
	 */
235
	function set_address_2( $address ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
236
		_deprecated_function( 'WC_Customer::set_address_2', '2.7', 'WC_Customer::set_billing_address_2' );
237
		$this->set_billing_address_2( $address );
238
	}
239
240
}
241