Completed
Pull Request — master (#9826)
by Mike
15:37
created

WC_Shipping_Legacy_International_Delivery   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1
Metric Value
wmc 11
lcom 3
cbo 1
dl 0
loc 63
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A get_option_key() 0 3 1
A init_form_fields() 0 14 1
B is_available() 0 15 8
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * International Delivery - Based on the Flat Rate Shipping Method.
8
 *
9
 * This class is here for backwards commpatility for methods existing before zones existed.
10
 *
11
 * @deprecated  2.6.0
12
 * @version		2.4.0
13
 * @package		WooCommerce/Classes/Shipping
14
 * @author 		WooThemes
15
 */
16
class WC_Shipping_Legacy_International_Delivery extends WC_Shipping_Legacy_Flat_Rate {
0 ignored issues
show
Deprecated Code introduced by
The class WC_Shipping_Legacy_Flat_Rate has been deprecated with message: 2.6.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
17
18
	/**
19
	 * Constructor.
20
	 */
21
	public function __construct() {
22
		$this->id                 = 'legacy_international_delivery';
23
		$this->method_title       = __( 'International Flat Rate (Legacy)', 'woocommerce' );
24
		$this->method_description = sprintf( __( '<strong>This method is deprecated in 2.6.0 and will be removed in future versions - we recommend disabling it and instead setting up a new rate within your <a href="%s">Shipping Zones</a>.</strong>', 'woocommerce' ), admin_url( 'admin.php?page=wc-shipping' ) );
25
		$this->init();
26
27
		add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
28
	}
29
30
	/**
31
	 * Return the name of the option in the WP DB.
32
	 * @since 2.6.0
33
	 * @return string
34
	 */
35
	public function get_option_key() {
36
		return $this->plugin_id . 'international_delivery' . '_settings';
37
	}
38
39
	/**
40
	 * Initialise settings form fields.
41
	 */
42
	public function init_form_fields() {
43
		parent::init_form_fields();
44
		$this->form_fields['availability'] = array(
45
			'title'			=> __( 'Availability', 'woocommerce' ),
46
			'type'			=> 'select',
47
			'class'         => 'wc-enhanced-select',
48
			'description'	=> '',
49
			'default'		=> 'including',
50
			'options'		=> array(
51
				'including' => __( 'Selected countries', 'woocommerce' ),
52
				'excluding' => __( 'Excluding selected countries', 'woocommerce' ),
53
			)
54
		);
55
	}
56
57
	/**
58
	 * is_available function.
59
	 *
60
	 * @param array $package
61
	 * @return bool
62
	 */
63
	public function is_available( $package ) {
64
		if ( "no" === $this->enabled ) {
65
			return false;
66
		}
67
		if ( 'including' === $this->availability ) {
0 ignored issues
show
Deprecated Code introduced by
The property WC_Shipping_Method::$availability has been deprecated with message: 2.6.0

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
68
			if ( is_array( $this->countries ) && ! in_array( $package['destination']['country'], $this->countries ) ) {
0 ignored issues
show
Deprecated Code introduced by
The property WC_Shipping_Method::$countries has been deprecated with message: 2.6.0

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
69
				return false;
70
			}
71
		} else {
72
			if ( is_array( $this->countries ) && ( in_array( $package['destination']['country'], $this->countries ) || ! $package['destination']['country'] ) ) {
0 ignored issues
show
Deprecated Code introduced by
The property WC_Shipping_Method::$countries has been deprecated with message: 2.6.0

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
73
				return false;
74
			}
75
		}
76
		return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true, $package );
77
	}
78
}
79