Passed
Push — master ( bb1a17...9cb74e )
by Warwick
02:14
created

LSX_WETU_Importer_Destination::display_page()   B

Complexity

Conditions 7
Paths 16

Size

Total Lines 195

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 16
nop 0
dl 0
loc 195
rs 7.0666
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
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' ); ?>
161
									</li>
162
163
164
								<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?>
165
									<li>
166
										<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...
167
											   type="checkbox" name="content[]"
168
											   value="videos"/> <?php esc_html_e( 'Videos', 'lsx-wetu-importer' ); ?></li>
169
								<?php } ?>
170
171
							</ul>
172
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
173
							<ul>
174
								<li>
175
									<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...
176
										   type="checkbox" name="content[]"
177
										   value="country"/> <?php esc_html_e( 'Set Country', 'lsx-wetu-importer' ); ?></li>
178
								<li>
179
									<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...
180
										   type="checkbox" name="content[]"
181
										   value="continent"/> <?php esc_html_e( 'Set Continent', 'lsx-wetu-importer' ); ?></li>
182
183
								<li>
184
									<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...
185
										   type="checkbox" name="content[]"
186
										   value="featured_image"/> <?php esc_html_e( 'Set Featured Image', 'lsx-wetu-importer' ); ?>
187
								</li>
188
								<?php if ( class_exists( 'LSX_Banners' ) ) { ?>
189
									<li>
190
										<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...
191
											   type="checkbox" name="content[]"
192
											   value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?>
193
									</li>
194
									<li>
195
										<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...
196
											   type="checkbox" name="content[]"
197
											   value="unique_banner_image"/> <?php esc_html_e( 'Use the WETU banner field', 'lsx-wetu-importer' ); ?>
198
									</li>
199
								<?php } ?>
200
201
								<li>
202
									<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...
203
										   type="checkbox" name="content[]"
204
										   value="strip_tags"/> <?php esc_html_e( 'Strip HTML from the description', 'lsx-wetu-importer' ); ?></li>
205
							</ul>
206
						</div>
207
						<div class="settings-all" style="width:30%;display:block;float:left;">
208
							<h3><?php esc_html_e( 'Travel Information' ); ?></h3>
209
							<ul>
210
								<li>
211
									<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...
212
										   type="checkbox" name="content[]"
213
										   value="electricity"/> <?php esc_html_e( 'Electricity', 'lsx-wetu-importer' ); ?></li>
214
								<li>
215
									<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...
216
										   type="checkbox" name="content[]"
217
										   value="banking"/> <?php esc_html_e( 'Banking', 'lsx-wetu-importer' ); ?></li>
218
								<li>
219
									<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...
220
										   type="checkbox" name="content[]"
221
										   value="cuisine"/> <?php esc_html_e( 'Cuisine', 'lsx-wetu-importer' ); ?></li>
222
								<li>
223
									<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...
224
										   type="checkbox" name="content[]"
225
										   value="climate"/> <?php esc_html_e( 'Climate', 'lsx-wetu-importer' ); ?></li>
226
								<li>
227
									<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...
228
										   type="checkbox" name="content[]"
229
										   value="transport"/> <?php esc_html_e( 'Transport', 'lsx-wetu-importer' ); ?></li>
230
								<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...
231
										   type="checkbox" name="content[]"
232
										   value="dress"/> <?php esc_html_e( 'Dress', 'lsx-wetu-importer' ); ?></li>
233
								<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...
234
										   type="checkbox" name="content[]"
235
										   value="health"/> <?php esc_html_e( 'Health', 'lsx-wetu-importer' ); ?></li>
236
								<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...
237
										   type="checkbox" name="content[]"
238
										   value="safety"/> <?php esc_html_e( 'Safety', 'lsx-wetu-importer' ); ?></li>
239
								<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...
240
										   type="checkbox" name="content[]"
241
										   value="visa"/> <?php esc_html_e( 'Visa', 'lsx-wetu-importer' ); ?></li>
242
								<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...
243
										   type="checkbox" name="content[]"
244
										   value="additional_info"/> <?php esc_html_e( 'General', 'lsx-wetu-importer' ); ?></li>
245
							</ul>
246
						</div>
247
248
						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
249
							<div style="width:30%;display:block;float:left;">
250
								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
251
								<?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...
252
							</div>
253
						<?php } ?>
254
255
						<br clear="both"/>
256
					</div>
257
258
259
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
260
					<p><input class="button button-primary" type="submit"
261
							  value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>"/></p>
262
					<table class="wp-list-table widefat fixed posts">
263
						<?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...
264
265
						<tbody>
266
267
						</tbody>
268
269
						<?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...
270
271
					</table>
272
273
					<p><input class="button button-primary" type="submit"
274
							  value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>"/></p>
275
				</form>
276
			</div>
277
278
			<div style="display:none;" class="completed-list-wrapper">
279
				<h3><?php esc_html_e( 'Completed' ); ?></h3>
280
				<ul>
281
				</ul>
282
			</div>
283
		</div>
284
		<?php
285
	}
286
287
	/**
288
	 * Grab all the current destination posts via the lsx_wetu_id field.
289
	 */
290 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...
291
		global $wpdb;
292
		$return = array();
293
294
		// @codingStandardsIgnoreStart
295
		$current_destination = $wpdb->get_results("
296
			SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified
297
			FROM {$wpdb->postmeta} key1
298
299
			INNER JOIN  {$wpdb->posts} key2
300
			ON key1.post_id = key2.ID
301
302
			WHERE key1.meta_key = 'lsx_wetu_id'
303
			AND key2.post_type = '{$post_type}'
304
305
			LIMIT 0,1000
306
		");
307
		// @codingStandardsIgnoreEnd
308
309
		if ( null !== $current_destination && ! empty( $current_destination ) ) {
310
			foreach ( $current_destination as $accom ) {
311
				$return[ $accom->meta_value ] = $accom;
312
			}
313
		}
314
315
		return $return;
316
	}
317
318
	/**
319
	 * Run through the accommodation grabbed from the DB.
320
	 */
321
	public function process_ajax_search() {
322
		$return = false;
323
		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
324
		if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) {
325
326
			$searched_items = false;
327 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...
328
				$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
329
			} else {
330
				$keyphrases = array( 0 );
331
			}
332
333
			if ( ! is_array( $keyphrases ) ) {
334
				$keyphrases = array( $keyphrases );
335
			}
336
			foreach ( $keyphrases as &$keyword ) {
337
				$keyword = ltrim( rtrim( $keyword ) );
338
			}
339
340
			$post_status = false;
341
342
			if ( in_array( 'publish', $keyphrases ) ) {
343
				$post_status = 'publish';
344
			}
345
			if ( in_array( 'pending', $keyphrases ) ) {
346
				$post_status = 'pending';
347
			}
348
			if ( in_array( 'draft', $keyphrases ) ) {
349
				$post_status = 'draft';
350
			}
351
			if ( in_array( 'import', $keyphrases ) ) {
352
				$post_status = 'import';
353
			}
354
355
			// If there is a post status use it.
356
			if ( false !== $post_status ) {
357
358
				$accommodation = array();
359
				$current_accommodation = $this->find_current_accommodation( 'destination' );
360 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...
361
					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
362
						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
363
					}
364
				}
365
366
				// Run through each accommodation and use it.
367 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...
368
					foreach ( $accommodation as $row_key => $row ) {
369
						if ( 'import' === $post_status ) {
370
371
							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
372
								$current_status = get_post_status( $row['post_id'] );
373
								if ( 'draft' === $current_status ) {
374
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
375
								}
376
							} else {
377
								continue;
378
							}
379
						} else {
380
							if ( 0 === $row['post_id'] ) {
381
								continue;
382
							} else {
383
								$current_status = get_post_status( $row['post_id'] );
384
385
								if ( $current_status !== $post_status ) {
386
									continue;
387
								}
388
							}
389
							$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
390
						}
391
					}
392
				}
393
			} else {
394
395
				$key_string_search = implode( '+', $keyphrases );
396
				$search_data       = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' );
397
398
				if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) {
399
					$search_data = json_decode( $search_data['body'], true );
400
					foreach ( $search_data as $sdata ) {
401
402
						if ( 'Destination' !== trim( $sdata['type'] ) ) {
403
							continue;
404
						}
405
406
						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
407 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...
408
							$sdata['post_id'] = 0;
409
						} else {
410
							$sdata['post_id'] = $temp_id;
411
						}
412
						$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|str..._id":"integer|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...
413
					}
414
				}
415
			}
416
417
			if ( false !== $searched_items ) {
418
				ksort( $searched_items );
419
				$return = implode( $searched_items );
420
			}
421
422
			print_r( $return );
423
		}
424
425
		die();
426
	}
427
428 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...
429
		$row_item = array(
430
			'id' => $cs_key,
431
			'type' => 'Destination',
432
			'name' => get_the_title( $ccs_id ),
433
			'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
434
			'post_id' => $ccs_id,
435
		);
436
		return $row_item;
437
	}
438
439
	/**
440
	 * Formats the row for output on the screen.
441
	 */
442 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...
443
		if ( false !== $row ) {
444
445
			$status = 'import';
446
			if ( 0 !== $row['post_id'] ) {
447
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
448
			}
449
450
			$row_html = '
451
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
452
				<th class="check-column" scope="row">
453
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
454
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
455
				</th>
456
				<td class="post-title page-title column-title">
457
					<strong>' . $row['name'] . '</strong> - ' . $status . '
458
				</td>
459
				<td class="date column-date">
460
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
461
				</td>
462
				<td class="ssid column-ssid">
463
					' . $row['id'] . '
464
				</td>
465
			</tr>';
466
			return $row_html;
467
		}
468
	}
469
470
	/**
471
	 * Connect to wetu
472
	 */
473
	public function process_ajax_import() {
474
		$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...
475
476
		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
477
		if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) {
478
479
			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
480
481
			if ( isset( $_POST['post_id'] ) ) {
482
				$post_id = sanitize_text_field( $_POST['post_id'] );
483
				$this->current_post = get_post( $post_id );
484
			} else {
485
				$post_id = 0;
486
			}
487
488 View Code Duplication
			if ( isset( $_POST['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...
489
				$team_members = sanitize_text_field( $_POST['team_members'] );
490
			} else {
491
				$team_members = false;
492
			}
493
494
			$safari_brands = false;
495
496
			delete_option( 'lsx_wetu_importer_destination_settings' );
497
498 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...
499
				$content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
500
				add_option( 'lsx_wetu_importer_destination_settings', $content );
501
			} else {
502
				$content = false;
503
			}
504
505
			$jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
506
507 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...
508
				$adata  = json_decode( $jdata['body'], true );
509
				$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
0 ignored issues
show
Security Bug introduced by
It seems like $content defined by false on line 502 can also be of type false; however, LSX_WETU_Importer_Destination::import_row() does only seem to accept array, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
510
				$this->remove_from_queue( $return );
511
				$this->format_completed_row( $return );
512
			} else {
513
				$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) );
514
			}
515
		}
516
	}
517
518
	/**
519
	 * Saves the queue to the option.
520
	 */
521 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...
522
		if ( ! empty( $this->queued_imports ) ) {
523
			$key = array_search( $id, $this->queued_imports );
524
			if ( false !== $key ) {
525
				unset( $this->queued_imports[ $key ] );
526
527
				delete_option( 'lsx_wetu_importer_que' );
528
				update_option( 'lsx_wetu_importer_que', $this->queued_imports );
529
			}
530
		}
531
	}
532
533
	/**
534
	 * Connect to wetu
535
	 */
536
	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...
537
		if ( 'Destination' === trim( $data[0]['type'] ) ) {
538
			$post_name = '';
539
			$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...
540
			$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...
541
542
			$post = array(
543
				'post_type' => 'destination',
544
			);
545
546
			if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) {
547
				$parent = $this->check_for_parent( $data );
548
				if ( false !== $parent ) {
549
					$post['post_parent'] = $parent;
550
				}
551
			}
552
553
			// Set the post_content.
554
			if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
555
				if ( isset( $data[0]['content']['general_description'] ) ) {
556
557
					if ( in_array( 'strip_tags', $importable_content ) ) {
558
						$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
559
					} else {
560
						$post['post_content'] = $data[0]['content']['general_description'];
561
					}
562
				}
563
			}
564
565 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...
566
				$post['ID'] = $id;
567
568
				if ( isset( $data[0]['name'] ) ) {
569
					$post['post_title'] = $data[0]['name'];
570
					$post['post_status'] = 'publish';
571
					$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
572
				}
573
574
				$id = wp_update_post( $post );
575
				$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
576
				update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
577
			} else {
578
				// Set the name.
579
				if ( isset( $data[0]['name'] ) ) {
580
					$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
581
				}
582
583
				$post['post_name'] = $post_name;
584
				$post['post_title'] = $data[0]['name'];
585
				$post['post_status'] = 'publish';
586
				$id = wp_insert_post( $post );
587
588
				// Save the WETU ID and the Last date it was modified.
589
				if ( false !== $id ) {
590
					add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
591
					add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
592
				}
593
			}
594
595
			$this->find_attachments( $id );
596
597
			// Set the team member if it is there.
598 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...
599
				$this->set_team_member( $id, $team_members );
600
			}
601
602
			$this->set_map_data( $data, $id, 9 );
603
604
			// Set the Room Data.
605
			if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
606
				$this->set_video_data( $data, $id );
607
			}
608
609
			// Set the Electricity.
610
			if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
611
				$this->set_travel_info( $data, $id, 'electricity', $importable_content );
612
			}
613
			// Set the cuisine.
614
			if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
615
				$this->set_travel_info( $data, $id, 'cuisine', $importable_content );
616
			}
617
			// Set the banking.
618
			if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
619
				$this->set_travel_info( $data, $id, 'banking', $importable_content );
620
			}
621
			// Set the transport.
622
			if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
623
				$this->set_travel_info( $data, $id, 'transport', $importable_content );
624
			}
625
			// Set the dress.
626
			if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
627
				$this->set_travel_info( $data, $id, 'dress', $importable_content );
628
			}
629
			// Set the climate.
630
			if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
631
				$this->set_travel_info( $data, $id, 'climate', $importable_content );
632
			}
633
			// Set the Health.
634
			if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
635
				$this->set_travel_info( $data, $id, 'health', $importable_content );
636
			}
637
			// Set the Safety.
638
			if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
639
				$this->set_travel_info( $data, $id, 'safety', $importable_content );
640
			}
641
			// Set the Visa.
642 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...
643
				$this->set_travel_info( $data, $id, 'visa', $importable_content );
644
			}
645
			// Set the General.
646 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...
647
				$this->set_travel_info( $data, $id, 'additional_info', $importable_content );
648
			}
649
650
			// Setup some default for use in the import.
651
			if ( false !== $importable_content && (in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content )) ) {
652
				$this->find_attachments( $id );
653
654
				// Set the featured image.
655
				if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
656
					$this->set_featured_image( $data, $id );
657
				}
658
				if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
659
					$this->set_banner_image( $data, $id, $importable_content );
660
				}
661
				// Import the main gallery.
662
				if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
663
					$this->create_main_gallery( $data, $id );
664
				}
665
			}
666
667
			// Set the continent.
668
			if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
669
				$this->set_continent( $data, $id );
670
			}
671
		}
672
673
		return $id;
674
	}
675
676
	/**
677
	 * Set the team memberon each item.
678
	 */
679 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...
680
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
681
682
		foreach ( $team_members as $team ) {
683
			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
684
		}
685
	}
686
687
	/**
688
	 * Saves the room data
689
	 */
690
	public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) {
691
		if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
692
			$content = $data[0]['travel_information'][ $meta_key ];
693
694
			if ( in_array( 'strip_tags', $importable ) ) {
695
				$content = strip_tags( $content );
696
			}
697
698
			$this->save_custom_field( $content, $meta_key, $id );
699
		}
700
	}
701
702
	/**
703
	 * Set the Travel Style
704
	 */
705
	public function set_continent( $data, $id ) {
706
707
		if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
708
			//get the continent code.
709
			$continent_code = to_continent_label( to_continent_code( to_country_data( $data[0]['position']['country'], false ) ) );
710
711
			if ( '' !== $continent_code ) {
712
				$term = term_exists( trim( $continent_code ), 'continent' );
713
				if ( ! $term ) {
714
					$term = wp_insert_term( trim( $continent_code ), 'continent' );
715
716
					if ( is_wp_error( $term ) ) {
717
						echo wp_kses_post( $term->get_error_message() );
718
					}
719
				} else {
720
					wp_set_object_terms( $id, sanitize_title( $continent_code ), 'continent', true );
721
				}
722
			}
723
		}
724
	}
725
726
	/**
727
	 * Save the list of Accommodation into an option
728
	 */
729
	public function update_options() {
730
		$data = wp_remote_get( $this->url . '/List?' . $this->url_qs );
731
		if ( ! empty( $data ) && isset( $data['response'] ) && isset( $data['response']['code'] ) && 200 === $data['response']['code'] ) {
732
			$accommodation = json_decode( $data['body'], true );
733
			set_transient( 'lsx_ti_accommodation', $accommodation, 60 * 60 * 2 );
734
			return true;
735
		}
736
	}
737
738
	/**
739
	 * search_form
740
	 */
741
	public function update_options_form() {
742
		echo '<div style="display:none;" class="wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . '</h3>';
743
744
		$accommodation = get_transient( 'lsx_ti_accommodation' );
745
746
		if ( '' === $accommodation || false === $accommodation || isset( $_GET['refresh_accommodation'] ) ) {
747
			$this->update_options();
748
		}
749
750
		echo '</div>';
751
	}
752
753
	/**
754
	 * Save the list of Accommodation into an option
755
	 */
756
	public function check_for_parent( $data = array() ) {
757
		global $wpdb;
758
759
		if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) {
760
			$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'] ) ) );
761
			if ( ! empty( $result ) && '' !== $result && false !== $result ) {
762
				return $result;
763
			}
764
		}
765
		return false;
766
	}
767
}
768