Completed
Pull Request — master (#11821)
by Mike
14:32
created

WC_Legacy_Customer::has_calculated_shipping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
			'id', '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 is_callable( array( $this, "get_{$key}" ) ) ? $this->{"get_{$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
55
		if ( is_callable( array( $this, "set_{$key}" ) ) ) {
56
			$this->{"set_{$key}"}( $value );
57
		}
58
	}
59
60
	/**
61
	 * Address and shipping_address are aliased, so we want to get the 'real' key name.
62
	 * For all other keys, we can just return it.
63
	 * @since 2.7.0
64
	 * @param  string $key
65
	 * @return string
66
	 */
67
	private function filter_legacy_key( $key ) {
68
		if ( 'address' === $key ) {
69
			$key = 'address_1';
70
		}
71
		if ( 'shipping_address' === $key ) {
72
			$key = 'shipping_address_1';
73
		}
74
		return $key;
75
	}
76
77
	/**
78
	 * Sets session data for the location.
79
	 *
80
	 * @param string $country
81
	 * @param string $state
82
	 * @param string $postcode (default: '')
83
	 * @param string $city (default: '')
84
	 */
85
	public function set_location( $country, $state, $postcode = '', $city = '' ) {
86
		$this->set_billing_location( $country, $state, $postcode, $city );
87
		$this->set_shipping_location( $country, $state, $postcode, $city );
88
	}
89
90
	/**
91
	 * Get default country for a customer.
92
	 * @return string
93
	 */
94
	public function get_default_country() {
95
		_deprecated_function( 'WC_Customer::get_default_country', '2.7', 'wc_get_customer_default_location' );
96
		$default = wc_get_customer_default_location();
97
		return $default['country'];
98
	}
99
100
	/**
101
	 * Get default state for a customer.
102
	 * @return string
103
	 */
104
	public function get_default_state() {
105
		_deprecated_function( 'WC_Customer::get_default_state', '2.7', 'wc_get_customer_default_location' );
106
		$default = wc_get_customer_default_location();
107
		return $default['state'];
108
	}
109
110
	/**
111
	 * Set customer address to match shop base address.
112
	 */
113
	public function set_to_base() {
114
		_deprecated_function( 'WC_Customer::set_to_base', '2.7', 'WC_Customer::set_billing_address_to_base' );
115
		$this->set_billing_address_to_base();
116
	}
117
118
	/**
119
	 * Set customer shipping address to base address.
120
	 */
121
	public function set_shipping_to_base() {
122
		_deprecated_function( 'WC_Customer::set_shipping_to_base', '2.7', 'WC_Customer::set_shipping_address_to_base' );
123
		$this->set_shipping_address_to_base();
124
	}
125
126
	/**
127
	 * Calculated shipping.
128
	 * @param boolean $calculated
129
	 */
130
	public function calculated_shipping( $calculated = true ) {
131
		_deprecated_function( 'WC_Customer::calculated_shipping', '2.7', 'WC_Customer::set_calculated_shipping' );
132
		$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...
133
	}
134
135
	/**
136
	 * Set default data for a customer.
137
	 */
138
	public function set_default_data() {
139
		_deprecated_function( 'WC_Customer::set_default_data', '2.7', '' );
140
	}
141
142
	/**
143
	 * Is the user a paying customer?
144
	 * @todo should this be moved to a get_ readonly?
145
	 * @return bool
146
	 */
147
	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...
148
		_deprecated_function( 'WC_Customer::is_paying_customer', '2.7', 'WC_Customer::get_is_paying_customer' );
149
		if ( ! empty( $user_id ) ) {
150
			$user_id = get_current_user_id();
151
		}
152
		return '1' === get_user_meta( $user_id, 'paying_customer', true );
153
	}
154
155
	/**
156
	 * Legacy get country.
157
	 */
158
	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...
159
		_deprecated_function( 'WC_Customer::get_country', '2.7', 'WC_Customer::get_billing_country' );
160
		return $this->get_billing_country();
161
	}
162
163
	/**
164
	 * Legacy get state.
165
	 */
166
	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...
167
		_deprecated_function( 'WC_Customer::get_state', '2.7', 'WC_Customer::get_billing_state' );
168
		return $this->get_billing_state();
169
	}
170
171
	/**
172
	 * Legacy get postcode.
173
	 */
174
	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...
175
		_deprecated_function( 'WC_Customer::get_postcode', '2.7', 'WC_Customer::get_billing_postcode' );
176
		return $this->get_billing_postcode();
177
	}
178
179
	/**
180
	 * Legacy get city.
181
	 */
182
	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...
183
		_deprecated_function( 'WC_Customer::get_city', '2.7', 'WC_Customer::get_billing_city' );
184
		return $this->get_billing_city();
185
	}
186
187
	/**
188
	 * Legacy set country.
189
	 */
190
	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...
191
		_deprecated_function( 'WC_Customer::set_country', '2.7', 'WC_Customer::set_billing_country' );
192
		$this->set_billing_country( $country );
193
	}
194
195
	/**
196
	 * Legacy set state.
197
	 */
198
	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...
199
		_deprecated_function( 'WC_Customer::set_state', '2.7', 'WC_Customer::set_billing_state' );
200
		$this->set_billing_state( $state );
201
	}
202
203
	/**
204
	 * Legacy set postcode.
205
	 */
206
	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...
207
		_deprecated_function( 'WC_Customer::set_postcode', '2.7', 'WC_Customer::set_billing_postcode' );
208
		$this->set_billing_postcode( $postcode );
209
	}
210
211
	/**
212
	 * Legacy set city.
213
	 */
214
	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...
215
		_deprecated_function( 'WC_Customer::set_city', '2.7', 'WC_Customer::set_billing_city' );
216
		$this->set_billing_city( $city );
217
	}
218
219
	/**
220
	 * Legacy set address.
221
	 */
222
	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...
223
		_deprecated_function( 'WC_Customer::set_address', '2.7', 'WC_Customer::set_billing_address' );
224
		$this->set_billing_address( $address );
225
	}
226
227
	/**
228
	 * Legacy set address.
229
	 */
230
	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...
231
		_deprecated_function( 'WC_Customer::set_address_2', '2.7', 'WC_Customer::set_billing_address_2' );
232
		$this->set_billing_address_2( $address );
233
	}
234
235
}
236