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

LSX_WETU_Importer_Accommodation   F

Complexity

Total Complexity 197

Size/Duplication

Total Lines 874
Duplicated Lines 28.95 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 253
loc 874
rs 1.726
c 0
b 0
f 0
wmc 197
lcom 1
cbo 1

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set_variables() 24 24 5
C display_page() 12 129 11
A update_options_form() 0 11 1
A update_options() 12 12 4
F process_ajax_search() 40 107 33
A prepare_row_attributes() 10 10 1
A format_row() 27 27 3
A remove_from_queue() 11 11 3
C process_ajax_import() 16 56 16
F import_row() 39 148 53
A set_team_member() 7 7 2
A set_safari_brands() 0 5 2
B connect_destinations() 0 35 10
A set_taxonomy_style() 0 18 4
C set_room_data() 6 47 15
A set_rating() 0 13 5
A set_spoken_languages() 13 13 6
A set_friendly() 13 13 6
A set_special_interests() 13 13 6
A set_checkin_checkout() 10 13 5
A set_facilities() 0 20 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

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

Common duplication problems, and corresponding solutions are:

Complex Class

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

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

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

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

1
<?php
2
/**
3
 * @package   LSX_WETU_Importer_Accommodation
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link
7
 * @copyright 2016 LightSpeed
8
 **/
9
10
class LSX_WETU_Importer_Accommodation extends LSX_WETU_Importer {
11
12
	/**
13
	 * The url to list items from WETU
14
	 *
15
	 * @since 0.0.1
16
	 *
17
	 * @var      string
18
	 */
19
	public $tab_slug = '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( 'lsx_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->update_options_form(); ?>
103
104
			<div class="tablenav top">
105
				<?php $this->search_form(); ?>
106
			</div>
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
				<table class="wp-list-table widefat fixed posts">
112
					<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_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...
113
114
					<tbody id="the-list">
115
						<tr class="post-0 type-tour status-none" id="post-0">
116
							<th class="check-column" scope="row">
117
								<label for="cb-select-0" class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'lsx-wetu-importer' ); ?></label>
118
							</th>
119
							<td class="post-title page-title column-title">
120
								<strong>
121
									<?php esc_html_e( 'Enter a title to search for', 'lsx-wetu-importer' ); ?>
122
								</strong>
123
							</td>
124
							<td class="date column-date">
125
							</td>
126
							<td class="ssid column-ssid">
127
							</td>
128
						</tr>
129
					</tbody>
130
131
					<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_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...
132
133
				</table>
134
135
				<p><input class="button button-primary add" type="button" value="<?php esc_attr_e( 'Add to List', 'lsx-wetu-importer' ); ?>" />
136
					<input class="button button-primary clear" type="button" value="<?php esc_attr_e( 'Clear', 'lsx-wetu-importer' ); ?>" />
137
				</p>
138
			</form>
139
140
			<div style="display:none;" class="import-list-wrapper">
141
				<br />
142
				<form method="get" action="" id="import-list">
143
144
					<div class="row">
145
						<div class="settings-all" style="width:30%;display:block;float:left;">
146
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
147
							<ul>
148
								<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', 'lsx-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...
149
								<?php if ( ! isset( $this->options['disable_accommodation_descriptions'] ) ) { ?>
150
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'description' ); ?>" type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description', 'lsx-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...
151
								<?php } ?>
152
								<?php if ( ! isset( $this->options['disable_accommodation_excerpts'] ) ) { ?>
153
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'excerpt' ); ?>" type="checkbox" name="content[]" value="excerpt" /> <?php esc_html_e( 'Excerpt', 'lsx-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...
154
								<?php } ?>
155
156 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...
157
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'gallery' ); ?>" type="checkbox" name="content[]" value="gallery" /> <?php esc_html_e( 'Main Gallery', 'lsx-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
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'category' ); ?>" type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category', 'lsx-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...
160 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...
161
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'location' ); ?>" type="checkbox" name="content[]" value="location" /> <?php esc_html_e( 'Location', 'lsx-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,'destination' ); ?>" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Connect Destinations', 'lsx-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
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'rating' ); ?>" type="checkbox" name="content[]" value="rating" /> <?php esc_html_e( 'Rating', 'lsx-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...
165
								<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'rooms' ); ?>" type="checkbox" name="content[]" value="rooms" /> <?php esc_html_e( 'Rooms', 'lsx-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
167
								<?php if ( ! isset( $this->accommodation_settings['disable_single'] ) ) { ?>
168
									<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', 'lsx-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,'facilities' ); ?>" type="checkbox" name="content[]" value="facilities" /> <?php esc_html_e( 'Facilities', 'lsx-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
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'friendly' ); ?>" type="checkbox" name="content[]" value="friendly" /> <?php esc_html_e( 'Friendly', 'lsx-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...
171
								<?php } ?>
172
173
								<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', 'lsx-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,'spoken_languages' ); ?>" type="checkbox" name="content[]" value="spoken_languages" /> <?php esc_html_e( 'Spoken Languages', 'lsx-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
176 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...
177
									<li><input class="content" checked="<?php $this->checked( $this->accommodation_options,'videos' ); ?>" type="checkbox" name="content[]" value="videos" /> <?php esc_html_e( 'Videos', 'lsx-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
								<?php } ?>
179
							</ul>
180
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
181
							<ul>
182
								<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', 'lsx-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...
183 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...
184
									<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', 'lsx-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...
185
								<?php } ?>
186
							</ul>
187
						</div>
188
						<div style="width:30%;display:block;float:left;">
189
							<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
190
							<?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...
191
						</div>
192
193
						<div style="width:30%;display:block;float:left;">
194
							<h3><?php esc_html_e( 'Assign a Safari Brand' ); ?></h3>
195
							<?php
196
								echo wp_kses_post( $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...
197
							?>
198
						</div>
199
200
						<br clear="both" />
201
					</div>
202
203
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
204
					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
205
					<table class="wp-list-table widefat fixed posts">
206
						<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_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...
207
208
						<tbody>
209
210
						</tbody>
211
212
						<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method LSX_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...
213
214
					</table>
215
216
					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
217
				</form>
218
			</div>
219
220
			<div style="display:none;" class="completed-list-wrapper">
221
				<h3><?php esc_html_e( 'Completed' ); ?> - <small><?php esc_html_e( 'Import your', 'lsx-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', 'lsx-wetu-importer' ); ?></small></h3>
222
				<ul>
223
				</ul>
224
			</div>
225
		</div>
226
		<?php
227
	}
228
229
	/**
230
	 * search_form
231
	 */
232
	public function update_options_form() {
233
		echo '<div style="display:none;" class="wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . '</h3>';
234
235
		$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...
236
237
		//if ( '' === $accommodation || false === $accommodation || isset( $_GET['refresh_accommodation'] ) ) {
238
			//$this->update_options();
239
		//}
240
241
		echo '</div>';
242
	}
243
244
	/**
245
	 * Save the list of Accommodation into an option
246
	 */
247 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...
248
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
249
250
		$accommodation = json_decode( $data, true );
251
252
		if ( isset( $accommodation['error'] ) ) {
253
			return $accommodation['error'];
254
		} elseif ( isset( $accommodation ) && ! empty( $accommodation ) ) {
255
			set_transient( 'lsx_ti_accommodation',$accommodation,60 * 60 * 2 );
256
			return true;
257
		}
258
	}
259
260
	/**
261
	 * Run through the accommodation grabbed from the DB.
262
	 */
263
	public function process_ajax_search() {
264
		$return = false;
265
266
		// @codingStandardsIgnoreLine
267
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_tour_importer' && isset( $_POST['type'] ) && $_POST['type'] === 'accommodation' ) {
268
269
			$searched_items = false;
270
271
			// @codingStandardsIgnoreLine
272 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...
273
				// @codingStandardsIgnoreLine
274
				$keyphrases = $_POST['keyword'];
275
			} else {
276
				$keyphrases = array( 0 );
277
			}
278
279
			if ( ! is_array( $keyphrases ) ) {
280
				$keyphrases = array( $keyphrases );
281
			}
282
			foreach ( $keyphrases as &$keyword ) {
283
				$keyword = ltrim( rtrim( $keyword ) );
284
			}
285
286
			$post_status = false;
287
288
			if ( in_array( 'publish', $keyphrases ) ) {
289
				$post_status = 'publish';
290
			}
291
			if ( in_array( 'pending', $keyphrases ) ) {
292
				$post_status = 'pending';
293
			}
294
			if ( in_array( 'draft', $keyphrases ) ) {
295
				$post_status = 'draft';
296
			}
297
			if ( in_array( 'import', $keyphrases ) ) {
298
				$post_status = 'import';
299
			}
300
301
			// If there is a post status use it.
302
			if ( false !== $post_status ) {
303
304
				$accommodation = array();
305
				$current_accommodation = $this->find_current_accommodation();
306 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...
307
					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
308
						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
309
					}
310
				}
311
312
				// Run through each accommodation and use it.
313 View Code Duplication
				if ( ! empty( $accommodation ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
314
					foreach ( $accommodation as $row_key => $row ) {
315
						if ( 'import' === $post_status ) {
316
							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
317
								$current_status = get_post_status( $row['post_id'] );
318
								if ( 'draft' === $current_status ) {
319
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
320
								}
321
							} else {
322
								continue;
323
							}
324
						} else {
325
							if ( 0 === $row['post_id'] ) {
326
								continue;
327
							} else {
328
								$current_status = get_post_status( $row['post_id'] );
329
								if ( $current_status !== $post_status ) {
330
									continue;
331
								}
332
							}
333
							$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
334
						}
335
					}
336
				}
337
			} else {
338
				$key_string_search = implode( '+', $keyphrases );
339
				$search_data = file_get_contents( $this->url . '/Search/' . $key_string_search );
340
				$search_data = json_decode( $search_data, true );
341
342
				if ( ! isset( $search_data['error'] ) ) {
343
					foreach ( $search_data as $sdata ) {
344
345
						if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) {
346
							continue;
347
						}
348
349
						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
0 ignored issues
show
Bug introduced by
The method get_post_id_by_key_value() does not seem to exist on object<LSX_WETU_Importer_Accommodation>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
350 View Code Duplication
						if ( false === $temp_id ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

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

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
356
					}
357
				}
358
			}
359
360
			if ( false !== $searched_items ) {
361
				ksort( $searched_items );
362
				$return = implode( $searched_items );
363
			}
364
365
			print_r( $return );
366
		}
367
368
		die();
369
	}
370
371 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...
372
		$row_item = array(
373
			'id' => $cs_key,
374
			'type' => 'Accommodation',
375
			'name' => get_the_title( $ccs_id ),
376
			'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
377
			'post_id' => $ccs_id,
378
		);
379
		return $row_item;
380
	}
381
382
	/**
383
	 * Formats the row for output on the screen.
384
	 *
385
	 * @param boolean $row the current row to format.
386
	 * @return void
387
	 */
388 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...
389
		if ( false !== $row ) {
390
391
			$status = 'import';
392
			if ( 0 !== $row['post_id'] ) {
393
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
394
			}
395
396
			$row_html = '
397
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
398
				<th class="check-column" scope="row">
399
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
400
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
401
				</th>
402
				<td class="post-title page-title column-title">
403
					<strong>' . $row['name'] . '</strong> - ' . $status . '
404
				</td>
405
				<td class="date column-date">
406
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
407
				</td>
408
				<td class="ssid column-ssid">
409
					' . $row['id'] . '
410
				</td>
411
			</tr>';
412
			return $row_html;
413
		}
414
	}
415
416
	/**
417
	 * Saves the queue to the option.
418
	 */
419 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...
420
		if ( ! empty( $this->queued_imports ) ) {
421
			$key = array_search( $id, $this->queued_imports );
422
			if ( false !== $key ) {
423
				unset( $this->queued_imports[ $key ] );
424
425
				delete_option( 'lsx_wetu_importer_que' );
426
				update_option( 'lsx_wetu_importer_que', $this->queued_imports );
427
			}
428
		}
429
	}
430
431
	/**
432
	 * Connect to wetu
433
	 */
434
	public function process_ajax_import() {
435
		$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...
436
437
		// @codingStandardsIgnoreLine
438
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'accommodation' && isset( $_POST['wetu_id'] ) ) {
439
			// @codingStandardsIgnoreLine
440
			$wetu_id = $_POST['wetu_id'];
441
442
			// @codingStandardsIgnoreLine
443
			if ( isset( $_POST['post_id'] ) ) {
444
				// @codingStandardsIgnoreLine
445
				$post_id = $_POST['post_id'];
446
			} else {
447
				$post_id = 0;
448
			}
449
450
			// @codingStandardsIgnoreLine
451
			if ( isset( $_POST['team_members'] ) ) {
452
				// @codingStandardsIgnoreLine
453
				$team_members = $_POST['team_members'];
454
			} else {
455
				$team_members = false;
456
			}
457
458
			// @codingStandardsIgnoreLine
459
			if ( isset( $_POST['safari_brands'] ) ) {
460
				// @codingStandardsIgnoreLine
461
				$safari_brands = $_POST['safari_brands'];
462
			} else {
463
				$safari_brands = false;
464
			}
465
466
			delete_option( 'lsx_wetu_importer_accommodation_settings' );
467
468
			// @codingStandardsIgnoreLine
469 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...
470
				// @codingStandardsIgnoreLine
471
				$content = $_POST['content'];
472
				add_option( 'lsx_wetu_importer_accommodation_settings',$content );
473
			} else {
474
				$content = false;
475
			}
476
477
			$jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
478
479 View Code Duplication
			if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
480
				$adata = json_decode( $jdata['body'], true );
481
				$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
482
				$this->format_completed_row( $return );
483
				$this->remove_from_queue( $return );
484
				$this->cleanup_posts();
485
			} else {
486
				$this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) );
487
			}
488
		}
489
	}
490
491
	/**
492
	 * Connect to wetu
493
	 */
494
	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
495
		$post_name = '';
496
		$data_post_content = '';
497
		$data_post_excerpt = '';
498
499
		$post = array(
500
			'post_type' => 'accommodation',
501
		);
502
		$content_used_general_description = false;
503
504
		// Set the post_content.
505
		if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
506
			if ( isset( $data[0]['content']['extended_description'] ) ) {
507
				$data_post_content = $data[0]['content']['extended_description'];
508 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...
509
				$data_post_content = $data[0]['content']['general_description'];
510
				$content_used_general_description = true;
511
			} elseif ( isset( $data[0]['content']['teaser_description'] ) ) {
512
				$data_post_content = $data[0]['content']['teaser_description'];
513
			}
514
515
			$post['post_content'] = wp_strip_all_tags( $data_post_content );
516
		}
517
518
		// set the post_excerpt.
519
		if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) {
520
			if ( isset( $data[0]['content']['teaser_description'] ) ) {
521
				$data_post_excerpt = $data[0]['content']['teaser_description'];
522 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...
523
				$data_post_excerpt = $data[0]['content']['general_description'];
524
			}
525
526
			$post['post_excerpt'] = $data_post_excerpt;
527
		}
528
529 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...
530
			$post['ID'] = $id;
531
532
			if ( isset( $data[0]['name'] ) ) {
533
				$post['post_title'] = $data[0]['name'];
534
				$post['post_status'] = 'publish';
535
				$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
536
			}
537
538
			$id = wp_update_post( $post );
539
			$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
540
			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
541
		} else {
542
			// Set the name.
543
			if ( isset( $data[0]['name'] ) ) {
544
				$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
545
			}
546
547
			$post['post_name']   = $post_name;
548
			$post['post_title']  = $data[0]['name'];
549
			$post['post_status'] = 'publish';
550
			$id                  = wp_insert_post( $post );
551
552
			// Save the WETU ID and the Last date it was modified.
553
			if ( false !== $id ) {
554
				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
555
				add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
556
			}
557
		}
558
559
		// Setup some default for use in the import.
560
		if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) {
561
			$this->find_attachments( $id );
562
		}
563
564
		// Set the team member if it is there.
565 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...
566
			$this->set_team_member( $id, $team_members );
567
		}
568
569
		// Set the safari brand.
570
		if ( false !== $safari_brands && '' !== $safari_brands ) {
571
			$this->set_safari_brands( $id, $safari_brands );
572
		}
573
574
		if ( class_exists( 'LSX_TO_Maps' ) ) {
575
			$this->set_map_data( $data, $id, 9 );
576
		}
577
578
		if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) {
579
			$this->connect_destinations( $data, $id );
580
		}
581
582
		if ( false !== $importable_content && in_array( 'category', $importable_content ) ) {
583
			$this->set_taxonomy_style( $data, $id );
584
		}
585
586
		// Set the Room Data.
587
		if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) {
588
			$this->set_room_data( $data, $id );
589
		}
590
591
		// Set the rating.
592
		if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) {
593
			$this->set_rating( $data, $id );
594
		}
595
596
		// Set the checkin checkout data.
597
		if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) {
598
			$this->set_checkin_checkout( $data, $id );
599
		}
600
601
		// Set the Spoken Languages.
602
		if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) {
603
			$this->set_spoken_languages( $data, $id );
604
		}
605
606
		// Set the friendly options.
607
		if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) {
608
			$this->set_friendly( $data, $id );
609
		}
610
611
		// Set the special_interests.
612
		if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) {
613
			$this->set_special_interests( $data, $id );
614
		}
615
616
		// Import the videos.
617
		if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
618
			$this->set_video_data( $data, $id );
619
		}
620
621
		// Import the facilities.
622
		if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) {
623
			$this->set_facilities( $data, $id );
624
		}
625
626
		// Set the featured image.
627
		if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
628
			$this->set_featured_image( $data, $id );
629
		}
630
631
		if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
632
			$this->set_banner_image( $data, $id );
633
		}
634
635
		// Import the main gallery.
636
		if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
637
			$this->create_main_gallery( $data, $id );
638
		}
639
640
		return $id;
641
	}
642
643
	/**
644
	 * Set the team memberon each item.
645
	 */
646 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...
647
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
648
649
		foreach ( $team_members as $team ) {
650
			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
651
		}
652
	}
653
654
	/**
655
	 * Set the safari brand
656
	 */
657
	public function set_safari_brands( $id, $safari_brands ) {
658
		foreach ( $safari_brands as $safari_brand ) {
659
			wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true );
660
		}
661
	}
662
663
	/**
664
	 * Connects the destinations post type
665
	 */
666
	public function connect_destinations( $data, $id ) {
667
		if ( isset( $data[0]['position'] ) ) {
668
			$destinations = false;
669
670
			if ( isset( $data[0]['position']['country'] ) ) {
671
				$destinations['country'] = $data[0]['position']['country'];
672
			}
673
674
			if ( isset( $data[0]['position']['destination'] ) ) {
675
				$destinations['destination'] = $data[0]['position']['destination'];
676
			}
677
678
			if ( false !== $destinations ) {
679
				$prev_values = get_post_meta( $id, 'destination_to_accommodation', false );
680
681
				if ( false === $prev_values || ! is_array( $prev_values ) ) {
682
					$prev_values = array();
683
				}
684
685
				delete_post_meta( $id, 'destination_to_accommodation', $prev_values );
686
				$destinations = array_unique( $destinations );
687
688
				foreach ( $destinations as $key => $value ) {
689
					$destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' );
690
					if ( null !== $destination ) {
691
						if ( ! in_array( $destination->ID, $prev_values ) ) {
692
							add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false );
693
							add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false );
694
							$this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination';
695
						}
696
					}
697
				}
698
			}
699
		}
700
	}
701
702
	/**
703
	 * Set the Travel Style
704
	 */
705
	public function set_taxonomy_style( $data, $id ) {
706
		$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...
707
708
		if ( isset( $data[0]['category'] ) ) {
709
			$term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' );
710
			if ( ! $term ) {
711
				$term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' );
712
713
				if ( is_wp_error( $term ) ) {
714
					echo wp_kses_post( $term->get_error_message() );
715
				}
716
			} else {
717
				wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true );
718
			}
719
		} else {
720
			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...
721
		}
722
	}
723
724
	/**
725
	 * Saves the room data
726
	 */
727
	public function set_room_data( $data, $id ) {
728
		if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) {
729
			$rooms = false;
730
731
			foreach ( $data[0]['rooms'] as $room ) {
732
				$temp_room = array();
733
734
				if ( isset( $room['name'] ) ) {
735
					$temp_room['title'] = $room['name'];
736
				}
737
738
				if ( isset( $room['description'] ) ) {
739
					$temp_room['description'] = strip_tags( $room['description'] );
740
				}
741
742
				$temp_room['price'] = 0;
743
				$temp_room['type']  = 'room';
744
745
				if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) {
746
					$temp_room['gallery'] = array();
747
					$temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id );
748
				}
749
				$rooms[] = $temp_room;
750
			}
751
752
			if ( false !== $id && '0' !== $id ) {
753
				delete_post_meta( $id, 'units' );
754
			}
755
756
			foreach ( $rooms as $room ) {
0 ignored issues
show
Bug introduced by
The expression $rooms of type false is not traversable.
Loading history...
757
				add_post_meta( $id, 'units', $room, false );
758
			}
759
760
			if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) {
761
				$room_count = $data[0]['features']['rooms'];
762
			} else {
763
				$room_count = count( $data[0]['rooms'] );
764
			}
765
766 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...
767
				$prev_rooms = get_post_meta( $id, 'number_of_rooms', true );
768
				update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms );
769
			} else {
770
				add_post_meta( $id, 'number_of_rooms', $room_count, true );
771
			}
772
		}
773
	}
774
775
	/**
776
	 * Set the ratings
777
	 */
778
	public function set_rating( $data, $id ) {
779
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) {
780
			$rating_type = $data[0]['features']['star_authority'];
781
		} else {
782
			$rating_type = 'Unspecified2';
783
		}
784
785
		$this->save_custom_field( $rating_type, 'rating_type', $id );
786
787
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) {
788
			$this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true );
789
		}
790
	}
791
792
	/**
793
	 * Set the spoken_languages
794
	 */
795 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...
796
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) {
797
			$languages = false;
798
799
			foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) {
800
				$languages[] = sanitize_title( $spoken_language );
801
			}
802
803
			if ( false !== $languages ) {
804
				$this->save_custom_field( $languages, 'spoken_languages', $id );
805
			}
806
		}
807
	}
808
809
	/**
810
	 * Set the friendly
811
	 */
812 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...
813
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) {
814
			$friendly_options = false;
815
816
			foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) {
817
				$friendly_options[] = sanitize_title( $visitor_type );
818
			}
819
820
			if ( false !== $friendly_options ) {
821
				$this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id );
822
			}
823
		}
824
	}
825
826
	/**
827
	 * Set the special interests
828
	 */
829 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...
830
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) {
831
			$interests = false;
832
833
			foreach ( $data[0]['features']['special_interests'] as $special_interest ) {
834
				$interests[] = sanitize_title( $special_interest );
835
			}
836
837
			if ( false !== $interests ) {
838
				$this->save_custom_field( $interests, 'special_interests', $id );
839
			}
840
		}
841
	}
842
843
	/**
844
	 * Set the Check in and Check out Date
845
	 */
846
	public function set_checkin_checkout( $data, $id ) {
847 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...
848
			$time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] );
849
			$time = date( 'h:ia', strtotime( $time ) );
850
			$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...
851
		}
852
853 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...
854
			$time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] );
855
			$time = date( 'h:ia', strtotime( $time ) );
856
			$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...
857
		}
858
	}
859
860
	/**
861
	 * Set the Facilities
862
	 */
863
	public function set_facilities( $data, $id ) {
864
		$parent_facilities = array(
865
			'available_services' => 'Available Services',
866
			'property_facilities' => 'Property Facilities',
867
			'room_facilities' => 'Room Facilities',
868
			'activities_on_site' => 'Activities on Site',
869
		);
870
871
		foreach ( $parent_facilities as $key => $label ) {
872
			$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...
873
874
			if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) {
875
				$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...
Bug introduced by
Are you sure the assignment to $parent_id is correct as $this->set_term($id, $label, 'facility') (which targets LSX_WETU_Importer::set_term()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
876
			}
877
878
			foreach ( $data[0]['features'][ $key ] as $child_facility ) {
879
				$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...
Documentation introduced by
$parent_id is of type null, 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
	}
883
}
884