Passed
Push — master ( 4ddb5b...a3fb73 )
by Warwick
03:31
created

WETU_Importer_Accommodation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @package   WETU_Importer_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
	{
73
	    parent::set_variables();
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 = '';
81
		//}
82
83
		$temp_options = get_option('_lsx-to_settings',false);
84
		if(false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])){
85
			$this->options = $temp_options[$this->plugin_slug];
86
		}
87
88
		$accommodation_options = get_option('wetu_importer_accommodation_settings',false);
89
		if(false !== $accommodation_options){
90
			$this->accommodation_options = $accommodation_options;
91
		}
92
	}
93
94
	/**
95
	 * Display the importer administration screen
96
	 */
97
	public function display_page() {
98
        ?>
99
        <div class="wrap">
100
            <?php $this->navigation('accommodation'); ?>
101
102
            <?php $this->update_options_form(); ?>
103
104
            <?php $this->search_form(); ?>
105
106
			<form method="get" action="" id="posts-filter">
107
				<input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>" />
108
				
109
				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" />
110
					<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" />
111
				</p>				
112
113
				<table class="wp-list-table widefat fixed posts">
114
					<?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...
115
				
116
					<tbody id="the-list">
117
						<tr class="post-0 type-tour status-none" id="post-0">
118
							<th class="check-column" scope="row">
119
								<label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter','wetu-importer'); ?></label>
120
							</th>
121
							<td class="post-title page-title column-title">
122
								<strong>
123
									<?php _e('Enter a title to search for','wetu-importer'); ?>
124
								</strong>
125
							</td>
126
							<td class="date column-date">							
127
							</td>
128
							<td class="ssid column-ssid">
129
							</td>
130
						</tr>									
131
					</tbody>
132
133
					<?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...
134
135
				</table>
136
137
				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" />
138
					<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" />
139
				</p>
140
			</form> 
141
142
			<div style="display:none;" class="import-list-wrapper">
143
				<br />        
144
				<form method="get" action="" id="import-list">
145
146
					<div class="row">
147
						<div class="settings-all" style="width:30%;display:block;float:left;">
148
							<h3><?php _e('What content to Sync from WETU'); ?></h3>
149
							<ul>
150
                                <li><input class="content select-all" <?php $this->checked($this->accommodation_options,'all'); ?> type="checkbox"name="content[]"  value="all" /> <?php _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...
151
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'description'); ?>" type="checkbox" name="content[]" value="description" /> <?php _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...
152
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'excerpt'); ?>" type="checkbox" name="content[]" value="excerpt" /> <?php _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...
153
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'gallery'); ?>" type="checkbox" name="content[]" value="gallery" /> <?php _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...
154
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'category'); ?>" type="checkbox" name="content[]" value="category" /> <?php _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...
155 View Code Duplication
		                        <?php if(class_exists('LSX_TO_Maps')){ ?>
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...
156
								    <li><input class="content" checked="<?php $this->checked($this->accommodation_options,'location'); ?>" type="checkbox" name="content[]" value="location" /> <?php _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...
157
		                        <?php } ?>
158
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'destination'); ?>" type="checkbox" name="content[]" value="destination" /> <?php _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...
159
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'checkin'); ?>" type="checkbox" name="content[]" value="checkin" /> <?php _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...
160
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'facilities'); ?>" type="checkbox" name="content[]" value="facilities" /> <?php _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...
161
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'friendly'); ?>" type="checkbox" name="content[]" value="friendly" /> <?php _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...
162
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'rating'); ?>" type="checkbox" name="content[]" value="rating" /> <?php _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...
163
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'rooms'); ?>" type="checkbox" name="content[]" value="rooms" /> <?php _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...
164
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'special_interests'); ?>" type="checkbox" name="content[]" value="special_interests" /> <?php _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...
165
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'spoken_languages'); ?>" type="checkbox" name="content[]" value="spoken_languages" /> <?php _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...
166
167 View Code Duplication
		                        <?php if(class_exists('LSX_TO_Videos')){ ?>
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...
168
								    <li><input class="content" checked="<?php $this->checked($this->accommodation_options,'videos'); ?>" type="checkbox" name="content[]" value="videos" /> <?php _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...
169
		                        <?php } ?>
170
							</ul>
171
							<h4><?php _e('Additional Content'); ?></h4>
172
							<ul>
173
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'featured_image'); ?>" type="checkbox" name="content[]" value="featured_image" /> <?php _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...
174 View Code Duplication
		                        <?php if(class_exists('LSX_Banners')){ ?>
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...
175
								    <li><input class="content" checked="<?php $this->checked($this->accommodation_options,'banner_image'); ?>" type="checkbox" name="content[]" value="banner_image" /> <?php _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...
176
		                        <?php } ?>
177
							</ul>
178
						</div>
179
						<div style="width:30%;display:block;float:left;">
180
							<h3><?php _e('Assign a Team Member'); ?></h3> 
181
							<?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...
182
						</div>
183
184
						<div style="width:30%;display:block;float:left;">
185
							<h3><?php _e('Assign a Safari Brand'); ?></h3> 
186
							<?php 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...
187
						</div>	
188
189
						<br clear="both" />			
190
					</div>
191
192
193
					<h3><?php _e('Your List'); ?></h3>
194
                    <p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p>
195
					<table class="wp-list-table widefat fixed posts">
196
						<?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...
197
198
						<tbody>
199
200
						</tbody>
201
202
						<?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...
203
204
					</table>
205
206
					<p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p>
207
				</form>
208
			</div>
209
210
			<div style="display:none;" class="completed-list-wrapper">
211
				<h3><?php _e('Completed'); ?> - <small><?php _e('Import your','wetu-importer'); ?> <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=destination"><?php _e('destinations'); ?></a> <?php _e('next','wetu-importer'); ?></small></h3>
212
				<ul>
213
				</ul>
214
			</div>
215
        </div>
216
        <?php
217
	}
218
219
	/**
220
	 * search_form
221
	 */
222
	public function update_options_form() {
223
		echo '<div style="display:none;" class="wetu-status"><h3>'.__('Wetu Status','wetu-importer').'</h3>';
224
		$accommodation = get_transient('lsx_ti_accommodation');
225
		if('' === $accommodation || false === $accommodation || isset($_GET['refresh_accommodation'])){
226
			$this->update_options();
227
		}
228
		echo '</div>';
229
	}
230
231
	/**
232
	 * Save the list of Accommodation into an option
233
	 */
234
	public function update_options() {
235
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
236
		$accommodation = json_decode($data, true);
237
238 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...
239
		    return $accommodation['error'];
240
        }elseif (isset($accommodation) && !empty($accommodation)) {
241
			set_transient('lsx_ti_accommodation',$accommodation,60*60*2);
242
			return true;
243
		}
244
	}
245
246
	/**
247
	 * Run through the accommodation grabbed from the DB.
248
	 */
249
	public function process_ajax_search() {
250
		$return = false;
251
252
		if(isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === 'accommodation'){
253
			$accommodation = get_transient('lsx_ti_accommodation');
254
255
			if(false === $accommodation){
256
			    $this->update_options();
257
            }
258
259
			if ( false !== $accommodation ) {
260
				$searched_items = false;
261
262 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...
263
					$keyphrases = $_POST['keyword'];
264
				}else{
265
					$keyphrases = array(0);
266
                }
267
268
				if(!is_array($keyphrases)){
269
					$keyphrases = array($keyphrases);
270
				}
271
				foreach($keyphrases as &$keyword){
272
					$keyword = ltrim(rtrim($keyword));
273
				}
274
275
276
				$post_status = false;
277
				if(in_array('publish',$keyphrases)){
278
					$post_status = 'publish';
279
				}
280
				if(in_array('pending',$keyphrases)){
281
					$post_status = 'pending';
282
				}
283
				if(in_array('draft',$keyphrases)){
284
					$post_status = 'draft';
285
				}
286
				if(in_array('import',$keyphrases)){
287
					$post_status = 'import';
288
				}
289
290
				if (!empty($accommodation)) {
291
292
					$current_accommodation = $this->find_current_accommodation();
293
294
					foreach($accommodation as $row_key => $row){
295
296
						//If this is a current tour, add its ID to the row.
297
						$row['post_id'] = 0;
298
						if(false !== $current_accommodation && array_key_exists($row['id'], $current_accommodation)){
299
							$row['post_id'] = $current_accommodation[$row['id']]->post_id;
300
						}
301
302
						//If we are searching for
303 View Code Duplication
						if(false !== $post_status){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
304
305
							if('import' === $post_status){
306
307
								if(0 !== $row['post_id']){
308
									continue;
309
								}else{
310
									$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...
311
								}
312
313
314
							}else{
315
316
								if(0 === $row['post_id']){
317
									continue;
318
								}else{
319
									$current_status = get_post_status($row['post_id']);
320
									if($current_status !== $post_status){
321
										continue;
322
									}
323
324
								}
325
								$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...
326
							}
327
328
						}else{
329
							//Search through each keyword.
330
							foreach($keyphrases as $keyphrase){
331
332
								//Make sure the keyphrase is turned into an array
333
								$keywords = explode(" ",$keyphrase);
334
								if(!is_array($keywords)){
335
									$keywords = array($keywords);
336
								}
337
338
								if($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false){
339
									$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...
340
								}
341
							}
342
						}
343
					}		
344
				}
345
346
347
				if(false !== $searched_items){
348
					ksort($searched_items);
349
					$return = implode($searched_items);
350
				}
351
			}
352
			print_r($return);
353
			die();
354
		}
355
	}
356
357
	/**
358
	 * Formats the row for output on the screen.
359
	 */	
360 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...
361
		if(false !== $row){
362
363
			$status = 'import';
364
			if(0 !== $row['post_id']){
365
				$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>';
366
			}
367
368
			$row_html = '
369
			<tr class="post-'.$row['post_id'].' type-tour" id="post-'.$row['post_id'].'">
370
				<th class="check-column" scope="row">
371
					<label for="cb-select-'.$row['id'].'" class="screen-reader-text">'.$row['name'].'</label>
372
					<input type="checkbox" data-identifier="'.$row['id'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['id'].'">
373
				</th>
374
				<td class="post-title page-title column-title">
375
					<strong>'.$row['name'].'</strong> - '.$status.'
376
				</td>
377
				<td class="date column-date">
378
					<abbr title="'.date('Y/m/d',strtotime($row['last_modified'])).'">'.date('Y/m/d',strtotime($row['last_modified'])).'</abbr><br>Last Modified
379
				</td>
380
				<td class="ssid column-ssid">
381
					'.$row['id'].'
382
				</td>
383
			</tr>';		
384
			return $row_html;
385
		}
386
	}
387
388
	/**
389
	 * Connect to wetu
390
	 */
391
	public function process_ajax_import() {
392
		$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...
393
		if(isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === 'accommodation' && isset($_POST['wetu_id'])){
394
			
395
			$wetu_id = $_POST['wetu_id'];
396
			if(isset($_POST['post_id'])){
397
				$post_id = $_POST['post_id'];	
398
			}else{
399
				$post_id = 0;
400
			}
401
402
			if(isset($_POST['team_members'])){
403
				$team_members = $_POST['team_members'];	
404
			}else{
405
				$team_members = false;
406
			}
407
408
			if(isset($_POST['safari_brands'])){
409
				$safari_brands = $_POST['safari_brands'];	
410
			}else{
411
				$safari_brands = false;
412
			}
413
414
			delete_option('wetu_importer_accommodation_settings');
415 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...
416
				$content = $_POST['content'];
417
				add_option('wetu_importer_accommodation_settings',$content);
418
			}else{
419
420
				$content = false;
421
			}
422
423
            $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
424 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...
425
            {
426
                $adata=json_decode($jdata,true);
427
                if(!empty($adata))
428
                {
429
                	$return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands);
430
                	$this->format_completed_row($return);
431
					$this->cleanup_posts();
432
                }
433
            }
434
		}
435
	}
436
437
	/**
438
	 * Connect to wetu
439
	 */
440
	public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) {
441
442
        if(trim($data[0]['type'])=='Accommodation')
443
        {
444
	        $post_name = $data_post_content = $data_post_excerpt = '';
445
	        $post = array(
446
	          'post_type'		=> 'accommodation',
447
	        );
448
449
	        $content_used_general_description = false;
450
451
	        //Set the post_content
452 View Code Duplication
	        if(false !== $importable_content && in_array('description',$importable_content)){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

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