Passed
Push — master ( 037742...36c501 )
by Warwick
02:17
created

LSX_WETU_Importer_Destination   F

Complexity

Total Complexity 145

Size/Duplication

Total Lines 773
Duplicated Lines 27.43 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 212
loc 773
rs 1.827
c 0
b 0
f 0
wmc 145
lcom 1
cbo 1

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set_variables() 16 16 5
C display_page() 3 194 8
A find_current_destination() 27 27 4
F process_ajax_search() 42 110 28
A prepare_row_attributes() 10 10 1
A format_row() 27 27 3
C process_ajax_import() 15 50 15
A remove_from_queue() 11 11 3
F import_row() 38 141 52
A set_team_member() 7 7 2
A set_travel_info() 0 11 4
B set_continent() 0 20 6
A update_options() 12 12 4
A update_options_form() 0 11 4
A check_for_parent() 0 11 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like LSX_WETU_Importer_Destination often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use LSX_WETU_Importer_Destination, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @package   LSX_WETU_Importer_Destination
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link
7
 * @copyright 2016 LightSpeed
8
 **/
9
10
class LSX_WETU_Importer_Destination extends LSX_WETU_Importer {
11
12
	/**
13
	 * The url to list items from WETU
14
	 *
15
	 * @since 0.0.1
16
	 *
17
	 * @var      string
18
	 */
19
	public $tab_slug = 'destination';
20
21
	/**
22
	 * The url to list items from WETU
23
	 *
24
	 * @since 0.0.1
25
	 *
26
	 * @var      string
27
	 */
28
	public $url = false;
29
30
	/**
31
	 * The query string url to list items from WETU
32
	 *
33
	 * @since 0.0.1
34
	 *
35
	 * @var      string
36
	 */
37
	public $url_qs = false;
38
39
	/**
40
	 * Options
41
	 *
42
	 * @since 0.0.1
43
	 *
44
	 * @var      string
45
	 */
46
	public $options = false;
47
48
	/**
49
	 * The fields you wish to import
50
	 *
51
	 * @since 0.0.1
52
	 *
53
	 * @var      string
54
	 */
55
	public $destination_options = false;
56
57
	/**
58
	 * Initialize the plugin by setting localization, filters, and administration functions.
59
	 *
60
	 * @since 1.0.0
61
	 *
62
	 * @access private
63
	 */
64
	public function __construct() {
65
		$this->set_variables();
66
	}
67
68
	/**
69
	 * Sets the variables used throughout the plugin.
70
	 */
71 View Code Duplication
	public function set_variables() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
		parent::set_variables();
73
		$this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
74
		$this->url_qs = 'all=include';
75
		$temp_options = get_option( '_lsx-to_settings', false );
76
77
		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
78
			$this->options = $temp_options[ $this->plugin_slug ];
79
		}
80
81
		$destination_options = get_option( 'lsx_wetu_importer_destination_settings', false );
82
83
		if ( false !== $destination_options ) {
84
			$this->destination_options = $destination_options;
85
		}
86
	}
87
88
	/**
89
	 * Display the importer administration screen
90
	 */
91
	public function display_page() {
92
		?>
93
		<div class="wrap">
94
			<div class="tablenav top">
95
				<?php $this->search_form(); ?>
96
			</div>
97
98
			<form method="get" action="" id="posts-filter">
99
				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>"/>
100
101
				<table class="wp-list-table widefat fixed posts">
102
					<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_WETU_Importer_Destination::table_header() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
103
104
					<tbody id="the-list">
105
					<tr class="post-0 type-tour status-none" id="post-0">
106
						<th class="check-column" scope="row">
107
							<label for="cb-select-0"
108
								   class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'lsx-wetu-importer' ); ?></label>
109
						</th>
110
						<td class="post-title page-title column-title">
111
							<strong>
112
								<?php esc_html_e( 'Enter a title to search for', 'lsx-wetu-importer' ); ?>
113
							</strong>
114
						</td>
115
						<td class="date column-date">
116
						</td>
117
						<td class="ssid column-ssid">
118
						</td>
119
					</tr>
120
					</tbody>
121
122
					<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_WETU_Importer_Destination::table_footer() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
123
124
				</table>
125
126
				<p><input class="button button-primary add" type="button"
127
						  value="<?php esc_html_e( 'Add to List', 'lsx-wetu-importer' ); ?>"/>
128
					<input class="button button-primary clear" type="button"
129
						   value="<?php esc_html_e( 'Clear', 'lsx-wetu-importer' ); ?>"/>
130
				</p>
131
			</form>
132
133
			<div style="display:none;" class="import-list-wrapper">
134
				<br/>
135
				<form method="get" action="" id="import-list">
136
137
					<div class="row">
138
						<div class="settings-all" style="width:30%;display:block;float:left;">
139
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
140
							<ul>
141
								<li>
142
									<input class="content select-all" <?php $this->checked( $this->destination_options, 'all' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
143
										   type="checkbox" name="content[]"
144
										   value="all"/> <?php esc_html_e( 'Select All', 'lsx-wetu-importer' ); ?></li>
145
								<?php if ( isset( $this->options ) && isset( $this->options['disable_destination_descriptions'] ) && 'on' !== $this->options['disable_destination_descriptions'] ) { ?>
146
								<li>
147
									<input class="content" <?php $this->checked( $this->destination_options, 'description' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
148
										   type="checkbox" name="content[]"
149
										   value="description"/> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
150
								<?php } ?>
151
152
								<li>
153
									<input class="content" <?php $this->checked( $this->destination_options, 'gallery' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
154
										   type="checkbox" name="content[]"
155
										   value="gallery"/> <?php esc_html_e( 'Main Gallery', 'lsx-wetu-importer' ); ?></li>
156
								<?php if ( class_exists( 'LSX_TO_Maps' ) ) { ?>
157
									<li>
158
										<input class="content" <?php $this->checked( $this->destination_options, 'location' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
159
											   type="checkbox" name="content[]"
160
											   value="location"/> <?php esc_html_e( 'Location', 'lsx-wetu-importer' ); ?></li>
161
								<?php } ?>
162
163
								<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?>
164
									<li>
165
										<input class="content" <?php $this->checked( $this->destination_options, 'videos' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
166
											   type="checkbox" name="content[]"
167
											   value="videos"/> <?php esc_html_e( 'Videos', 'lsx-wetu-importer' ); ?></li>
168
								<?php } ?>
169
170
							</ul>
171
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
172
							<ul>
173
								<li>
174
									<input class="content" <?php $this->checked( $this->destination_options, 'country' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
										   type="checkbox" name="content[]"
176
										   value="country"/> <?php esc_html_e( 'Set Country', 'lsx-wetu-importer' ); ?></li>
177
								<li>
178
									<input class="content" <?php $this->checked( $this->destination_options, 'continent' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
179
										   type="checkbox" name="content[]"
180
										   value="continent"/> <?php esc_html_e( 'Set Continent', 'lsx-wetu-importer' ); ?></li>
181
182
								<li>
183
									<input class="content" <?php $this->checked( $this->destination_options, 'featured_image' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
184
										   type="checkbox" name="content[]"
185
										   value="featured_image"/> <?php esc_html_e( 'Set Featured Image', 'lsx-wetu-importer' ); ?>
186
								</li>
187
								<?php if ( class_exists( 'LSX_Banners' ) ) { ?>
188
									<li>
189
										<input class="content" <?php $this->checked( $this->destination_options, 'banner_image' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
190
											   type="checkbox" name="content[]"
191
											   value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?>
192
									</li>
193
									<li>
194
										<input class="content" <?php $this->checked( $this->destination_options, 'unique_banner_image' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
195
											   type="checkbox" name="content[]"
196
											   value="unique_banner_image"/> <?php esc_html_e( 'Use the WETU banner field', 'lsx-wetu-importer' ); ?>
197
									</li>
198
								<?php } ?>
199
200
								<li>
201
									<input class="content" <?php $this->checked( $this->destination_options, 'strip_tags' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
202
										   type="checkbox" name="content[]"
203
										   value="strip_tags"/> <?php esc_html_e( 'Strip HTML from the description', 'lsx-wetu-importer' ); ?></li>
204
							</ul>
205
						</div>
206
						<div class="settings-all" style="width:30%;display:block;float:left;">
207
							<h3><?php esc_html_e( 'Travel Information' ); ?></h3>
208
							<ul>
209
								<li>
210
									<input class="content" <?php $this->checked( $this->destination_options, 'electricity' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
211
										   type="checkbox" name="content[]"
212
										   value="electricity"/> <?php esc_html_e( 'Electricity', 'lsx-wetu-importer' ); ?></li>
213
								<li>
214
									<input class="content" <?php $this->checked( $this->destination_options, 'banking' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
215
										   type="checkbox" name="content[]"
216
										   value="banking"/> <?php esc_html_e( 'Banking', 'lsx-wetu-importer' ); ?></li>
217
								<li>
218
									<input class="content" <?php $this->checked( $this->destination_options, 'cuisine' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
219
										   type="checkbox" name="content[]"
220
										   value="cuisine"/> <?php esc_html_e( 'Cuisine', 'lsx-wetu-importer' ); ?></li>
221
								<li>
222
									<input class="content" <?php $this->checked( $this->destination_options, 'climate' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
223
										   type="checkbox" name="content[]"
224
										   value="climate"/> <?php esc_html_e( 'Climate', 'lsx-wetu-importer' ); ?></li>
225
								<li>
226
									<input class="content" <?php $this->checked( $this->destination_options, 'transport' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
227
										   type="checkbox" name="content[]"
228
										   value="transport"/> <?php esc_html_e( 'Transport', 'lsx-wetu-importer' ); ?></li>
229
								<li><input class="content" <?php $this->checked( $this->destination_options, 'dress' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
230
										   type="checkbox" name="content[]"
231
										   value="dress"/> <?php esc_html_e( 'Dress', 'lsx-wetu-importer' ); ?></li>
232
								<li><input class="content" <?php $this->checked( $this->destination_options, 'health' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
233
										   type="checkbox" name="content[]"
234
										   value="health"/> <?php esc_html_e( 'Health', 'lsx-wetu-importer' ); ?></li>
235
								<li><input class="content" <?php $this->checked( $this->destination_options, 'safety' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
236
										   type="checkbox" name="content[]"
237
										   value="safety"/> <?php esc_html_e( 'Safety', 'lsx-wetu-importer' ); ?></li>
238
								<li><input class="content" <?php $this->checked( $this->destination_options, 'visa' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
239
										   type="checkbox" name="content[]"
240
										   value="visa"/> <?php esc_html_e( 'Visa', 'lsx-wetu-importer' ); ?></li>
241
								<li><input class="content" <?php $this->checked( $this->destination_options, 'additional_info' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
242
										   type="checkbox" name="content[]"
243
										   value="additional_info"/> <?php esc_html_e( 'General', 'lsx-wetu-importer' ); ?></li>
244
							</ul>
245
						</div>
246
247
						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
248
							<div style="width:30%;display:block;float:left;">
249
								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
250
								<?php $this->team_member_checkboxes( $this->destination_options ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
251
							</div>
252
						<?php } ?>
253
254
						<br clear="both"/>
255
					</div>
256
257
258
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
259
					<p><input class="button button-primary" type="submit"
260
							  value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>"/></p>
261
					<table class="wp-list-table widefat fixed posts">
262
						<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_WETU_Importer_Destination::table_header() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
263
264
						<tbody>
265
266
						</tbody>
267
268
						<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_WETU_Importer_Destination::table_footer() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
269
270
					</table>
271
272
					<p><input class="button button-primary" type="submit"
273
							  value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>"/></p>
274
				</form>
275
			</div>
276
277
			<div style="display:none;" class="completed-list-wrapper">
278
				<h3><?php esc_html_e( 'Completed' ); ?></h3>
279
				<ul>
280
				</ul>
281
			</div>
282
		</div>
283
		<?php
284
	}
285
286
	/**
287
	 * Grab all the current destination posts via the lsx_wetu_id field.
288
	 */
289 View Code Duplication
	public function find_current_destination( $post_type = 'destination' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290
		global $wpdb;
291
		$return = array();
292
293
		// @codingStandardsIgnoreStart
294
		$current_destination = $wpdb->get_results("
295
			SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified
296
			FROM {$wpdb->postmeta} key1
297
298
			INNER JOIN  {$wpdb->posts} key2
299
			ON key1.post_id = key2.ID
300
301
			WHERE key1.meta_key = 'lsx_wetu_id'
302
			AND key2.post_type = '{$post_type}'
303
304
			LIMIT 0,1000
305
		");
306
		// @codingStandardsIgnoreEnd
307
308
		if ( null !== $current_destination && ! empty( $current_destination ) ) {
309
			foreach ( $current_destination as $accom ) {
310
				$return[ $accom->meta_value ] = $accom;
311
			}
312
		}
313
314
		return $return;
315
	}
316
317
	/**
318
	 * Run through the accommodation grabbed from the DB.
319
	 */
320
	public function process_ajax_search() {
321
		$return = false;
322
323
		// @codingStandardsIgnoreLine
324
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_tour_importer' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' ) {
325
326
			$searched_items = false;
327
328
			// @codingStandardsIgnoreLine
329 View Code Duplication
			if ( isset( $_POST['keyword'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
330
				// @codingStandardsIgnoreLine
331
				$keyphrases = $_POST['keyword'];
332
			} else {
333
				$keyphrases = array( 0 );
334
			}
335
336
			if ( ! is_array( $keyphrases ) ) {
337
				$keyphrases = array( $keyphrases );
338
			}
339
			foreach ( $keyphrases as &$keyword ) {
340
				$keyword = ltrim( rtrim( $keyword ) );
341
			}
342
343
			$post_status = false;
344
345
			if ( in_array( 'publish', $keyphrases ) ) {
346
				$post_status = 'publish';
347
			}
348
			if ( in_array( 'pending', $keyphrases ) ) {
349
				$post_status = 'pending';
350
			}
351
			if ( in_array( 'draft', $keyphrases ) ) {
352
				$post_status = 'draft';
353
			}
354
			if ( in_array( 'import', $keyphrases ) ) {
355
				$post_status = 'import';
356
			}
357
358
			// If there is a post status use it.
359
			if ( false !== $post_status ) {
360
361
				$accommodation = array();
362
				$current_accommodation = $this->find_current_accommodation( 'destination' );
363 View Code Duplication
				if ( ! empty( $current_accommodation ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
364
					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
365
						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
366
					}
367
				}
368
369
				// Run through each accommodation and use it.
370 View Code Duplication
				if ( ! empty( $accommodation ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
371
					foreach ( $accommodation as $row_key => $row ) {
372
						if ( 'import' === $post_status ) {
373
374
							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
375
								$current_status = get_post_status( $row['post_id'] );
376
								if ( 'draft' === $current_status ) {
377
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
378
								}
379
							} else {
380
								continue;
381
							}
382
						} else {
383
							if ( 0 === $row['post_id'] ) {
384
								continue;
385
							} else {
386
								$current_status = get_post_status( $row['post_id'] );
387
388
								if ( $current_status !== $post_status ) {
389
									continue;
390
								}
391
							}
392
							$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
393
						}
394
					}
395
				}
396
			} else {
397
398
				$key_string_search = implode( '+', $keyphrases );
399
				$search_data = file_get_contents( $this->url . '/Search/' . $key_string_search . '/?all=include' );
400
				$search_data = json_decode( $search_data, true );
401
402
				if ( ! isset( $search_data['error'] ) ) {
403
					foreach ( $search_data as $sdata ) {
404
405
						if ( 'Destination' !== trim( $sdata['type'] ) ) {
406
							continue;
407
						}
408
409
						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
0 ignored issues
show
Bug introduced by
The method get_post_id_by_key_value() does not seem to exist on object<LSX_WETU_Importer_Destination>.

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...
410 View Code Duplication
						if ( false === $temp_id ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
411
							$sdata['post_id'] = 0;
412
						} else {
413
							$sdata['post_id'] = $temp_id;
414
						}
415
						$searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata );
0 ignored issues
show
Documentation introduced by
$sdata is of type array<string,integer,{"post_id":"integer"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
416
					}
417
				}
418
			}
419
420
			if ( false !== $searched_items ) {
421
				ksort( $searched_items );
422
				$return = implode( $searched_items );
423
			}
424
425
			print_r( $return );
426
		}
427
428
		die();
429
	}
430
431 View Code Duplication
	public function prepare_row_attributes( $cs_key, $ccs_id ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
432
		$row_item = array(
433
			'id' => $cs_key,
434
			'type' => 'Destination',
435
			'name' => get_the_title( $ccs_id ),
436
			'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
437
			'post_id' => $ccs_id,
438
		);
439
		return $row_item;
440
	}
441
442
	/**
443
	 * Formats the row for output on the screen.
444
	 */
445 View Code Duplication
	public function format_row( $row = false ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
446
		if ( false !== $row ) {
447
448
			$status = 'import';
449
			if ( 0 !== $row['post_id'] ) {
450
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
451
			}
452
453
			$row_html = '
454
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
455
				<th class="check-column" scope="row">
456
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
457
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
458
				</th>
459
				<td class="post-title page-title column-title">
460
					<strong>' . $row['name'] . '</strong> - ' . $status . '
461
				</td>
462
				<td class="date column-date">
463
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
464
				</td>
465
				<td class="ssid column-ssid">
466
					' . $row['id'] . '
467
				</td>
468
			</tr>';
469
			return $row_html;
470
		}
471
	}
472
473
	/**
474
	 * Connect to wetu
475
	 */
476
	public function process_ajax_import() {
477
		$return = false;
0 ignored issues
show
Unused Code introduced by
$return is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
478
479
		// @codingStandardsIgnoreLine
480
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' && isset( $_POST['wetu_id'] ) ) {
481
			// @codingStandardsIgnoreLine
482
			$wetu_id = $_POST['wetu_id'];
483
484
			// @codingStandardsIgnoreLine
485
			if ( isset( $_POST['post_id'] ) ) {
486
				// @codingStandardsIgnoreLine
487
				$post_id = $_POST['post_id'];
488
				$this->current_post = get_post( $post_id );
489
			} else {
490
				$post_id = 0;
491
			}
492
493
			// @codingStandardsIgnoreLine
494
			if ( isset( $_POST['team_members'] ) ) {
495
				// @codingStandardsIgnoreLine
496
				$team_members = $_POST['team_members'];
497
			} else {
498
				$team_members = false;
499
			}
500
501
			$safari_brands = false;
502
503
			delete_option( 'lsx_wetu_importer_destination_settings' );
504
505
			// @codingStandardsIgnoreLine
506 View Code Duplication
			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
507
				// @codingStandardsIgnoreLine
508
				$content = $_POST['content'];
509
				add_option( 'lsx_wetu_importer_destination_settings', $content );
510
			} else {
511
				$content = false;
512
			}
513
514
			$jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
515
516 View Code Duplication
			if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
517
				$adata = json_decode( $jdata, true );
518
				$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
519
				$this->remove_from_queue( $return );
520
				$this->format_completed_row( $return );
521
			} else {
522
				$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) );
523
			}
524
		}
525
	}
526
527
	/**
528
	 * Saves the queue to the option.
529
	 */
530 View Code Duplication
	public function remove_from_queue( $id ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
531
		if ( ! empty( $this->queued_imports ) ) {
532
			$key = array_search( $id, $this->queued_imports );
533
			if ( false !== $key ) {
534
				unset( $this->queued_imports[ $key ] );
535
536
				delete_option( 'lsx_wetu_importer_que' );
537
				update_option( 'lsx_wetu_importer_que', $this->queued_imports );
538
			}
539
		}
540
	}
541
542
	/**
543
	 * Connect to wetu
544
	 */
545
	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $safari_brands is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
546
		if ( 'Destination' === trim( $data[0]['type'] ) ) {
547
			$post_name = '';
548
			$data_post_content = '';
0 ignored issues
show
Unused Code introduced by
$data_post_content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
549
			$data_post_excerpt = '';
0 ignored issues
show
Unused Code introduced by
$data_post_excerpt is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
550
551
			$post = array(
552
				'post_type' => 'destination',
553
			);
554
555
			if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) {
556
				$parent = $this->check_for_parent( $data );
557
				if ( false !== $parent ) {
558
					$post['post_parent'] = $parent;
559
				}
560
			}
561
562
			// Set the post_content.
563
			if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
564
				if ( isset( $data[0]['content']['general_description'] ) ) {
565
566
					if ( in_array( 'strip_tags', $importable_content ) ) {
567
						$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
568
					} else {
569
						$post['post_content'] = $data[0]['content']['general_description'];
570
					}
571
				}
572
			}
573
574 View Code Duplication
			if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison !== seems to always evaluate to true as the types of '0' (string) and $id (integer) can never be identical. Maybe you want to use a loose comparison != instead?
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
575
				$post['ID'] = $id;
576
577
				if ( isset( $data[0]['name'] ) ) {
578
					$post['post_title'] = $data[0]['name'];
579
					$post['post_status'] = 'publish';
580
					$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
581
				}
582
583
				$id = wp_update_post( $post );
584
				$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
585
				update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
586
			} else {
587
				// Set the name.
588
				if ( isset( $data[0]['name'] ) ) {
589
					$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
590
				}
591
592
				$post['post_name'] = $post_name;
593
				$post['post_title'] = $data[0]['name'];
594
				$post['post_status'] = 'publish';
595
				$id = wp_insert_post( $post );
596
597
				// Save the WETU ID and the Last date it was modified.
598
				if ( false !== $id ) {
599
					add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
600
					add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
601
				}
602
			}
603
604
			$this->find_attachments( $id );
605
606
			// Set the team member if it is there.
607 View Code Duplication
			if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
608
				$this->set_team_member( $id, $team_members );
609
			}
610
611
			if ( class_exists( 'LSX_TO_Maps' ) ) {
612
				$this->set_map_data( $data, $id, 9 );
613
			}
614
615
			// Set the Room Data.
616
			if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
617
				$this->set_video_data( $data, $id );
618
			}
619
620
			// Set the Electricity.
621
			if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
622
				$this->set_travel_info( $data, $id, 'electricity', $importable_content );
623
			}
624
			// Set the cuisine.
625
			if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
626
				$this->set_travel_info( $data, $id, 'cuisine', $importable_content );
627
			}
628
			// Set the banking.
629
			if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
630
				$this->set_travel_info( $data, $id, 'banking', $importable_content );
631
			}
632
			// Set the transport.
633
			if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
634
				$this->set_travel_info( $data, $id, 'transport', $importable_content );
635
			}
636
			// Set the dress.
637
			if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
638
				$this->set_travel_info( $data, $id, 'dress', $importable_content );
639
			}
640
			// Set the climate.
641
			if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
642
				$this->set_travel_info( $data, $id, 'climate', $importable_content );
643
			}
644
			// Set the Health.
645
			if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
646
				$this->set_travel_info( $data, $id, 'health', $importable_content );
647
			}
648
			// Set the Safety.
649
			if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
650
				$this->set_travel_info( $data, $id, 'safety', $importable_content );
651
			}
652
			// Set the Visa.
653 View Code Duplication
			if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
654
				$this->set_travel_info( $data, $id, 'visa', $importable_content );
655
			}
656
			// Set the General.
657 View Code Duplication
			if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
658
				$this->set_travel_info( $data, $id, 'additional_info', $importable_content );
659
			}
660
661
			// Setup some default for use in the import.
662
			if ( false !== $importable_content && (in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content )) ) {
663
				$this->find_attachments( $id );
664
665
				// Set the featured image.
666
				if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
667
					$this->set_featured_image( $data, $id );
668
				}
669
				if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
670
					$this->set_banner_image( $data, $id, $importable_content );
671
				}
672
				// Import the main gallery.
673
				if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
674
					$this->create_main_gallery( $data, $id );
675
				}
676
			}
677
678
			// Set the continent.
679
			if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
680
				$this->set_continent( $data, $id );
681
			}
682
		}
683
684
		return $id;
685
	}
686
687
	/**
688
	 * Set the team memberon each item.
689
	 */
690 View Code Duplication
	public function set_team_member( $id, $team_members ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
691
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
692
693
		foreach ( $team_members as $team ) {
694
			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
695
		}
696
	}
697
698
	/**
699
	 * Saves the room data
700
	 */
701
	public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) {
702
		if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
703
			$content = $data[0]['travel_information'][ $meta_key ];
704
705
			if ( in_array( 'strip_tags', $importable ) ) {
706
				$content = strip_tags( $content );
707
			}
708
709
			$this->save_custom_field( $content, $meta_key, $id );
710
		}
711
	}
712
713
	/**
714
	 * Set the Travel Style
715
	 */
716
	public function set_continent( $data, $id ) {
717
718
		if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
719
			//get the continent code.
720
			$continent_code = to_continent_label( to_continent_code( to_country_data( $data[0]['position']['country'], false ) ) );
721
722
			if ( '' !== $continent_code ) {
723
				$term = term_exists( trim( $continent_code ), 'continent' );
724
				if ( ! $term ) {
725
					$term = wp_insert_term( trim( $continent_code ), 'continent' );
726
727
					if ( is_wp_error( $term ) ) {
728
						echo wp_kses_post( $term->get_error_message() );
729
					}
730
				} else {
731
					wp_set_object_terms( $id, sanitize_title( $continent_code ), 'continent', true );
732
				}
733
			}
734
		}
735
	}
736
737
	/**
738
	 * Save the list of Accommodation into an option
739
	 */
740 View Code Duplication
	public function update_options() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
741
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
742
743
		$accommodation = json_decode( $data, true );
744
745
		if ( isset( $accommodation['error'] ) ) {
746
			return $accommodation['error'];
747
		} elseif ( isset( $accommodation ) && ! empty( $accommodation ) ) {
748
			set_transient( 'lsx_ti_accommodation', $accommodation,60 * 60 * 2 );
749
			return true;
750
		}
751
	}
752
753
	/**
754
	 * search_form
755
	 */
756
	public function update_options_form() {
757
		echo '<div style="display:none;" class="wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . '</h3>';
758
759
		$accommodation = get_transient( 'lsx_ti_accommodation' );
760
761
		if ( '' === $accommodation || false === $accommodation || isset( $_GET['refresh_accommodation'] ) ) {
762
			$this->update_options();
763
		}
764
765
		echo '</div>';
766
	}
767
768
	/**
769
	 * Save the list of Accommodation into an option
770
	 */
771
	public function check_for_parent( $data = array() ) {
772
		global $wpdb;
773
774
		if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) {
775
			$result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) );
776
			if ( ! empty( $result ) && '' !== $result && false !== $result ) {
777
				return $result;
778
			}
779
		}
780
		return false;
781
	}
782
}
783