Passed
Push — master ( f222a0...381f60 )
by Warwick
02:11
created

WETU_Importer_Destination::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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 ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
		//	$this->url    = 'https://wetu.com/API/Pins/';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
		//	$this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
		//} elseif ( false !== $this->api_key ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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' );
339
340
			if ( false === $accommodation ) {
341
				$this->update_options();
0 ignored issues
show
Bug introduced by
The method update_options() does not exist on WETU_Importer_Destination. Did you maybe mean update_options_form()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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
				if ( ! empty( $accommodation ) ) {
378
379
					$current_accommodation = $this->find_current_accommodation( 'destination' );
380
381
					foreach ( $accommodation as $row_key => $row ) {
382
383
						if ( 'Destination' === trim( $row['type'] ) ) {
384
385
							//If this is a current tour, add its ID to the row.
386
							$row['post_id'] = 0;
387
388 View Code Duplication
							if ( false !== $current_accommodation && array_key_exists( $row['id'], $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...
389
								$row['post_id'] = $current_accommodation[ $row['id'] ]->post_id;
390
							}
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 );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, 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...
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 );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, 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
							} 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 );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, 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...
426
									}
427
								}
428
							}
429
						}// end of the destination if
430
					}
431
				}
432
433
				if ( false !== $searched_items ) {
434
					ksort( $searched_items );
435
					$return = implode( $searched_items );
436
				}
437
			}
438
439
			print_r( $return );
440
		}
441
442
		die();
443
	}
444
445
	/**
446
	 * Formats the row for output on the screen.
447
	 */
448 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...
449
		if ( false !== $row ) {
450
451
			$status = 'import';
452
			if ( 0 !== $row['post_id'] ) {
453
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
454
			}
455
456
			$row_html = '
457
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
458
				<th class="check-column" scope="row">
459
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
460
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
461
				</th>
462
				<td class="post-title page-title column-title">
463
					<strong>' . $row['name'] . '</strong> - ' . $status . '
464
				</td>
465
				<td class="date column-date">
466
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
467
				</td>
468
				<td class="ssid column-ssid">
469
					' . $row['id'] . '
470
				</td>
471
			</tr>';
472
			return $row_html;
473
		}
474
	}
475
476
	/**
477
	 * Connect to wetu
478
	 */
479
	public function process_ajax_import() {
480
		$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...
481
482
		// @codingStandardsIgnoreLine
483
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' && isset( $_POST['wetu_id'] ) ) {
484
			// @codingStandardsIgnoreLine
485
			$wetu_id = $_POST['wetu_id'];
486
487
			// @codingStandardsIgnoreLine
488
			if ( isset( $_POST['post_id'] ) ) {
489
				// @codingStandardsIgnoreLine
490
				$post_id = $_POST['post_id'];
491
				$this->current_post = get_post( $post_id );
492
			} else {
493
				$post_id = 0;
494
			}
495
496
			// @codingStandardsIgnoreLine
497
			if ( isset( $_POST['team_members'] ) ) {
498
				// @codingStandardsIgnoreLine
499
				$team_members = $_POST['team_members'];
500
			} else {
501
				$team_members = false;
502
			}
503
504
			$safari_brands = false;
505
506
			delete_option( 'wetu_importer_destination_settings' );
507
508
			// @codingStandardsIgnoreLine
509 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...
510
				// @codingStandardsIgnoreLine
511
				$content = $_POST['content'];
512
				add_option( 'wetu_importer_destination_settings', $content );
513
			} else {
514
				$content = false;
515
			}
516
517
			$jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
518
519 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...
520
				$adata = json_decode( $jdata, true );
521
522
				if ( ! empty( $adata ) && ! isset( $adata['error'] ) ) {
523
					$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
524
					$this->remove_from_queue( $return );
525
					$this->format_completed_row( $return );
526
				} else {
527
					if ( isset( $adata['error'] ) ) {
528
						$this->format_error( $adata['error'] );
529
					} else {
530
						$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.','wetu-importer' ) );
531
					}
532
				}
533
			}
534
		}
535
	}
536
537
	/**
538
	 * Saves the queue to the option.
539
	 */
540 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...
541
		if ( ! empty( $this->queued_imports ) ) {
542
			// @codingStandardsIgnoreLine
543
			if ( ( $key = array_search( $id, $this->queued_imports ) ) !== false ) {
544
				unset( $this->queued_imports[ $key ] );
545
546
				delete_option( 'wetu_importer_que' );
547
				update_option( 'wetu_importer_que',$this->queued_imports );
548
			}
549
		}
550
	}
551
552
	/**
553
	 * Connect to wetu
554
	 */
555
	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...
556
		if ( 'Destination' === trim( $data[0]['type'] ) ) {
557
			$post_name = '';
558
			$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...
559
			$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...
560
561
			$post = array(
562
				'post_type' => 'destination',
563
			);
564
565
			if ( false !== $importable_content && in_array( 'country', $importable_content ) ) {
566
				$parent = $this->check_for_parent();
567
				if( false !== $parent ) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
568
					//$post['post_parent'] = $parent;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
569
				}
570
			}
571
572
			//Set the post_content
573
			if ( false !== $importable_content && in_array( 'description', $importable_content ) ) {
574
				if ( isset( $data[0]['content']['general_description'] ) ) {
575
576
					if ( false !== $importable_content && in_array( 'strip_tags', $importable_content ) ) {
577
						$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
578
					} else {
579
						$post['post_content'] = $data[0]['content']['general_description'];
580
					}
581
				}
582
			}
583
584 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...
585
				$post['ID'] = $id;
586
587
				if ( isset( $data[0]['name'] ) ) {
588
					$post['post_title'] = $data[0]['name'];
589
					$post['post_status'] = 'publish';
590
					$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
591
				}
592
593
				$id = wp_update_post( $post );
594
				$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
595
				update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
596
			} else {
597
				//Set the name
598
				if ( isset( $data[0]['name'] ) ) {
599
					$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
600
				}
601
602
				$post['post_name'] = $post_name;
603
				$post['post_title'] = $data[0]['name'];
604
				$post['post_status'] = 'publish';
605
				$id = wp_insert_post( $post );
606
607
				//Save the WETU ID and the Last date it was modified.
608
				if ( false !== $id ) {
609
					add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
610
					add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
611
				}
612
			}
613
614
			$this->find_attachments( $id );
615
616
			//Set the team member if it is there
617 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...
618
				$this->set_team_member( $id, $team_members );
619
			}
620
621
			if ( class_exists( 'LSX_TO_Maps' ) ) {
622
				$this->set_map_data( $data, $id, 9 );
623
			}
624
625
			//Set the Room Data
626
			if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
627
				$this->set_video_data( $data, $id );
628
			}
629
630
			//Set the Electricity
631
			if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
632
				$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...
633
			}
634
			//Set the cuisine
635
			if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
636
				$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...
637
			}
638
			//Set the banking
639
			if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
640
				$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...
641
			}
642
			//Set the transport
643
			if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
644
				$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...
645
			}
646
			//Set the dress
647
			if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
648
				$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...
649
			}
650
			//Set the climate
651
			if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
652
				$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...
653
			}
654
			//Set the Health
655
			if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
656
				$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...
657
			}
658
			//Set the Safety
659
			if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
660
				$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...
661
			}
662
			//Set the Visa
663 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...
664
				$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...
665
			}
666
			//Set the General
667 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...
668
				$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...
669
			}
670
671
			//Setup some default for use in the import
672
			if ( false !== $importable_content && (in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content )) ) {
673
				$this->find_attachments( $id );
674
675
				//Set the featured image
676
				if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
677
					$this->set_featured_image( $data, $id );
678
				}
679
				if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
680
					$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...
681
				}
682
				//Import the main gallery
683
				if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
684
					$this->create_main_gallery( $data, $id );
685
				}
686
			}
687
688
			//Set the continent
689
			if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
690
				$this->set_continent( $data, $id );
691
			}
692
		}
693
694
		return $id;
695
	}
696
697
	/**
698
	 * Set the team memberon each item.
699
	 */
700 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...
701
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
702
703
		foreach ( $team_members as $team ) {
704
			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
705
		}
706
	}
707
708
	/**
709
	 * Saves the room data
710
	 */
711
	public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) {
712
		if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
713
			$content = $data[0]['travel_information'][ $meta_key ];
714
715
			if ( in_array( 'strip_tags', $importable ) ) {
716
				$content = strip_tags( $content );
717
			}
718
719
			$this->save_custom_field( $content, $meta_key, $id );
720
		}
721
	}
722
723
	/**
724
	 * Set the Travel Style
725
	 */
726
	public function set_continent( $data, $id ) {
727
728
		if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
729
			//get the continent code.
730
			$continent_code = to_continent_label( to_continent_code( to_country_data( $data[0]['position']['country'], false ) ) );
731
732
			if ( '' !== $continent_code ) {
733
				// @codingStandardsIgnoreLine
734
				if ( ! $term = term_exists( trim( $continent_code ), 'continent' ) ) {
735
					$term = wp_insert_term( trim( $continent_code ), 'continent' );
736
737
					if ( is_wp_error( $term ) ) {
738
						// @codingStandardsIgnoreLine
739
						echo $term->get_error_message();
740
					}
741
				} else {
742
					wp_set_object_terms( $id, sanitize_title( $continent_code ), 'continent', true );
743
				}
744
			}
745
		}
746
	}
747
748
	/**
749
	 * search_form
750
	 */
751 View Code Duplication
	public function update_options_form() {
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...
752
		echo '<div style="display:none;" class="wetu-status"><h3>' . esc_html__( 'Wetu Status', 'wetu-importer' ) . '</h3>';
753
754
		$accommodation = get_transient( 'lsx_ti_accommodation' );
755
756
		if ( '' === $accommodation || false === $accommodation || isset( $_GET['refresh_accommodation'] ) ) {
757
			$this->update_options();
0 ignored issues
show
Bug introduced by
The method update_options() does not exist on WETU_Importer_Destination. Did you maybe mean update_options_form()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
758
		}
759
760
		echo '</div>';
761
	}
762
763
	/**
764
	 * Save the list of Accommodation into an option
765
	 */
766
	public function check_for_parent( $wid = 0 ) {
767
		global $wpdb;
768
769
		$query = "
770
		SELECT post_id
771
		FROM {$wpdb->postmeta}
772
		WHERE meta_key = 'lsx_wetu_id'
773
		AND meta_valule = {$wid}";
774
775
		print_r( $query );
776
777
		$result = $wpdb->get_var( $query );
778
779
		if( ! empty( $result ) && '' !== $result && false !== $result ) {
780
			return $result;
781
		} else {
782
			return false;
783
		}
784
	}
785
}
786