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

WETU_Importer_Accommodation::display_page()   C

Complexity

Conditions 11
Paths 128

Size

Total Lines 134

Duplication

Lines 12
Ratio 8.96 %

Importance

Changes 0
Metric Value
cc 11
nc 128
nop 0
dl 12
loc 134
rs 5.6666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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   WETU_Importer_Accommodation
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link
7
 * @copyright 2016 LightSpeed
8
 **/
9
10
class WETU_Importer_Accommodation 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 = 'accommodation';
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 $accommodation_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
74
		// ** This request only works with API KEY **
75
		//if ( false !== $this->api_username && false !== $this->api_password ) {
76
		//	$this->url    = 'https://wetu.com/API/Pins/';
77
		//	$this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
78
		//} elseif ( false !== $this->api_key ) {
79
			$this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
80
			$this->url_qs = 'all=include';
81
		//}
82
83
		$temp_options = get_option( '_lsx-to_settings', false );
84
85
		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
86
			$this->options = $temp_options[ $this->plugin_slug ];
87
		}
88
89
		$accommodation_options = get_option( 'wetu_importer_accommodation_settings',false );
90
91
		if ( false !== $accommodation_options ) {
92
			$this->accommodation_options = $accommodation_options;
93
		}
94
	}
95
96
	/**
97
	 * Display the importer administration screen
98
	 */
99
	public function display_page() {
100
		?>
101
		<div class="wrap">
102
			<?php $this->navigation( 'accommodation' ); ?>
103
104
			<?php $this->update_options_form(); ?>
105
106
			<?php $this->search_form(); ?>
107
108
			<form method="get" action="" id="posts-filter">
109
				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
110
111
				<p><input class="button button-primary add" type="button" value="<?php esc_attr_e( 'Add to List', 'wetu-importer' ); ?>" />
112
					<input class="button button-primary clear" type="button" value="<?php esc_attr_e( 'Clear', 'wetu-importer' ); ?>" />
113
				</p>
114
115
				<table class="wp-list-table widefat fixed posts">
116
					<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Accommodation::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...
117
118
					<tbody id="the-list">
119
						<tr class="post-0 type-tour status-none" id="post-0">
120
							<th class="check-column" scope="row">
121
								<label for="cb-select-0" 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_Accommodation::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" value="<?php esc_attr_e( 'Add to List', 'wetu-importer' ); ?>" />
140
					<input class="button button-primary clear" type="button" value="<?php esc_attr_e( 'Clear', 'wetu-importer' ); ?>" />
141
				</p>
142
			</form>
143
144
			<div style="display:none;" class="import-list-wrapper">
145
				<br />
146
				<form method="get" action="" id="import-list">
147
148
					<div class="row">
149
						<div class="settings-all" style="width:30%;display:block;float:left;">
150
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
151
							<ul>
152
								<li><input class="content select-all" <?php $this->checked( $this->accommodation_options, 'all' ); ?> type="checkbox" name="content[]" value="all" /> <?php esc_html_e( 'Select All', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
153
								<?php if ( ! isset( $this->options['disable_accommodation_descriptions'] ) ) { ?>
154
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'description' ); ?>" type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
155
								<?php } ?>
156
								<?php if ( ! isset( $this->options['disable_accommodation_excerpts'] ) ) { ?>
157
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'excerpt' ); ?>" type="checkbox" name="content[]" value="excerpt" /> <?php esc_html_e( 'Excerpt', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
158
								<?php } ?>
159
160 View Code Duplication
								<?php if ( ! isset( $this->accommodation_settings['disable_single'] ) ) { ?>
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...
161
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'gallery' ); ?>" type="checkbox" name="content[]" value="gallery" /> <?php esc_html_e( 'Main Gallery', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
162
								<?php } ?>
163
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'category' ); ?>" type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
164 View Code Duplication
								<?php if ( class_exists( 'LSX_TO_Maps' ) && ! isset( $this->accommodation_settings['disable_single'] ) ) { ?>
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...
165
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'location' ); ?>" type="checkbox" name="content[]" value="location" /> <?php esc_html_e( 'Location', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_options is of type string, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
166
								<?php } ?>
167
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'destination' ); ?>" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Connect Destinations', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
168
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'rating' ); ?>" type="checkbox" name="content[]" value="rating" /> <?php esc_html_e( 'Rating', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
169
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'rooms' ); ?>" type="checkbox" name="content[]" value="rooms" /> <?php esc_html_e( 'Rooms', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
170
171
								<?php if ( ! isset( $this->accommodation_settings['disable_single'] ) ) { ?>
172
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'checkin' ); ?>" type="checkbox" name="content[]" value="checkin" /> <?php esc_html_e( 'Check In / Check Out', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
173
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'facilities' ); ?>" type="checkbox" name="content[]" value="facilities" /> <?php esc_html_e( 'Facilities', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
174
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'friendly' ); ?>" type="checkbox" name="content[]" value="friendly" /> <?php esc_html_e( 'Friendly', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_options is of type string, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
								<?php } ?>
176
177
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'special_interests' ); ?>" type="checkbox" name="content[]" value="special_interests" /> <?php esc_html_e( 'Special Interests', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
178
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'spoken_languages' ); ?>" type="checkbox" name="content[]" value="spoken_languages" /> <?php esc_html_e( 'Spoken Languages', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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
180 View Code Duplication
								<?php if ( class_exists( 'LSX_TO_Videos' ) && ! isset( $this->accommodation_settings['disable_single'] ) ) { ?>
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...
181
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'videos' ); ?>" type="checkbox" name="content[]" value="videos" /> <?php esc_html_e( 'Videos', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
182
								<?php } ?>
183
							</ul>
184
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
185
							<ul>
186
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'featured_image' ); ?>" type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e( 'Set Featured Image', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
187 View Code Duplication
								<?php if ( class_exists( 'LSX_Banners' ) && ! isset( $this->accommodation_settings['disable_single'] ) ) { ?>
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...
188
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'banner_image' ); ?>" type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e( 'Set Banner Image', 'wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
189
								<?php } ?>
190
							</ul>
191
						</div>
192
						<div style="width:30%;display:block;float:left;">
193
							<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
194
							<?php $this->team_member_checkboxes( $this->accommodation_options ); ?>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
195
						</div>
196
197
						<div style="width:30%;display:block;float:left;">
198
							<h3><?php esc_html_e( 'Assign a Safari Brand' ); ?></h3>
199
							<?php
200
								// @codingStandardsIgnoreLine
201
								echo $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options );
0 ignored issues
show
Documentation introduced by
'accommodation-brand' 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...
Documentation introduced by
$this->accommodation_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...
202
							?>
203
						</div>
204
205
						<br clear="both" />
206
					</div>
207
208
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
209
					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'wetu-importer' ); ?>" /></p>
210
					<table class="wp-list-table widefat fixed posts">
211
						<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Accommodation::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...
212
213
						<tbody>
214
215
						</tbody>
216
217
						<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Accommodation::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...
218
219
					</table>
220
221
					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'wetu-importer' ); ?>" /></p>
222
				</form>
223
			</div>
224
225
			<div style="display:none;" class="completed-list-wrapper">
226
				<h3><?php esc_html_e( 'Completed' ); ?> - <small><?php esc_html_e( 'Import your', 'wetu-importer' ); ?> <a href="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>?page=<?php echo esc_attr( $this->plugin_slug ); ?>&tab=destination"><?php esc_html_e( 'destinations' ); ?></a> <?php esc_html_e( 'next', 'wetu-importer' ); ?></small></h3>
227
				<ul>
228
				</ul>
229
			</div>
230
		</div>
231
		<?php
232
	}
233
234
	/**
235
	 * search_form
236
	 */
237
	public function update_options_form() {
238
		echo '<div style="display:none;" class="wetu-status"><h3>' . esc_html__( 'Wetu Status', 'wetu-importer' ) . '</h3>';
239
240
		$accommodation = get_transient( 'lsx_ti_accommodation' );
0 ignored issues
show
Unused Code introduced by
$accommodation is not used, you could remove the assignment.

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

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

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

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

Loading history...
241
242
		//if ( '' === $accommodation || false === $accommodation || isset( $_GET['refresh_accommodation'] ) ) {
243
			//$this->update_options();
244
		//}
245
246
		echo '</div>';
247
	}
248
249
	/**
250
	 * Save the list of Accommodation into an option
251
	 */
252 View Code Duplication
	public function update_options() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
253
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
254
255
		$accommodation = json_decode( $data, true );
256
257
		if ( isset( $accommodation['error'] ) ) {
258
			return $accommodation['error'];
259
		} elseif ( isset( $accommodation ) && ! empty( $accommodation ) ) {
260
			set_transient( 'lsx_ti_accommodation',$accommodation,60 * 60 * 2 );
261
			return true;
262
		}
263
	}
264
265
	/**
266
	 * Run through the accommodation grabbed from the DB.
267
	 */
268
	public function process_ajax_search() {
269
		$return = false;
270
271
		// @codingStandardsIgnoreLine
272
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_tour_importer' && isset( $_POST['type'] ) && $_POST['type'] === 'accommodation' ) {
273
			//$accommodation = get_transient( 'lsx_ti_accommodation' );
274
275
			//if ( false === $accommodation ) {
276
				//$this->update_options();
277
			//}
278
279
			//if ( false !== $accommodation ) {
280
				$searched_items = false;
281
282
				// @codingStandardsIgnoreLine
283 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...
284
					// @codingStandardsIgnoreLine
285
					$keyphrases = $_POST['keyword'];
286
				} else {
287
					$keyphrases = array( 0 );
288
				}
289
290
				if ( ! is_array( $keyphrases ) ) {
291
					$keyphrases = array( $keyphrases );
292
				}
293
				foreach ( $keyphrases as &$keyword ) {
294
					$keyword = ltrim( rtrim( $keyword ) );
295
				}
296
297
				$post_status = false;
298
299
				if ( in_array( 'publish',$keyphrases ) ) {
300
					$post_status = 'publish';
301
				}
302
				if ( in_array( 'pending',$keyphrases ) ) {
303
					$post_status = 'pending';
304
				}
305
				if ( in_array( 'draft',$keyphrases ) ) {
306
					$post_status = 'draft';
307
				}
308
				if ( in_array( 'import',$keyphrases ) ) {
309
					$post_status = 'import';
310
				}
311
312
				$accommodation = array();
313
314
				$current_accommodation = $this->find_current_accommodation();
315
316 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...
317
					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
318
						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
319
					}
320
				}
321
322
				if ( ! empty( $accommodation ) ) {
323
324
					foreach ( $accommodation as $row_key => $row ) {
325
326
						if ( 'Destination' === trim( $row['type'] ) ||
327
							 'Activity' === trim( $row['type'] ) ||
328
							 'Restaurant' === trim( $row['type'] ) ||
329
							 'None' === trim( $row['type'] ) ||
330
							 'Site / Attraction' === trim( $row['type'] ) ||
331
							 '' === trim( $row['type'] )
332
						) {
333
							continue;
334
						}
335
336
						//If we are searching for
337
						if ( false !== $post_status ) {
338 View Code Duplication
							if ( 'import' === $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...
339
340
								if ( is_array( $this->queued_imports ) && in_array( $row['post_id'],$this->queued_imports ) ) {
341
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
342
								} else {
343
									continue;
344
								}
345
							} else {
346
								if ( 0 === $row['post_id'] ) {
347
									continue;
348
								} else {
349
									$current_status = get_post_status( $row['post_id'] );
350
351
									if ( $current_status !== $post_status ) {
352
										continue;
353
									}
354
								}
355
356
								$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
357
							}
358 View Code Duplication
						} else {
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...
359
							//Search through each keyword.
360
							foreach ( $keyphrases as $keyphrase ) {
361
								//Make sure the keyphrase is turned into an array
362
								$keywords = explode( ' ',$keyphrase );
363
364
								if ( ! is_array( $keywords ) ) {
365
									$keywords = array( $keywords );
366
								}
367
368
								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
369
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
370
								}
371
							}
372
						}
373
					}
374
				}
375
376
				if ( false !== $searched_items ) {
377
					ksort( $searched_items );
378
					$return = implode( $searched_items );
379
				}
380
			//}
381
382
			print_r( $return );
383
		}
384
385
		die();
386
	}
387
388 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...
389
		return 	$row_item = array(
0 ignored issues
show
Unused Code introduced by
$row_item is not used, you could remove the assignment.

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

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

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

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

Loading history...
390
			'id' => $cs_key,
391
			'type' => 'Accommodation',
392
			'name' => get_the_title( $ccs_id ),
393
			'last_modified' => date('Y-m-d', strtotime( 'now' ) ),
394
			'post_id' => $ccs_id,
395
		);
396
	}
397
398
	/**
399
	 * Formats the row for output on the screen.
400
	 */
401 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...
402
		if ( false !== $row ) {
403
404
			$status = 'import';
405
			if ( 0 !== $row['post_id'] ) {
406
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
407
			}
408
409
			$row_html = '
410
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
411
				<th class="check-column" scope="row">
412
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
413
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
414
				</th>
415
				<td class="post-title page-title column-title">
416
					<strong>' . $row['name'] . '</strong> - ' . $status . '
417
				</td>
418
				<td class="date column-date">
419
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
420
				</td>
421
				<td class="ssid column-ssid">
422
					' . $row['id'] . '
423
				</td>
424
			</tr>';
425
			return $row_html;
426
		}
427
	}
428
429
	/**
430
	 * Saves the queue to the option.
431
	 */
432 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...
433
		if ( ! empty( $this->queued_imports ) ) {
434
			// @codingStandardsIgnoreLine
435
			if ( ( $key = array_search( $id, $this->queued_imports ) ) !== false ) {
436
				unset( $this->queued_imports[ $key ] );
437
438
				delete_option( 'wetu_importer_que' );
439
				update_option( 'wetu_importer_que',$this->queued_imports );
440
			}
441
		}
442
	}
443
444
	/**
445
	 * Connect to wetu
446
	 */
447
	public function process_ajax_import() {
448
		$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...
449
450
		// @codingStandardsIgnoreLine
451
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'accommodation' && isset( $_POST['wetu_id'] ) ) {
452
			// @codingStandardsIgnoreLine
453
			$wetu_id = $_POST['wetu_id'];
454
455
			// @codingStandardsIgnoreLine
456
			if ( isset( $_POST['post_id'] ) ) {
457
				// @codingStandardsIgnoreLine
458
				$post_id = $_POST['post_id'];
459
			} else {
460
				$post_id = 0;
461
			}
462
463
			// @codingStandardsIgnoreLine
464
			if ( isset( $_POST['team_members'] ) ) {
465
				// @codingStandardsIgnoreLine
466
				$team_members = $_POST['team_members'];
467
			} else {
468
				$team_members = false;
469
			}
470
471
			// @codingStandardsIgnoreLine
472
			if ( isset( $_POST['safari_brands'] ) ) {
473
				// @codingStandardsIgnoreLine
474
				$safari_brands = $_POST['safari_brands'];
475
			} else {
476
				$safari_brands = false;
477
			}
478
479
			delete_option( 'wetu_importer_accommodation_settings' );
480
481
			// @codingStandardsIgnoreLine
482 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...
483
				// @codingStandardsIgnoreLine
484
				$content = $_POST['content'];
485
				add_option( 'wetu_importer_accommodation_settings',$content );
486
			} else {
487
				$content = false;
488
			}
489
490
			$jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
491
492 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...
493
				$adata = json_decode( $jdata,true );
494
				if ( ! empty( $adata ) && ! isset( $adata['error'] ) ) {
495
					$return = $this->import_row( $adata,$wetu_id,$post_id,$team_members,$content,$safari_brands );
496
					$this->format_completed_row( $return );
497
					$this->remove_from_queue( $return );
498
					$this->cleanup_posts();
499
				} else {
500
					if ( isset( $adata['error'] ) ) {
501
						$this->format_error( $adata['error'] );
502
					} else {
503
						$this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'wetu-importer' ) );
504
					}
505
				}
506
			}
507
		}
508
	}
509
510
	/**
511
	 * Connect to wetu
512
	 */
513
	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = false, $safari_brands = false ) {
514
		$post_name = '';
515
		$data_post_content = '';
516
		$data_post_excerpt = '';
517
518
		$post = array(
519
		  'post_type' => 'accommodation',
520
		);
521
522
		$content_used_general_description = false;
523
524
		//Set the post_content
525
		if ( false !== $importable_content && in_array( 'description',$importable_content ) ) {
526
			if ( isset( $data[0]['content']['extended_description'] ) ) {
527
				$data_post_content = $data[0]['content']['extended_description'];
528 View Code Duplication
			} elseif ( isset( $data[0]['content']['general_description'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
529
				$data_post_content = $data[0]['content']['general_description'];
530
				$content_used_general_description = true;
531
			} elseif ( isset( $data[0]['content']['teaser_description'] ) ) {
532
				$data_post_content = $data[0]['content']['teaser_description'];
533
			}
534
535
			$post['post_content'] = wp_strip_all_tags( $data_post_content );
536
		}
537
538
		//set the post_excerpt
539
		if ( false !== $importable_content && in_array( 'excerpt',$importable_content ) ) {
540
			if ( isset( $data[0]['content']['teaser_description'] ) ) {
541
				$data_post_excerpt = $data[0]['content']['teaser_description'];
542 View Code Duplication
			} elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) {
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...
543
				$data_post_excerpt = $data[0]['content']['general_description'];
544
			}
545
546
			$post['post_excerpt'] = $data_post_excerpt;
547
		}
548
549 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...
550
			$post['ID'] = $id;
551
552
			if ( isset( $data[0]['name'] ) ) {
553
				$post['post_title'] = $data[0]['name'];
554
				$post['post_status'] = 'publish';
555
				$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ),$id, 'draft', 'accommodation', 0 );
556
			}
557
558
			$id = wp_update_post( $post );
559
			$prev_date = get_post_meta( $id,'lsx_wetu_modified_date', true );
560
			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
561
		} else {
562
			//Set the name
563
			if ( isset( $data[0]['name'] ) ) {
564
				$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ),$id, 'draft', 'accommodation', 0 );
565
			}
566
567
			$post['post_name'] = $post_name;
568
			$post['post_title'] = $data[0]['name'];
569
			$post['post_status'] = 'publish';
570
			$id = wp_insert_post( $post );
571
572
			//Save the WETU ID and the Last date it was modified.
573
			if ( false !== $id ) {
574
				add_post_meta( $id,'lsx_wetu_id',$wetu_id );
575
				add_post_meta( $id,'lsx_wetu_modified_date',strtotime( $data[0]['last_modified'] ) );
576
			}
577
		}
578
579
		//Setup some default for use in the import
580
		if ( false !== $importable_content && (in_array( 'gallery',$importable_content ) || in_array( 'banner_image',$importable_content ) || in_array( 'featured_image',$importable_content )) ) {
581
			$this->find_attachments( $id );
582
		}
583
584
		//Set the team member if it is there
585 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...
586
			$this->set_team_member( $id,$team_members );
587
		}
588
589
		//Set the safari brand
590
		if ( false !== $safari_brands && '' !== $safari_brands ) {
591
			$this->set_safari_brands( $id,$safari_brands );
592
		}
593
594
		if ( class_exists( 'LSX_TO_Maps' ) ) {
595
			$this->set_map_data( $data,$id,9 );
596
		}
597
598
		if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination',$importable_content ) ) {
599
			$this->connect_destinations( $data,$id );
600
		}
601
602
		if ( false !== $importable_content && in_array( 'category',$importable_content ) ) {
603
			$this->set_taxonomy_style( $data,$id );
604
		}
605
606
		//Set the Room Data
607
		if ( false !== $importable_content && in_array( 'rooms',$importable_content ) ) {
608
			$this->set_room_data( $data,$id );
609
		}
610
611
		//Set the rating
612
		if ( false !== $importable_content && in_array( 'rating',$importable_content ) ) {
613
			$this->set_rating( $data,$id );
614
		}
615
616
		//Set the checkin checkout data
617
		if ( false !== $importable_content && in_array( 'checkin',$importable_content ) ) {
618
			$this->set_checkin_checkout( $data,$id );
619
		}
620
621
		//Set the Spoken Languages
622
		if ( false !== $importable_content && in_array( 'spoken_languages',$importable_content ) ) {
623
			$this->set_spoken_languages( $data,$id );
624
		}
625
626
		//Set the friendly options
627
		if ( false !== $importable_content && in_array( 'friendly',$importable_content ) ) {
628
			$this->set_friendly( $data,$id );
629
		}
630
631
		//Set the special_interests
632
		if ( false !== $importable_content && in_array( 'special_interests',$importable_content ) ) {
633
			$this->set_special_interests( $data,$id );
634
		}
635
636
		//Import the videos
637
		if ( false !== $importable_content && in_array( 'videos',$importable_content ) ) {
638
			$this->set_video_data( $data,$id );
639
		}
640
641
		//Import the facilities
642
		if ( false !== $importable_content && in_array( 'facilities',$importable_content ) ) {
643
			$this->set_facilities( $data,$id );
644
		}
645
646
		//Set the featured image
647
		if ( false !== $importable_content && in_array( 'featured_image',$importable_content ) ) {
648
			$this->set_featured_image( $data,$id );
649
		}
650
651
		if ( false !== $importable_content && in_array( 'banner_image',$importable_content ) ) {
652
			$this->set_banner_image( $data,$id );
653
		}
654
655
		//Import the main gallery
656
		if ( false !== $importable_content && in_array( 'gallery',$importable_content ) ) {
657
			$this->create_main_gallery( $data,$id );
658
		}
659
660
		return $id;
661
	}
662
663
	/**
664
	 * Set the team memberon each item.
665
	 */
666 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...
667
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
668
669
		foreach ( $team_members as $team ) {
670
			add_post_meta( $id,'team_to_' . $this->tab_slug,$team );
671
		}
672
	}
673
674
	/**
675
	 * Set the safari brand
676
	 */
677
	public function set_safari_brands( $id, $safari_brands ) {
678
		foreach ( $safari_brands as $safari_brand ) {
679
			wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand',true );
680
		}
681
	}
682
683
	/**
684
	 * Connects the destinations post type
685
	 */
686
	public function connect_destinations( $data, $id ) {
687
		if ( isset( $data[0]['position'] ) ) {
688
			$destinations = false;
689
690
			if ( isset( $data[0]['position']['country'] ) ) {
691
				$destinations['country'] = $data[0]['position']['country'];
692
			}
693
694
			if ( isset( $data[0]['position']['destination'] ) ) {
695
				$destinations['destination'] = $data[0]['position']['destination'];
696
			}
697
698
			if ( false !== $destinations ) {
699
				$prev_values = get_post_meta( $id,'destination_to_accommodation',false );
700
701
				if ( false === $prev_values || ! is_array( $prev_values ) ) {
702
					$prev_values = array();
703
				}
704
705
				delete_post_meta( $id,'destination_to_accommodation',$prev_values );
706
707
				//print_r($destinations);
708
				$destinations = array_unique( $destinations );
709
				//print_r($destinations);
710
711
				foreach ( $destinations as $key => $value ) {
712
					$destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' );
713
					if ( null !== $destination ) {
714
						if ( ! in_array( $destination->ID,$prev_values ) ) {
715
							   add_post_meta( $id,'destination_to_accommodation',$destination->ID,false );
716
							   add_post_meta( $destination->ID,'accommodation_to_destination',$id,false );
717
							$this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination';
718
						}
719
					}
720
				}
721
			}
722
		}
723
	}
724
725
	/**
726
	 * Set the Travel Style
727
	 */
728
	public function set_taxonomy_style( $data, $id ) {
729
		$terms = false;
0 ignored issues
show
Unused Code introduced by
$terms 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...
730
731
		if ( isset( $data[0]['category'] ) ) {
732
			// @codingStandardsIgnoreLine
733
			if ( ! $term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' ) ) {
734
				$term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' );
735
736
				if ( is_wp_error( $term ) ) {
737
					// @codingStandardsIgnoreLine
738
					echo $term->get_error_message();
739
				}
740
			} else {
741
				wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type',true );
742
			}
743
		} else {
744
			wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type',true );
0 ignored issues
show
Bug introduced by
The variable $term seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
745
		}
746
	}
747
748
	/**
749
	 * Saves the room data
750
	 */
751
	public function set_room_data( $data, $id ) {
752
		if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) {
753
			$rooms = false;
754
755
			foreach ( $data[0]['rooms'] as $room ) {
756
				$temp_room = array();
757
758
				if ( isset( $room['name'] ) ) {
759
					$temp_room['title'] = $room['name'];
760
				}
761
762
				if ( isset( $room['description'] ) ) {
763
					$temp_room['description'] = strip_tags( $room['description'] );
764
				}
765
766
				$temp_room['price'] = 0;
767
				$temp_room['type'] = 'room';
768
769
				if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) {
770
					$temp_room['gallery'] = array();
771
					$temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id );
772
773
					/*foreach($room['images'] as $image_data){
774
			    		$temp_room['gallery'][] = $this->attach_image($image_data,$id);
775
			    	}*/
776
				}
777
778
				$rooms[] = $temp_room;
779
			}
780
781
			if ( false !== $id && '0' !== $id ) {
782
				delete_post_meta( $id, 'units' );
783
			}
784
785
			foreach ( $rooms as $room ) {
0 ignored issues
show
Bug introduced by
The expression $rooms of type false is not traversable.
Loading history...
786
				add_post_meta( $id,'units',$room,false );
787
			}
788
789
			if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) {
790
				$room_count = $data[0]['features']['rooms'];
791
			} else {
792
				$room_count = count( $data[0]['rooms'] );
793
			}
794
795 View Code Duplication
			if ( false !== $id && '0' !== $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...
796
				$prev_rooms = get_post_meta( $id,'number_of_rooms',true );
797
				update_post_meta( $id,'number_of_rooms',$room_count,$prev_rooms );
798
			} else {
799
				add_post_meta( $id,'number_of_rooms',$room_count,true );
800
			}
801
		}
802
	}
803
804
	/**
805
	 * Set the ratings
806
	 */
807
	public function set_rating( $data, $id ) {
808
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) {
809
			$rating_type = $data[0]['features']['star_authority'];
810
		} else {
811
			$rating_type = 'Unspecified2';
812
		}
813
814
		$this->save_custom_field( $rating_type,'rating_type',$id );
815
816
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) {
817
			$this->save_custom_field( $data[0]['features']['stars'],'rating',$id,true );
818
		}
819
	}
820
821
	/**
822
	 * Set the spoken_languages
823
	 */
824 View Code Duplication
	public function set_spoken_languages( $data, $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...
825
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) {
826
			$languages = false;
827
828
			foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) {
829
				$languages[] = sanitize_title( $spoken_language );
830
			}
831
832
			if ( false !== $languages ) {
833
				$this->save_custom_field( $languages,'spoken_languages',$id );
834
			}
835
		}
836
	}
837
838
	/**
839
	 * Set the friendly
840
	 */
841 View Code Duplication
	public function set_friendly( $data, $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...
842
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) {
843
			$friendly_options = false;
844
845
			foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) {
846
				$friendly_options[] = sanitize_title( $visitor_type );
847
			}
848
849
			if ( false !== $friendly_options ) {
850
				$this->save_custom_field( $friendly_options,'suggested_visitor_types',$id );
851
			}
852
		}
853
	}
854
855
	/**
856
	 * Set the special interests
857
	 */
858 View Code Duplication
	public function set_special_interests( $data, $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...
859
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) {
860
			$interests = false;
861
862
			foreach ( $data[0]['features']['special_interests'] as $special_interest ) {
863
				$interests[] = sanitize_title( $special_interest );
864
			}
865
866
			if ( false !== $interests ) {
867
				$this->save_custom_field( $interests,'special_interests',$id );
868
			}
869
		}
870
	}
871
872
	/**
873
	 * Set the Check in and Check out Date
874
	 */
875
	public function set_checkin_checkout( $data, $id ) {
876 View Code Duplication
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) {
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...
877
			$time = str_replace( 'h',':',$data[0]['features']['check_in_time'] );
878
			$time = date( 'h:ia',strtotime( $time ) );
879
			$this->save_custom_field( $time,'checkin_time',$id );
0 ignored issues
show
Documentation introduced by
$time 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...
880
		}
881
882 View Code Duplication
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) {
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...
883
			$time = str_replace( 'h',':',$data[0]['features']['check_out_time'] );
884
			$time = date( 'h:ia',strtotime( $time ) );
885
			$this->save_custom_field( $time,'checkout_time',$id );
0 ignored issues
show
Documentation introduced by
$time 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...
886
		}
887
	}
888
889
	/**
890
	 * Set the Facilities
891
	 */
892
	public function set_facilities( $data, $id ) {
893
		$parent_facilities = array(
894
			'available_services' => 'Available Services',
895
			'property_facilities' => 'Property Facilities',
896
			'room_facilities' => 'Room Facilities',
897
			'activities_on_site' => 'Activities on Site',
898
		);
899
900
		foreach ( $parent_facilities as $key => $label ) {
901
			$terms = false;
0 ignored issues
show
Unused Code introduced by
$terms 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...
902
903
			if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) {
904
				$parent_id = $this->set_term( $id,$label,'facility' );
0 ignored issues
show
Documentation introduced by
$label 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...
Documentation introduced by
'facility' 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...
905
			}
906
907
			foreach ( $data[0]['features'][ $key ] as $child_facility ) {
908
				$this->set_term( $id,$child_facility,'facility',$parent_id );
0 ignored issues
show
Bug introduced by
The variable $parent_id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation introduced by
'facility' 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...
909
			}
910
		}
911
	}
912
}
913