Completed
Push — master ( a84d89...a9842c )
by Fernando
02:35
created

WETU_Importer_Accommodation   D

Complexity

Total Complexity 194

Size/Duplication

Total Lines 880
Duplicated Lines 21.14 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 194
lcom 1
cbo 1
dl 186
loc 880
rs 4.4444
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B set_variables() 22 24 5
D display_page() 12 134 11
A update_options_form() 0 11 4
A update_options() 6 12 4
F process_ajax_search() 5 106 28
B format_row() 27 27 3
A remove_from_queue() 11 11 3
C process_ajax_import() 23 62 16
F import_row() 30 149 53
A set_team_member() 7 7 2
A set_safari_brands() 0 5 2
D connect_destinations() 0 38 10
A set_taxonomy_style() 0 19 4
C set_room_data() 0 52 15
B set_rating() 0 13 5
B set_spoken_languages() 11 13 6
B set_friendly() 11 13 6
B set_special_interests() 11 13 6
B set_checkin_checkout() 10 13 5
B 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 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 WETU_Importer_Accommodation, and based on these observations, apply Extract Interface, too.

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 ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
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' );
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
	public function update_options() {
253
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
254
255
		$accommodation = json_decode( $data, true );
256
257 View Code Duplication
		if ( isset( $accommodation['error'] ) ) {
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...
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
				if ( ! empty( $accommodation ) ) {
313
					$current_accommodation = $this->find_current_accommodation();
314
315
					foreach ( $accommodation as $row_key => $row ) {
316
						//If this is a current tour, add its ID to the row.
317
						$row['post_id'] = 0;
318
319
						if ( false !== $current_accommodation && array_key_exists( $row['id'], $current_accommodation ) ) {
320
							$row['post_id'] = $current_accommodation[ $row['id'] ]->post_id;
321
						}
322
323
						//If we are searching for
324
						if ( false !== $post_status ) {
325
							if ( 'import' === $post_status ) {
326
327
								if ( is_array( $this->queued_imports ) && in_array( $row['post_id'],$this->queued_imports ) ) {
328
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
329
								} else {
330
									continue;
331
								}
332
							} else {
333
								if ( 0 === $row['post_id'] ) {
334
									continue;
335
								} else {
336
									$current_status = get_post_status( $row['post_id'] );
337
338
									if ( $current_status !== $post_status ) {
339
										continue;
340
									}
341
								}
342
343
								$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
344
							}
345
						} else {
346
							//Search through each keyword.
347
							foreach ( $keyphrases as $keyphrase ) {
348
								//Make sure the keyphrase is turned into an array
349
								$keywords = explode( ' ',$keyphrase );
350
351
								if ( ! is_array( $keywords ) ) {
352
									$keywords = array( $keywords );
353
								}
354
355
								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
356
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
357
								}
358
							}
359
						}
360
					}
361
				}
362
363
				if ( false !== $searched_items ) {
364
					ksort( $searched_items );
365
					$return = implode( $searched_items );
366
				}
367
			}
368
369
			print_r( $return );
370
		}
371
372
		die();
373
	}
374
375
	/**
376
	 * Formats the row for output on the screen.
377
	 */
378 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...
379
		if ( false !== $row ) {
380
381
			$status = 'import';
382
			if ( 0 !== $row['post_id'] ) {
383
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
384
			}
385
386
			$row_html = '
387
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
388
				<th class="check-column" scope="row">
389
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
390
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
391
				</th>
392
				<td class="post-title page-title column-title">
393
					<strong>' . $row['name'] . '</strong> - ' . $status . '
394
				</td>
395
				<td class="date column-date">
396
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
397
				</td>
398
				<td class="ssid column-ssid">
399
					' . $row['id'] . '
400
				</td>
401
			</tr>';
402
			return $row_html;
403
		}
404
	}
405
406
	/**
407
	 * Saves the queue to the option.
408
	 */
409 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...
410
		if ( ! empty( $this->queued_imports ) ) {
411
			// @codingStandardsIgnoreLine
412
			if ( ( $key = array_search( $id, $this->queued_imports ) ) !== false ) {
413
				unset( $this->queued_imports[ $key ] );
414
415
				delete_option( 'wetu_importer_que' );
416
				update_option( 'wetu_importer_que',$this->queued_imports );
417
			}
418
		}
419
	}
420
421
	/**
422
	 * Connect to wetu
423
	 */
424
	public function process_ajax_import() {
425
		$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...
426
427
		// @codingStandardsIgnoreLine
428
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'accommodation' && isset( $_POST['wetu_id'] ) ) {
429
			// @codingStandardsIgnoreLine
430
			$wetu_id = $_POST['wetu_id'];
431
432
			// @codingStandardsIgnoreLine
433
			if ( isset( $_POST['post_id'] ) ) {
434
				// @codingStandardsIgnoreLine
435
				$post_id = $_POST['post_id'];
436
			} else {
437
				$post_id = 0;
438
			}
439
440
			// @codingStandardsIgnoreLine
441
			if ( isset( $_POST['team_members'] ) ) {
442
				// @codingStandardsIgnoreLine
443
				$team_members = $_POST['team_members'];
444
			} else {
445
				$team_members = false;
446
			}
447
448
			// @codingStandardsIgnoreLine
449
			if ( isset( $_POST['safari_brands'] ) ) {
450
				// @codingStandardsIgnoreLine
451
				$safari_brands = $_POST['safari_brands'];
452
			} else {
453
				$safari_brands = false;
454
			}
455
456
			delete_option( 'wetu_importer_accommodation_settings' );
457
458
			// @codingStandardsIgnoreLine
459 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...
460
				// @codingStandardsIgnoreLine
461
				$content = $_POST['content'];
462
				add_option( 'wetu_importer_accommodation_settings',$content );
463
			} else {
464
				$content = false;
465
			}
466
467
			$jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
468
469 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...
470
				$adata = json_decode( $jdata,true );
471
				if ( ! empty( $adata ) && ! isset( $adata['error'] ) ) {
472
					$return = $this->import_row( $adata,$wetu_id,$post_id,$team_members,$content,$safari_brands );
473
					$this->format_completed_row( $return );
474
					$this->remove_from_queue( $return );
475
					$this->cleanup_posts();
476
				} else {
477
					if ( isset( $adata['error'] ) ) {
478
						$this->format_error( $adata['error'] );
479
					} else {
480
						$this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'wetu-importer' ) );
481
					}
482
				}
483
			}
484
		}
485
	}
486
487
	/**
488
	 * Connect to wetu
489
	 */
490
	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = false, $safari_brands = false ) {
491
		$post_name = '';
492
		$data_post_content = '';
493
		$data_post_excerpt = '';
494
495
		$post = array(
496
		  'post_type' => 'accommodation',
497
		);
498
499
		$content_used_general_description = false;
500
501
		//Set the post_content
502
		if ( false !== $importable_content && in_array( 'description',$importable_content ) ) {
503
			if ( isset( $data[0]['content']['extended_description'] ) ) {
504
				$data_post_content = $data[0]['content']['extended_description'];
505
			} elseif ( isset( $data[0]['content']['general_description'] ) ) {
506
				$data_post_content = $data[0]['content']['general_description'];
507
				$content_used_general_description = true;
508
			} elseif ( isset( $data[0]['content']['teaser_description'] ) ) {
509
				$data_post_content = $data[0]['content']['teaser_description'];
510
			}
511
512
			$post['post_content'] = wp_strip_all_tags( $data_post_content );
513
		}
514
515
		//set the post_excerpt
516
		if ( false !== $importable_content && in_array( 'excerpt',$importable_content ) ) {
517
			if ( isset( $data[0]['content']['teaser_description'] ) ) {
518
				$data_post_excerpt = $data[0]['content']['teaser_description'];
519
			} elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) {
520
				$data_post_excerpt = $data[0]['content']['general_description'];
521
			}
522
523
			$post['post_excerpt'] = $data_post_excerpt;
524
		}
525
526 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...
527
			$post['ID'] = $id;
528
529
			if ( isset( $data[0]['name'] ) ) {
530
				$post['post_title'] = $data[0]['name'];
531
				$post['post_status'] = 'publish';
532
				$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ),$id, 'draft', 'accommodation', 0 );
533
			}
534
535
			$id = wp_update_post( $post );
536
			$prev_date = get_post_meta( $id,'lsx_wetu_modified_date', true );
537
			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
538
		} else {
539
			//Set the name
540
			if ( isset( $data[0]['name'] ) ) {
541
				$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ),$id, 'draft', 'accommodation', 0 );
542
			}
543
544
			$post['post_name'] = $post_name;
545
			$post['post_title'] = $data[0]['name'];
546
			$post['post_status'] = 'publish';
547
			$id = wp_insert_post( $post );
548
549
			//Save the WETU ID and the Last date it was modified.
550
			if ( false !== $id ) {
551
				add_post_meta( $id,'lsx_wetu_id',$wetu_id );
552
				add_post_meta( $id,'lsx_wetu_modified_date',strtotime( $data[0]['last_modified'] ) );
553
			}
554
		}
555
556
		//Setup some default for use in the import
557
		if ( false !== $importable_content && (in_array( 'gallery',$importable_content ) || in_array( 'banner_image',$importable_content ) || in_array( 'featured_image',$importable_content )) ) {
558
			$this->find_attachments( $id );
559
		}
560
561
		//Set the team member if it is there
562 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...
563
			$this->set_team_member( $id,$team_members );
564
		}
565
566
		//Set the safari brand
567
		if ( false !== $safari_brands && '' !== $safari_brands ) {
568
			$this->set_safari_brands( $id,$safari_brands );
569
		}
570
571
		if ( class_exists( 'LSX_TO_Maps' ) ) {
572
			$this->set_map_data( $data,$id,9 );
573
		}
574
575
		if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination',$importable_content ) ) {
576
			$this->connect_destinations( $data,$id );
577
		}
578
579
		if ( false !== $importable_content && in_array( 'category',$importable_content ) ) {
580
			$this->set_taxonomy_style( $data,$id );
581
		}
582
583
		//Set the Room Data
584
		if ( false !== $importable_content && in_array( 'rooms',$importable_content ) ) {
585
			$this->set_room_data( $data,$id );
586
		}
587
588
		//Set the rating
589
		if ( false !== $importable_content && in_array( 'rating',$importable_content ) ) {
590
			$this->set_rating( $data,$id );
591
		}
592
593
		//Set the checkin checkout data
594
		if ( false !== $importable_content && in_array( 'checkin',$importable_content ) ) {
595
			$this->set_checkin_checkout( $data,$id );
596
		}
597
598
		//Set the Spoken Languages
599
		if ( false !== $importable_content && in_array( 'spoken_languages',$importable_content ) ) {
600
			$this->set_spoken_languages( $data,$id );
601
		}
602
603
		//Set the friendly options
604
		if ( false !== $importable_content && in_array( 'friendly',$importable_content ) ) {
605
			$this->set_friendly( $data,$id );
606
		}
607
608
		//Set the special_interests
609
		if ( false !== $importable_content && in_array( 'special_interests',$importable_content ) ) {
610
			$this->set_special_interests( $data,$id );
611
		}
612
613
		//Import the videos
614
		if ( false !== $importable_content && in_array( 'videos',$importable_content ) ) {
615
			$this->set_video_data( $data,$id );
616
		}
617
618
		//Import the facilities
619
		if ( false !== $importable_content && in_array( 'facilities',$importable_content ) ) {
620
			$this->set_facilities( $data,$id );
621
		}
622
623
		//Set the featured image
624
		if ( false !== $importable_content && in_array( 'featured_image',$importable_content ) ) {
625
			$this->set_featured_image( $data,$id );
626
		}
627
628
		if ( false !== $importable_content && in_array( 'banner_image',$importable_content ) ) {
629
			$this->set_banner_image( $data,$id );
630
		}
631
632
		//Import the main gallery
633
		if ( false !== $importable_content && in_array( 'gallery',$importable_content ) ) {
634
			$this->create_main_gallery( $data,$id );
635
		}
636
637
		return $id;
638
	}
639
640
	/**
641
	 * Set the team memberon each item.
642
	 */
643 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...
644
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
645
646
		foreach ( $team_members as $team ) {
647
			add_post_meta( $id,'team_to_' . $this->tab_slug,$team );
648
		}
649
	}
650
651
	/**
652
	 * Set the safari brand
653
	 */
654
	public function set_safari_brands( $id, $safari_brands ) {
655
		foreach ( $safari_brands as $safari_brand ) {
656
			wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand',true );
657
		}
658
	}
659
660
	/**
661
	 * Connects the destinations post type
662
	 */
663
	public function connect_destinations( $data, $id ) {
664
		if ( isset( $data[0]['position'] ) ) {
665
			$destinations = false;
666
667
			if ( isset( $data[0]['position']['country'] ) ) {
668
				$destinations['country'] = $data[0]['position']['country'];
669
			}
670
671
			if ( isset( $data[0]['position']['destination'] ) ) {
672
				$destinations['destination'] = $data[0]['position']['destination'];
673
			}
674
675
			if ( false !== $destinations ) {
676
				$prev_values = get_post_meta( $id,'destination_to_accommodation',false );
677
678
				if ( false === $prev_values || ! is_array( $prev_values ) ) {
679
					$prev_values = array();
680
				}
681
682
				delete_post_meta( $id,'destination_to_accommodation',$prev_values );
683
684
				//print_r($destinations);
685
				$destinations = array_unique( $destinations );
686
				//print_r($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
			// @codingStandardsIgnoreLine
710
			if ( ! $term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' ) ) {
711
				$term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' );
712
713
				if ( is_wp_error( $term ) ) {
714
					// @codingStandardsIgnoreLine
715
					echo $term->get_error_message();
716
				}
717
			} else {
718
				wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type',true );
719
			}
720
		} else {
721
			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...
722
		}
723
	}
724
725
	/**
726
	 * Saves the room data
727
	 */
728
	public function set_room_data( $data, $id ) {
729
		if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) {
730
			$rooms = false;
731
732
			foreach ( $data[0]['rooms'] as $room ) {
733
				$temp_room = array();
734
735
				if ( isset( $room['name'] ) ) {
736
					$temp_room['title'] = $room['name'];
737
				}
738
739
				if ( isset( $room['description'] ) ) {
740
					$temp_room['description'] = strip_tags( $room['description'] );
741
				}
742
743
				$temp_room['price'] = 0;
744
				$temp_room['type'] = 'room';
745
746
				if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) {
747
					$temp_room['gallery'] = array();
748
					$temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id );
749
750
					/*foreach($room['images'] as $image_data){
0 ignored issues
show
Unused Code Comprehensibility introduced by
76% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

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