Passed
Push — master ( 3ad2f5...1dfce5 )
by Warwick
02:41
created

prepare_row_attributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   WETU_Importer_Destination
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link
7
 * @copyright 2016 LightSpeed
8
 **/
9
10
class WETU_Importer_Destination extends 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 request only works with API KEY **
74
		//if ( false !== $this->api_username && false !== $this->api_password ) {
75
		//	$this->url    = 'https://wetu.com/API/Pins/';
76
		//	$this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
77
		//} elseif ( false !== $this->api_key ) {
78
		$this->url = 'https://wetu.com/API/Pins/' . $this->api_key;
79
		$this->url_qs = 'all=include';
80
		//}
81
82
		$temp_options = get_option( '_lsx-to_settings', false );
83
84
		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
85
			$this->options = $temp_options[ $this->plugin_slug ];
86
		}
87
88
		$destination_options = get_option( 'wetu_importer_destination_settings', false );
89
90
		if ( false !== $destination_options ) {
91
			$this->destination_options = $destination_options;
92
		}
93
	}
94
95
	/**
96
	 * Display the importer administration screen
97
	 */
98
	public function display_page() {
99
		?>
100
		<div class="wrap">
101
			<?php $this->navigation( 'destination' ); ?>
102
103
			<?php $this->search_form(); ?>
104
105
			<form method="get" action="" id="posts-filter">
106
				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>"/>
107
108
				<p><input class="button button-primary add" type="button"
109
						  value="<?php esc_html_e( 'Add to List', 'wetu-importer' ); ?>"/>
110
					<input class="button button-primary clear" type="button"
111
						   value="<?php esc_html_e( 'Clear', 'wetu-importer' ); ?>"/>
112
				</p>
113
114
				<table class="wp-list-table widefat fixed posts">
115
					<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method 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...
116
117
					<tbody id="the-list">
118
					<tr class="post-0 type-tour status-none" id="post-0">
119
						<th class="check-column" scope="row">
120
							<label for="cb-select-0"
121
								   class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'wetu-importer' ); ?></label>
122
						</th>
123
						<td class="post-title page-title column-title">
124
							<strong>
125
								<?php esc_html_e( 'Enter a title to search for', 'wetu-importer' ); ?>
126
							</strong>
127
						</td>
128
						<td class="date column-date">
129
						</td>
130
						<td class="ssid column-ssid">
131
						</td>
132
					</tr>
133
					</tbody>
134
135
					<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method 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...
136
137
				</table>
138
139
				<p><input class="button button-primary add" type="button"
140
						  value="<?php esc_html_e( 'Add to List', 'wetu-importer' ); ?>"/>
141
					<input class="button button-primary clear" type="button"
142
						   value="<?php esc_html_e( 'Clear', 'wetu-importer' ); ?>"/>
143
				</p>
144
			</form>
145
146
			<div style="display:none;" class="import-list-wrapper">
147
				<br/>
148
				<form method="get" action="" id="import-list">
149
150
					<div class="row">
151
						<div class="settings-all" style="width:30%;display:block;float:left;">
152
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
153
							<ul>
154
								<li>
155
									<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...
156
										   type="checkbox" name="content[]"
157
										   value="all"/> <?php esc_html_e( 'Select All', 'wetu-importer' ); ?></li>
158
								<?php if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_descriptions'] ) { ?>
159
								<li>
160
									<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...
161
										   type="checkbox" name="content[]"
162
										   value="description"/> <?php esc_html_e( 'Description', 'wetu-importer' ); ?></li>
163
								<?php } ?>
164
165
								<li>
166
									<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...
167
										   type="checkbox" name="content[]"
168
										   value="gallery"/> <?php esc_html_e( 'Main Gallery', 'wetu-importer' ); ?></li>
169
								<?php if ( class_exists( 'LSX_TO_Maps' ) ) { ?>
170
									<li>
171
										<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...
172
											   type="checkbox" name="content[]"
173
											   value="location"/> <?php esc_html_e( 'Location', 'wetu-importer' ); ?></li>
174
								<?php } ?>
175
176
								<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?>
177
									<li>
178
										<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...
179
											   type="checkbox" name="content[]"
180
											   value="videos"/> <?php esc_html_e( 'Videos', 'wetu-importer' ); ?></li>
181
								<?php } ?>
182
183
							</ul>
184
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
185
							<ul>
186
								<li>
187
									<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...
188
										   type="checkbox" name="content[]"
189
										   value="country"/> <?php esc_html_e( 'Set Country', 'wetu-importer' ); ?></li>
190
								<li>
191
									<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...
192
										   type="checkbox" name="content[]"
193
										   value="continent"/> <?php esc_html_e( 'Set Continent', 'wetu-importer' ); ?></li>
194
195
								<li>
196
									<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...
197
										   type="checkbox" name="content[]"
198
										   value="featured_image"/> <?php esc_html_e( 'Set Featured Image', 'wetu-importer' ); ?>
199
								</li>
200
								<?php if ( class_exists( 'LSX_Banners' ) ) { ?>
201
									<li>
202
										<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...
203
											   type="checkbox" name="content[]"
204
											   value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'wetu-importer' ); ?>
205
									</li>
206
									<li>
207
										<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...
208
											   type="checkbox" name="content[]"
209
											   value="unique_banner_image"/> <?php esc_html_e( 'Use the WETU banner field', 'wetu-importer' ); ?>
210
									</li>
211
								<?php } ?>
212
213
								<li>
214
									<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...
215
										   type="checkbox" name="content[]"
216
										   value="strip_tags"/> <?php esc_html_e( 'Strip HTML from the description', 'wetu-importer' ); ?></li>
217
							</ul>
218
						</div>
219
						<div class="settings-all" style="width:30%;display:block;float:left;">
220
							<h3><?php esc_html_e( 'Travel Information' ); ?></h3>
221
							<ul>
222
								<li>
223
									<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...
224
										   type="checkbox" name="content[]"
225
										   value="electricity"/> <?php esc_html_e( 'Electricity', 'wetu-importer' ); ?></li>
226
								<li>
227
									<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...
228
										   type="checkbox" name="content[]"
229
										   value="banking"/> <?php esc_html_e( 'Banking', 'wetu-importer' ); ?></li>
230
								<li>
231
									<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...
232
										   type="checkbox" name="content[]"
233
										   value="cuisine"/> <?php esc_html_e( 'Cuisine', 'wetu-importer' ); ?></li>
234
								<li>
235
									<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...
236
										   type="checkbox" name="content[]"
237
										   value="climate"/> <?php esc_html_e( 'Climate', 'wetu-importer' ); ?></li>
238
								<li>
239
									<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...
240
										   type="checkbox" name="content[]"
241
										   value="transport"/> <?php esc_html_e( 'Transport', 'wetu-importer' ); ?></li>
242
								<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...
243
										   type="checkbox" name="content[]"
244
										   value="dress"/> <?php esc_html_e( 'Dress', 'wetu-importer' ); ?></li>
245
								<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...
246
										   type="checkbox" name="content[]"
247
										   value="health"/> <?php esc_html_e( 'Health', 'wetu-importer' ); ?></li>
248
								<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...
249
										   type="checkbox" name="content[]"
250
										   value="safety"/> <?php esc_html_e( 'Safety', 'wetu-importer' ); ?></li>
251
								<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...
252
										   type="checkbox" name="content[]"
253
										   value="visa"/> <?php esc_html_e( 'Visa', 'wetu-importer' ); ?></li>
254
								<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...
255
										   type="checkbox" name="content[]"
256
										   value="additional_info"/> <?php esc_html_e( 'General', 'wetu-importer' ); ?></li>
257
							</ul>
258
						</div>
259
260
						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
261
							<div style="width:30%;display:block;float:left;">
262
								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
263
								<?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...
264
							</div>
265
						<?php } ?>
266
267
						<br clear="both"/>
268
					</div>
269
270
271
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
272
					<p><input class="button button-primary" type="submit"
273
							  value="<?php esc_html_e( 'Sync', 'wetu-importer' ); ?>"/></p>
274
					<table class="wp-list-table widefat fixed posts">
275
						<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method 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...
276
277
						<tbody>
278
279
						</tbody>
280
281
						<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method 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...
282
283
					</table>
284
285
					<p><input class="button button-primary" type="submit"
286
							  value="<?php esc_html_e( 'Sync', 'wetu-importer' ); ?>"/></p>
287
				</form>
288
			</div>
289
290
			<div style="display:none;" class="completed-list-wrapper">
291
				<h3><?php esc_html_e( 'Completed' ); ?></h3>
292
				<ul>
293
				</ul>
294
			</div>
295
		</div>
296
		<?php
297
	}
298
299
	/**
300
	 * Grab all the current destination posts via the lsx_wetu_id field.
301
	 */
302 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...
303
		global $wpdb;
304
		$return = array();
305
306
		// @codingStandardsIgnoreStart
307
		$current_destination = $wpdb->get_results("
308
			SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified
309
			FROM {$wpdb->postmeta} key1
310
311
			INNER JOIN  {$wpdb->posts} key2
312
			ON key1.post_id = key2.ID
313
314
			WHERE key1.meta_key = 'lsx_wetu_id'
315
			AND key2.post_type = '{$post_type}'
316
317
			LIMIT 0,1000
318
		");
319
		// @codingStandardsIgnoreEnd
320
321
		if ( null !== $current_destination && ! empty( $current_destination ) ) {
322
			foreach ( $current_destination as $accom ) {
323
				$return[ $accom->meta_value ] = $accom;
324
			}
325
		}
326
327
		return $return;
328
	}
329
330
	/**
331
	 * Run through the accommodation grabbed from the DB.
332
	 */
333
	public function process_ajax_search() {
334
		$return = false;
335
336
		// @codingStandardsIgnoreLine
337
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_tour_importer' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' ) {
338
			$accommodation = get_transient( 'lsx_ti_accommodation' );
0 ignored issues
show
Unused Code introduced by
$accommodation 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...
339
340
			//if ( false === $accommodation ) {
341
				//$this->update_options();
342
			//}
343
344
			//if ( false !== $accommodation ) {
345
				$searched_items = false;
346
347
				// @codingStandardsIgnoreLine
348 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...
349
					// @codingStandardsIgnoreLine
350
					$keyphrases = $_POST['keyword'];
351
				} else {
352
					$keyphrases = array( 0 );
353
				}
354
355
				if ( ! is_array( $keyphrases ) ) {
356
					$keyphrases = array( $keyphrases );
357
				}
358
				foreach ( $keyphrases as &$keyword ) {
359
					$keyword = ltrim( rtrim( $keyword ) );
360
				}
361
362
				$post_status = false;
363
364
				if ( in_array( 'publish',$keyphrases ) ) {
365
					$post_status = 'publish';
366
				}
367
				if ( in_array( 'pending',$keyphrases ) ) {
368
					$post_status = 'pending';
369
				}
370
				if ( in_array( 'draft',$keyphrases ) ) {
371
					$post_status = 'draft';
372
				}
373
				if ( in_array( 'import',$keyphrases ) ) {
374
					$post_status = 'import';
375
				}
376
377
				$accommodation = array();
378
379
				$current_accommodation = $this->find_current_accommodation( 'destination' );
380 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...
381
					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
382
						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
383
					}
384
				}
385
386
				if ( ! empty( $accommodation ) ) {
387
388
					foreach ( $accommodation as $row_key => $row ) {
389
390
						//If this is a current tour, add its ID to the row.
391
392
						//If we are searching for
393 View Code Duplication
						if ( false !== $post_status ) {
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...
394
							if ( 'import' === $post_status ) {
395
396
								if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
397
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
398
								} else {
399
									continue;
400
								}
401
							} else {
402
								if ( 0 === $row['post_id'] ) {
403
									continue;
404
								} else {
405
									$current_status = get_post_status( $row['post_id'] );
406
407
									if ( $current_status !== $post_status ) {
408
										continue;
409
									}
410
								}
411
412
								$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
413
							}
414
						} else {
415
							//Search through each keyword.
416
							/*foreach ( $keyphrases as $keyphrase ) {
417
								//Make sure the keyphrase is turned into an array
418
								$keywords = explode( ' ', $keyphrase );
419
420
								if ( ! is_array( $keywords ) ) {
421
									$keywords = array( $keywords );
422
								}
423
424
								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
425
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
426
								}
427
							}*/
428
						}
429
					}
430
				}
431
432
				if ( false !== $searched_items ) {
433
					ksort( $searched_items );
434
					$return = implode( $searched_items );
435
				}
436
			//}
437
438
			print_r( $return );
439
		}
440
441
		die();
442
	}
443
444 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...
445
		return 	$row_item = array(
0 ignored issues
show
Unused Code introduced by
$row_item 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...
446
			'id' => $cs_key,
447
			'type' => 'Destination',
448
			'name' => get_the_title( $ccs_id ),
449
			'last_modified' => date('Y-m-d', strtotime( 'now' ) ),
450
			'post_id' => $ccs_id,
451
		);
452
	}
453
454
	/**
455
	 * Formats the row for output on the screen.
456
	 */
457 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...
458
		if ( false !== $row ) {
459
460
			$status = 'import';
461
			if ( 0 !== $row['post_id'] ) {
462
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
463
			}
464
465
			$row_html = '
466
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
467
				<th class="check-column" scope="row">
468
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
469
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
470
				</th>
471
				<td class="post-title page-title column-title">
472
					<strong>' . $row['name'] . '</strong> - ' . $status . '
473
				</td>
474
				<td class="date column-date">
475
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
476
				</td>
477
				<td class="ssid column-ssid">
478
					' . $row['id'] . '
479
				</td>
480
			</tr>';
481
			return $row_html;
482
		}
483
	}
484
485
	/**
486
	 * Connect to wetu
487
	 */
488
	public function process_ajax_import() {
489
		$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...
490
491
		// @codingStandardsIgnoreLine
492
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' && isset( $_POST['wetu_id'] ) ) {
493
			// @codingStandardsIgnoreLine
494
			$wetu_id = $_POST['wetu_id'];
495
496
			// @codingStandardsIgnoreLine
497
			if ( isset( $_POST['post_id'] ) ) {
498
				// @codingStandardsIgnoreLine
499
				$post_id = $_POST['post_id'];
500
				$this->current_post = get_post( $post_id );
501
			} else {
502
				$post_id = 0;
503
			}
504
505
			// @codingStandardsIgnoreLine
506
			if ( isset( $_POST['team_members'] ) ) {
507
				// @codingStandardsIgnoreLine
508
				$team_members = $_POST['team_members'];
509
			} else {
510
				$team_members = false;
511
			}
512
513
			$safari_brands = false;
514
515
			delete_option( 'wetu_importer_destination_settings' );
516
517
			// @codingStandardsIgnoreLine
518 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...
519
				// @codingStandardsIgnoreLine
520
				$content = $_POST['content'];
521
				add_option( 'wetu_importer_destination_settings', $content );
522
			} else {
523
				$content = false;
524
			}
525
526
			$jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
527
528 View Code Duplication
			if ( $jdata ) {
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...
529
				$adata = json_decode( $jdata, true );
530
531
				if ( ! empty( $adata ) && ! isset( $adata['error'] ) ) {
532
					$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
533
					$this->remove_from_queue( $return );
534
					$this->format_completed_row( $return );
535
				} else {
536
					if ( isset( $adata['error'] ) ) {
537
						$this->format_error( $adata['error'] );
538
					} else {
539
						$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.','wetu-importer' ) );
540
					}
541
				}
542
			}
543
		}
544
	}
545
546
	/**
547
	 * Saves the queue to the option.
548
	 */
549 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...
550
		if ( ! empty( $this->queued_imports ) ) {
551
			// @codingStandardsIgnoreLine
552
			if ( ( $key = array_search( $id, $this->queued_imports ) ) !== false ) {
553
				unset( $this->queued_imports[ $key ] );
554
555
				delete_option( 'wetu_importer_que' );
556
				update_option( 'wetu_importer_que',$this->queued_imports );
557
			}
558
		}
559
	}
560
561
	/**
562
	 * Connect to wetu
563
	 */
564
	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = false, $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...
565
		if ( 'Destination' === trim( $data[0]['type'] ) ) {
566
			$post_name = '';
567
			$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...
568
			$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...
569
570
			$post = array(
571
				'post_type' => 'destination',
572
			);
573
574
			if ( false !== $importable_content && in_array( 'country', $importable_content ) ) {
575
				$parent = $this->check_for_parent( $data );
576
				if( false !== $parent ) {
577
					$post['post_parent'] = $parent;
578
				}
579
			}
580
581
			//Set the post_content
582
			if ( false !== $importable_content && in_array( 'description', $importable_content ) ) {
583
				if ( isset( $data[0]['content']['general_description'] ) ) {
584
585
					if ( false !== $importable_content && in_array( 'strip_tags', $importable_content ) ) {
586
						$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
587
					} else {
588
						$post['post_content'] = $data[0]['content']['general_description'];
589
					}
590
				}
591
			}
592
593 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...
594
				$post['ID'] = $id;
595
596
				if ( isset( $data[0]['name'] ) ) {
597
					$post['post_title'] = $data[0]['name'];
598
					$post['post_status'] = 'publish';
599
					$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
600
				}
601
602
				$id = wp_update_post( $post );
603
				$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
604
				update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
605
			} else {
606
				//Set the name
607
				if ( isset( $data[0]['name'] ) ) {
608
					$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
609
				}
610
611
				$post['post_name'] = $post_name;
612
				$post['post_title'] = $data[0]['name'];
613
				$post['post_status'] = 'publish';
614
				$id = wp_insert_post( $post );
615
616
				//Save the WETU ID and the Last date it was modified.
617
				if ( false !== $id ) {
618
					add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
619
					add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
620
				}
621
			}
622
623
			$this->find_attachments( $id );
624
625
			//Set the team member if it is there
626 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...
627
				$this->set_team_member( $id, $team_members );
628
			}
629
630
			if ( class_exists( 'LSX_TO_Maps' ) ) {
631
				$this->set_map_data( $data, $id, 9 );
632
			}
633
634
			//Set the Room Data
635
			if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
636
				$this->set_video_data( $data, $id );
637
			}
638
639
			//Set the Electricity
640
			if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
641
				$this->set_travel_info( $data, $id, 'electricity', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
642
			}
643
			//Set the cuisine
644
			if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
645
				$this->set_travel_info( $data, $id, 'cuisine', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
646
			}
647
			//Set the banking
648
			if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
649
				$this->set_travel_info( $data, $id, 'banking', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
650
			}
651
			//Set the transport
652
			if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
653
				$this->set_travel_info( $data, $id, 'transport', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
654
			}
655
			//Set the dress
656
			if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
657
				$this->set_travel_info( $data, $id, 'dress', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
658
			}
659
			//Set the climate
660
			if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
661
				$this->set_travel_info( $data, $id, 'climate', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
662
			}
663
			//Set the Health
664
			if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
665
				$this->set_travel_info( $data, $id, 'health', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
666
			}
667
			//Set the Safety
668
			if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
669
				$this->set_travel_info( $data, $id, 'safety', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
670
			}
671
			//Set the Visa
672 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...
673
				$this->set_travel_info( $data, $id, 'visa', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
674
			}
675
			//Set the General
676 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...
677
				$this->set_travel_info( $data, $id, 'additional_info', $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
678
			}
679
680
			//Setup some default for use in the import
681
			if ( false !== $importable_content && (in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content )) ) {
682
				$this->find_attachments( $id );
683
684
				//Set the featured image
685
				if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
686
					$this->set_featured_image( $data, $id );
687
				}
688
				if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
689
					$this->set_banner_image( $data, $id, $importable_content );
0 ignored issues
show
Documentation introduced by
$importable_content is of type boolean, 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...
690
				}
691
				//Import the main gallery
692
				if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
693
					$this->create_main_gallery( $data, $id );
694
				}
695
			}
696
697
			//Set the continent
698
			if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
699
				$this->set_continent( $data, $id );
700
			}
701
		}
702
703
		return $id;
704
	}
705
706
	/**
707
	 * Set the team memberon each item.
708
	 */
709 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...
710
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
711
712
		foreach ( $team_members as $team ) {
713
			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
714
		}
715
	}
716
717
	/**
718
	 * Saves the room data
719
	 */
720
	public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) {
721
		if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
722
			$content = $data[0]['travel_information'][ $meta_key ];
723
724
			if ( in_array( 'strip_tags', $importable ) ) {
725
				$content = strip_tags( $content );
726
			}
727
728
			$this->save_custom_field( $content, $meta_key, $id );
729
		}
730
	}
731
732
	/**
733
	 * Set the Travel Style
734
	 */
735
	public function set_continent( $data, $id ) {
736
737
		if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
738
			//get the continent code.
739
			$continent_code = to_continent_label( to_continent_code( to_country_data( $data[0]['position']['country'], false ) ) );
740
741
			if ( '' !== $continent_code ) {
742
				// @codingStandardsIgnoreLine
743
				if ( ! $term = term_exists( trim( $continent_code ), 'continent' ) ) {
744
					$term = wp_insert_term( trim( $continent_code ), 'continent' );
745
746
					if ( is_wp_error( $term ) ) {
747
						// @codingStandardsIgnoreLine
748
						echo $term->get_error_message();
749
					}
750
				} else {
751
					wp_set_object_terms( $id, sanitize_title( $continent_code ), 'continent', true );
752
				}
753
			}
754
		}
755
	}
756
757
	/**
758
	 * Save the list of Accommodation into an option
759
	 */
760 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...
761
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
762
763
		$accommodation = json_decode( $data, true );
764
765
		if ( isset( $accommodation['error'] ) ) {
766
			return $accommodation['error'];
767
		} elseif ( isset( $accommodation ) && ! empty( $accommodation ) ) {
768
			set_transient( 'lsx_ti_accommodation',$accommodation,60 * 60 * 2 );
769
			return true;
770
		}
771
	}
772
773
	/**
774
	 * search_form
775
	 */
776
	public function update_options_form() {
777
		echo '<div style="display:none;" class="wetu-status"><h3>' . esc_html__( 'Wetu Status', 'wetu-importer' ) . '</h3>';
778
779
		$accommodation = get_transient( 'lsx_ti_accommodation' );
780
781
		if ( '' === $accommodation || false === $accommodation || isset( $_GET['refresh_accommodation'] ) ) {
782
			$this->update_options();
783
		}
784
785
		echo '</div>';
786
	}
787
788
	/**
789
	 * Save the list of Accommodation into an option
790
	 */
791
	public function check_for_parent( $data = array() ) {
792
		global $wpdb;
793
794
		if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) {
795
			$query = "
796
			SELECT post_id
797
			FROM {$wpdb->postmeta}
798
			WHERE meta_key = 'lsx_wetu_id'
799
			AND meta_value = {$data[0]['position']['country_content_entity_id']}";
800
801
			$result = $wpdb->get_var( $query );
802
803
			if( ! empty( $result ) && '' !== $result && false !== $result ) {
804
				return $result;
805
			}
806
		}
807
808
		return false;
809
	}
810
}
811