Issues (663)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

class/hotel.php (52 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * $Id: hotel.php,v 1.42 2007/02/04 15:01:40 malanciault Exp $
4
 * Module:martin
5
 * Licence: GNU
6
 */
7
8
if (!defined("XOOPS_ROOT_PATH")) {
9
    die("XOOPS root path not defined");
10
}
11
12
include_once XOOPS_ROOT_PATH . '/modules/martin/include/common.php';
13
14
/**
15
 * Class MartinHotel
16
 */
17
class MartinHotel extends XoopsObject
18
{
19
    public function MartinHotel()
20
    {
21
        $this->initVar("hotel_id", XOBJ_DTYPE_INT, null, false);
22
        //$this->initVar("hotel_city_id", XOBJ_DTYPE_INT, null, false);
23
        $this->initVar("hotel_city", XOBJ_DTYPE_TXTBOX, null, true, 255);
24
        $this->initVar("hotel_city_id", XOBJ_DTYPE_TXTBOX, null, true, 255);
25
        $this->initVar("hotel_environment", XOBJ_DTYPE_TXTBOX, null, false, 255);
26
        $this->initVar("hotel_rank", XOBJ_DTYPE_INT, null, false);
27
        $this->initVar("hotel_name", XOBJ_DTYPE_TXTBOX, null, true, 255);
28
        $this->initVar("hotel_enname", XOBJ_DTYPE_TXTBOX, null, true, 255);
29
        $this->initVar("hotel_alias", XOBJ_DTYPE_TXTBOX, null, true, 255);
30
        $this->initVar("hotel_keywords", XOBJ_DTYPE_TXTBOX, null, true, 255);
31
        $this->initVar("hotel_tags", XOBJ_DTYPE_TXTBOX, null, true, 255);
32
        $this->initVar("hotel_description", XOBJ_DTYPE_TXTBOX, null, true, 255);
33
        $this->initVar("hotel_star", XOBJ_DTYPE_INT, null, false);
34
        $this->initVar("hotel_address", XOBJ_DTYPE_TXTBOX, null, true, 255);
35
        $this->initVar("hotel_telephone", XOBJ_DTYPE_TXTBOX, null, true, 45);
36
        $this->initVar("hotel_fax", XOBJ_DTYPE_TXTBOX, null, true, 45);
37
        $this->initVar("hotel_room_count", XOBJ_DTYPE_INT, null, false);
38
        $this->initVar("hotel_icon", XOBJ_DTYPE_TXTBOX, null, true, 255);
39
        $this->initVar("hotel_image", XOBJ_DTYPE_ARRAY, '', true, 1000);
40
        $this->initVar("hotel_google", XOBJ_DTYPE_ARRAY, '', true, 255);
41
        $this->initVar("hotel_characteristic", XOBJ_DTYPE_TXTBOX, null, true, 255);
42
        $this->initVar("hotel_reminded", XOBJ_DTYPE_TXTBOX, null, true, 1000);
43
        $this->initVar("hotel_facility", XOBJ_DTYPE_TXTBOX, null, true, 1000);
44
        $this->initVar("hotel_info", XOBJ_DTYPE_TXTAREA, null, false);
45
        $this->initVar("hotel_status", XOBJ_DTYPE_INT, null, false);
46
        $this->initVar("hotel_open_time", XOBJ_DTYPE_INT, null, false);
47
        $this->initVar("hotel_add_time", XOBJ_DTYPE_INT, null, false);
48
    }
49
50
    /**
51
     * @return mixed
52
     */
53
    public function hotel_id()
54
    {
55
        return $this->getVar("hotel_id");
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61
    public function hotel_city()
62
    {
63
        return $this->getVar("hotel_city");
64
    }
65
66
    /*function hotel_city_id()
67
    {
68
        return $this->getVar("hotel_city_id");
69
    }*/
70
71
    /**
72
     * @param string $format
73
     * @return mixed
74
     */
75
    public function hotel_city_id($format = 'S')
76
    {
77
        return $this->getVar("hotel_city_id", $format);
78
    }
79
80
    /**
81
     * @param string $format
82
     * @return mixed
83
     */
84
    public function hotel_environment($format = 'S')
85
    {
86
        return $this->getVar("hotel_environment", $format);
87
    }
88
89
    /**
90
     * @return mixed
91
     */
92
    public function hotel_rank()
93
    {
94
        return $this->getVar("hotel_rank");
95
    }
96
97
    /**
98
     * @param string $format
99
     * @return mixed
100
     */
101
    public function hotel_city_name($format = 'S')
102
    {
103
        return $this->getVar("hotel_city_name", $format);
104
    }
105
106
    /**
107
     * @param string $format
108
     * @return mixed
109
     */
110
    public function hotel_name($format = 'S')
111
    {
112
        return $this->getVar("hotel_name", $format);
113
    }
114
115
    /**
116
     * @param string $format
117
     * @return mixed
118
     */
119
    public function hotel_enname($format = 'S')
120
    {
121
        return $this->getVar("hotel_enname", $format);
122
    }
123
124
    /**
125
     * @param string $format
126
     * @return mixed
127
     */
128
    public function hotel_alias($format = 'S')
129
    {
130
        return $this->getVar("hotel_alias", $format);
131
    }
132
133
    /**
134
     * @param string $format
135
     * @return mixed
136
     */
137
    public function hotel_keywords($format = 'S')
138
    {
139
        return $this->getVar("hotel_keywords", $format);
140
    }
141
142
    /**
143
     * @param string $format
144
     * @return mixed
145
     */
146
    public function hotel_tags($format = 'S')
147
    {
148
        return $this->getVar("hotel_tags", $format);
149
    }
150
151
    /**
152
     * @param string $format
153
     * @return mixed
154
     */
155
    public function hotel_description($format = 'S')
156
    {
157
        return $this->getVar("hotel_description", $format);
158
    }
159
160
    /**
161
     * @return mixed
162
     */
163
    public function hotel_star()
164
    {
165
        return $this->getVar("hotel_star");
166
    }
167
168
    /**
169
     * @param string $format
170
     * @return mixed
171
     */
172
    public function hotel_address($format = 'S')
173
    {
174
        return $this->getVar("hotel_address", $format);
175
    }
176
177
    /**
178
     * @param string $format
179
     * @return mixed
180
     */
181
    public function hotel_telephone($format = 'S')
182
    {
183
        return $this->getVar("hotel_telephone", $format);
184
    }
185
186
    /**
187
     * @param string $format
188
     * @return mixed
189
     */
190
    public function hotel_fax($format = 'S')
191
    {
192
        return $this->getVar("hotel_fax", $format);
193
    }
194
195
    /**
196
     * @return mixed
197
     */
198
    public function hotel_room_count()
199
    {
200
        return $this->getVar("hotel_room_count");
201
    }
202
203
    /**
204
     * @param string $format
205
     * @return mixed
206
     */
207
    public function hotel_icon($format = 'S')
208
    {
209
        return ($this->getVar("hotel_icon", $format));
210
    }
211
212
    /**
213
     * @param string $format
214
     * @return mixed
215
     */
216
    public function hotel_image($format = 'S')
217
    {
218
        return unserialize($this->getVar("hotel_image", $format));
219
    }
220
221
    /**
222
     * @param string $format
223
     * @return mixed
224
     */
225
    public function hotel_google($format = 'S')
226
    {
227
        return unserialize($this->getVar("hotel_google", $format));
228
    }
229
230
    /**
231
     * @param string $format
232
     * @return mixed
233
     */
234
    public function hotel_characteristic($format = 'S')
235
    {
236
        return $this->getVar("hotel_characteristic", $format);
237
    }
238
239
    /**
240
     * @param string $format
241
     * @return mixed
242
     */
243
    public function hotel_reminded($format = 'S')
244
    {
245
        return $this->getVar("hotel_reminded", $format);
246
    }
247
248
    /**
249
     * @param string $format
250
     * @return mixed
251
     */
252
    public function hotel_facility($format = 'S')
253
    {
254
        return $this->getVar("hotel_facility", $format);
255
    }
256
257
    /**
258
     * @param string $format
259
     * @return mixed
260
     */
261
    public function hotel_info($format = 'edit')
262
    {
263
        return $this->getVar("hotel_info", $format);
264
    }
265
266
    /**
267
     * @return mixed
268
     */
269
    public function hotel_status()
270
    {
271
        return $this->getVar("hotel_status");
272
    }
273
274
    /**
275
     * @return mixed
276
     */
277
    public function hotel_open_time()
278
    {
279
        return $this->getVar("hotel_open_time");
280
    }
281
282
    /**
283
     * @return mixed
284
     */
285
    public function hotel_add_time()
286
    {
287
        return $this->getVar("hotel_add_time");
288
    }
289
}
290
291
/**
292
 * @method: HotelCityHandler
293
 * @license   http://www.blags.org/
294
 * @created   :2010年05月21日 20时40分
295
 * @copyright 1997-2010 The Martin Group
296
 * @author    Martin <[email protected]>
297
 * */
298
class MartinHotelHandler extends XoopsObjectHandler
299
{
300
    /**
301
     * create a new hotel city
302
     * @param bool $isNew flag the new objects as "new"?
303
     * @return object Hotel
304
     */
305
    public function &create($isNew = true)
306
    {
307
        $hotel = new MartinHotel();
308
        if ($isNew) {
309
            $hotel->setNew();
310
        }
311
312
        return $hotel;
313
    }
314
315
    /**
316
     * retrieve a hotel city
317
     *
318
     * @param int $id hotelcityid of the hotel
319
     * @return mixed reference to the {@link Hotel} object, FALSE if failed
320
     */
321
    public function &get($id)
322
    {
323
        if ((int)($id) <= 0) {
324
            return false;
325
        }
326
327
        $criteria = new CriteriaCompo(new Criteria('hotel_id', $id));
328
        $criteria->setLimit(1);
329
        $obj_array = $this->getObjects($criteria);
330
        if (count($obj_array) != 1) {
331
            $obj =& $this->create();
332
333
            return $obj;
334
        }
335
        $cityList   = &self::getCityList();
336
        $hotel_city = $obj_array[0]->hotel_city();
337
        $obj_array[0]->setVar('hotel_city', $cityList[$hotel_city]);
338
        $city_ids = explode(',', $obj_array[0]->hotel_city_id());
339
        foreach ($city_ids as $id) {
340
            $city_name[] = $cityList[$id];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$city_name was never initialized. Although not strictly required by PHP, it is generally a good practice to add $city_name = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
341
        }
342
        $obj_array[0]->city_name = implode(',', $city_name);
0 ignored issues
show
The variable $city_name 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...
343
344
        return $obj_array[0];
345
    }
346
347
    /**
348
     * @get       rows
349
     * @license   http://www.blags.org/
350
     * @created   :2010年06月20日 13时09分
351
     * @copyright 1997-2010 The Martin Group
352
     * @author    Martin <[email protected]>
353
     * @param      $sql
354
     * @param null $key
355
     * @return array
356
     */
357 View Code Duplication
    public function GetRows($sql, $key = null)
0 ignored issues
show
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...
358
    {
359
        global $xoopsDB;
360
        $result = $xoopsDB->query($sql);
361
        $rows   = array();
362
        while ($row = $xoopsDB->fetchArray($result)) {
363
            if (is_null($key)) {
364
                $rows[] = $row;
365
            } else {
366
                $rows[$row[$key]] = $row;
367
            }
368
        }
369
370
        return $rows;
371
    }
372
373
    /**
374
     * @得到列表
375
     * @method:
376
     * @license   http://www.blags.org/
377
     * @created   :2010年05月23日 14时59分
378
     * @copyright 1997-2010 The Martin Group
379
     * @author    Martin <[email protected]>
380
     * @param int    $limit
381
     * @param int    $start
382
     * @param int    $city_parentid
383
     * @param string $sort
384
     * @param string $order
385
     * @param bool   $id_as_key
386
     * @return array
387
     */
388 View Code Duplication
    public function &getHotels($limit = 0, $start = 0, $city_parentid = 0, $sort = 'hotel_id', $order = 'ASC', $id_as_key = true)
0 ignored issues
show
This method seems to be duplicated in your project.

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

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

Loading history...
389
    {
390
        $criteria = new CriteriaCompo();
391
392
        $criteria->setSort($sort);
393
        $criteria->setOrder($order);
394
395
        $criteria->setStart($start);
396
        $criteria->setLimit($limit);
397
398
        return $this->getObjects($criteria, $id_as_key);
399
    }
400
401
    /**
402
     * insert a new hotel in the database
403
     *
404
     * @param object $hotel reference to the {@link Hotel} object
405
     * $city_ids = explode(',',$row['hotel_city_id']);
406
     * foreach($city_ids as $id)
407
     * {
408
     * $city_name[] = $cityList[$id];
409
     * }
410
     * @param bool   $force
411
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
412
     */
413
    public function insert(&$hotel, $force = false)
414
    {
415
        if (strtolower(get_class($hotel)) !== 'martinhotel') {
416
            return false;
417
        }
418
419
        if (!$hotel->cleanVars()) {
420
            return false;
421
        }
422
423
        foreach ($hotel->cleanVars as $k => $v) {
424
            ${$k} = $v;
425
        }
426
        //echo $hotel_room_count;exit;
427
428
        if ($hotel->isNew()) {
429
            $sql = sprintf("INSERT INTO %s (
430
                                hotel_id,hotel_city,hotel_city_id , hotel_environment,hotel_rank,hotel_name, hotel_enname,hotel_alias,
431
                                hotel_keywords,hotel_tags,
432
                                hotel_description,    hotel_star,    hotel_address,    hotel_telephone,hotel_fax,hotel_room_count,
433
                                hotel_icon,hotel_image,hotel_google,hotel_characteristic,
434
                                hotel_reminded, hotel_facility ,hotel_info,    hotel_status,
435
                                hotel_open_time,hotel_add_time
436
                            ) VALUES (
437
                                NULL,%u,%s,%s,%u,    %s,    %s,    %s,    %s,    %s , %s , %u , %s , %s,    %s,
438
                                %u,    %s, %s , %s, %s, %s, %s , %s, %u, %u, %u
439
                            )", $this->db->prefix('martin_hotel'), //$hotel_city_id,
440
                           $hotel_city, $this->db->quoteString($hotel_city_id), $this->db->quoteString($hotel_environment), $hotel_rank, $this->db->quoteString($hotel_name), $this->db->quoteString($hotel_enname), $this->db->quoteString($hotel_alias), $this->db->quoteString($hotel_keywords), $this->db->quoteString($hotel_tags), $this->db->quoteString($hotel_description), $hotel_star, $this->db->quoteString($hotel_address), $this->db->quoteString($hotel_telephone), $this->db->quoteString($hotel_fax), $hotel_room_count, $this->db->quoteString($hotel_icon), $this->db->quoteString($hotel_image), $this->db->quoteString($hotel_google), $this->db->quoteString($hotel_characteristic), $this->db->quoteString($hotel_reminded), $this->db->quoteString($hotel_facility), $this->db->quoteString($hotel_info), $hotel_status, $hotel_open_time, $hotel_add_time);
0 ignored issues
show
The variable $hotel_city does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_city_id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_environment does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_rank does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_name does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_enname does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_alias does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_keywords does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_tags does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_description does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_star does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_address does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_telephone does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_fax does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_room_count does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_icon does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_image does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_google does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_characteristic does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_reminded does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_facility does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_info does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_status does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_open_time does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $hotel_add_time does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
441
            //echo $sql;exit;
442
        } else {
443
            $sql = sprintf("UPDATE %s SET hotel_city = %u,
444
                                hotel_city_id = %s,hotel_environment=%s,hotel_rank = %u,hotel_name = %s, hotel_enname = %s,hotel_alias = %s,
445
                                hotel_keywords = %s,hotel_tags = %s,hotel_description = %s,    hotel_star = %u,hotel_address = %s,
446
                                hotel_telephone = %s,
447
                                hotel_fax = %s,hotel_room_count = %u,hotel_icon = %s ,hotel_image = %s,hotel_google = %s,
448
                                hotel_characteristic = %s,hotel_reminded = %s, hotel_facility = %s , hotel_info = %s,    hotel_status = %u,
449
                                hotel_open_time = %u,hotel_add_time = %u
450
                            WHERE hotel_id = %u", $this->db->prefix('martin_hotel'), //$hotel_city_id,
451
                           $hotel_city, $this->db->quoteString($hotel_city_id), $this->db->quoteString($hotel_environment), $hotel_rank, $this->db->quoteString($hotel_name), $this->db->quoteString($hotel_enname), $this->db->quoteString($hotel_alias), $this->db->quoteString($hotel_keywords), $this->db->quoteString($hotel_tags), $this->db->quoteString($hotel_description), $hotel_star, $this->db->quoteString($hotel_address), $this->db->quoteString($hotel_telephone), $this->db->quoteString($hotel_fax), $hotel_room_count, $this->db->quoteString($hotel_icon), $this->db->quoteString($hotel_image), $this->db->quoteString($hotel_google), $this->db->quoteString($hotel_characteristic), $this->db->quoteString($hotel_reminded), $this->db->quoteString($hotel_facility), $this->db->quoteString($hotel_info), $hotel_status, $hotel_open_time, $hotel_add_time, $hotel_id);
0 ignored issues
show
The variable $hotel_id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
452
        }
453
        //echo $sql;exit;
454
        //echo "<br />" . $sql . "<br />";exit;
455
        if (false != $force) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
456
            $result = $this->db->queryF($sql);
457
        } else {
458
            $result = $this->db->query($sql);
459
        }
460
        if (!$result) {
461
            $hotel->setErrors('The query returned an error. ' . $this->db->error());
462
463
            return false;
464
        }
465
        if ($hotel->isNew()) {
466
            $hotel->assignVar('hotel_id', $this->db->getInsertId());
467
        }
468
469
        $hotel->assignVar('hotel_id', $hotel_id);
470
471
        return true;
472
    }
473
474
    /**
475
     * @删除一个酒店
476
     * @method:delete(city_id)
477
     * @license   http://www.blags.org/
478
     * @created   :2010年05月21日 20时40分
479
     * @copyright 1997-2010 The Martin Group
480
     * @author    Martin <[email protected]>
481
     * @param object $hotel
482
     * @param bool   $force
483
     * @return bool|void
484
     */
485
    public function delete(&$hotel, $force = false)
486
    {
487
        if (strtolower(get_class($hotel)) !== 'martinhotel') {
488
            return false;
489
        }
490
        /**
491
         * delete relations
492
         **/
493
        //delete images 
494
        $HotelImages = $hotel->hotel_image();
495
        if (!empty($HotelImages) && is_array($HotelImages)) {
496
            foreach ($HotelImages as $HotelImage) {
497
                $file = MARTIN_HOTEL_IMAGE_PATH . $HotelImage['filename'];
498
                if (file_exists($file) && is_writable($file)) {
499
                    unlink($file);
500
                }
501
            }
502
        }
503
        //delete icon
504
        $full_icon_img = MARTIN_ROOT_PATH . 'images/hotelicon/' . $hotel->hotel_icon();
505
        if (file_exists($full_icon_img) && is_writable($full_icon_img)) {
506
            unlink($full_icon_img);
507
        }
508
509
        //delete tags
510
        self::deleteTags($hotel);
511
512
        //delete room group
513
        $sql = "DELETE FROM " . $this->db->prefix("martin_group_room") . " WHERE room_id IN (
514
            SELECT room_id FROM " . $this->db->prefix("martin_room") . " WHERE hotel_id = " . $hotel->hotel_id() . ' ) ';
515
        $this->db->queryF($sql);
516
        //delete room group
517
        $sql = "DELETE FROM " . $this->db->prefix("martin_auction_room") . " WHERE room_id IN (
518
            SELECT room_id FROM " . $this->db->prefix("martin_room") . " WHERE hotel_id = " . $hotel->hotel_id() . ' ) ';
519
        $this->db->queryF($sql);
520
        //delete group prices
521
        $sql = "DELETE FROM " . $this->db->prefix("martin_room_price") . " WHERE room_id IN (
522
            SELECT room_id FROM " . $this->db->prefix("martin_room") . " WHERE hotel_id = " . $hotel->hotel_id() . ' ) ';
523
        $this->db->queryF($sql);
524
        //delete rooms
525
        $sql = "DELETE FROM " . $this->db->prefix("martin_room") . " WHERE hotel_id = " . $hotel->hotel_id();
526
        $this->db->queryF($sql);
527
        //delete hotel promotions
528
        $sql = "DELETE FROM " . $this->db->prefix("martin_hotel_promotions") . " WHERE hotel_id = " . $hotel->hotel_id();
529
        $this->db->queryF($sql);
530
531
        $sql = "DELETE FROM " . $this->db->prefix("martin_hotel") . " WHERE hotel_id = " . $hotel->hotel_id();
532
        if (false != $force) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
533
            $result = $this->db->queryF($sql);
534
        } else {
535
            $result = $this->db->query($sql);
536
        }
537
538
        if (!$result) {
539
            return false;
540
        }
541
542
        return true;
543
    }
544
545
    /**
546
     * delete hotel cities matching a set of conditions
547
     *
548
     * @param object $criteria {@link CriteriaElement}
0 ignored issues
show
Should the type for parameter $criteria not be object|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
549
     * @return bool FALSE if deletion failed
550
     */
551 View Code Duplication
    public function deleteAll($criteria = null)
0 ignored issues
show
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...
552
    {
553
        $sql = 'DELETE FROM ' . $this->db->prefix('martin_hotel');
554
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
555
            $sql .= ' ' . $criteria->renderWhere();
556
        }
557
        if (!$result = $this->db->query($sql)) {
558
            return false;
559
        }
560
561
        return true;
562
    }
563
564
    /**
565
     * count hotel cities matching a condition
566
     *
567
     * @param $searchData
568
     * @return int count of categories
569
     * @internal param object $criteria <a href='psi_element://CriteriaElement'>CriteriaElement</a> to match to match
570
     */
571
    public function getCount($searchData)
572
    {
573 View Code Duplication
        if (!empty($searchData) && is_array($searchData)) {
0 ignored issues
show
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...
574
            $where = 'where 1 = 1 ';
575
            //$where .= !empty($searchData['hotel_city_id']) ? " and h.hotel_city_id = {$searchData['hotel_city_id']} " : " ";
576
            $where .= !empty($searchData['hotel_city_id']) ? " and h.hotel_city_id LIKE  '%{$searchData['hotel_city_id']}%' " : " ";
577
            $where .= !empty($searchData['hotel_star']) ? " and h.hotel_star = {$searchData['hotel_star']} " : " ";
578
            $where .= !empty($searchData['hotel_name']) ? " and h.hotel_name like '%{$searchData['hotel_name']}%' " : " ";
579
        }
580
        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('martin_hotel') . " h $where";
0 ignored issues
show
The variable $where 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...
581
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
0 ignored issues
show
The variable $criteria seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
582
            $sql .= ' ' . $criteria->renderWhere();
583
        }
584
        //echo $sql;
585
        $result = $this->db->query($sql);
586
        if (!$result) {
587
            return 0;
588
        }
589
        list($count) = $this->db->fetchRow($result);
590
591
        return $count;
592
    }
593
594
    /**
595
     * @得到城市
596
     * @license   http://www.blags.org/
597
     * @created   :2010年05月21日 20时40分
598
     * @copyright 1997-2010 The Martin Group
599
     * @author    Martin <[email protected]>
600
     * @param null $criteria
601
     * @param bool $id_as_key
602
     * @return array
603
     */
604 View Code Duplication
    public function &getObjects($criteria = null, $id_as_key = false)
0 ignored issues
show
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...
605
    {
606
        $ret   = array();
607
        $limit = $start = 0;
608
        $sql   = 'SELECT * FROM ' . $this->db->prefix('martin_hotel');
609
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
610
            $sql .= ' ' . $criteria->renderWhere();
611
            if ($criteria->getSort() != '') {
612
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
613
            }
614
            $limit = $criteria->getLimit();
615
            $start = $criteria->getStart();
616
        }
617
        //echo "<br />" . $sql . "<br />";
618
        $result = $this->db->query($sql, $limit, $start);
619
620
        if (!$result) {
621
            return $ret;
622
        }
623
624
        $theObjects = array();
625
626
        while ($myrow = $this->db->fetchArray($result)) {
627
            $hotel = new MartinHotel();
628
            $hotel->assignVars($myrow);
629
            $theObjects[$myrow['hotel_id']] =& $hotel;
630
            //var_dump($hotel);
631
            unset($hotel);
632
        }
633
        //var_dump($theObjects);
634
635
        foreach ($theObjects as $theObject) {
636
            if (!$id_as_key) {
637
                $ret[] =& $theObject;
638
            } else {
639
                $ret[$theObject->hotel_id()] =& $theObject;
640
            }
641
            unset($theObject);
642
        }
643
644
        return $ret;
645
    }
646
647
    /**
648
     * @得到酒店列表
649
     * @license   http://www.blags.org/
650
     * @created   :2010年05月29日 11时31分
651
     * @copyright 1997-2010 The Martin Group
652
     * @author    Martin <[email protected]>
653
     * @param        $searchData
654
     * @param int    $limit
655
     * @param int    $start
656
     * @param string $sort
657
     * @return array
658
     */
659
    public function getHotelList($searchData, $limit = 0, $start = 0, $sort = 'hotel_id')
660
    {
661 View Code Duplication
        if (!empty($searchData) && is_array($searchData)) {
0 ignored issues
show
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...
662
            $where = 'where 1 = 1 ';
663
            //$where .= !empty($searchData['hotel_city_id']) ? " and h.hotel_city_id = {$searchData['hotel_city_id']} " : " ";
664
            $where .= !empty($searchData['hotel_city_id']) ? " and h.hotel_city_id LIKE '%{$searchData['hotel_city_id']}%' " : " ";
665
            $where .= !empty($searchData['hotel_star']) ? " and h.hotel_star = {$searchData['hotel_star']} " : " ";
666
            $where .= !empty($searchData['hotel_name']) ? " and h.hotel_name like '%{$searchData['hotel_name']}%' " : " ";
667
        }
668
        $sql = "SELECT h.* FROM " . $this->db->prefix("martin_hotel") . " h ";
669
        //left join ".$this->db->prefix("martin_hotel_city")." hc ON (hc.city_id IN ( h.hotel_city_id ) )
670
        //$sql .=    "$where    Group BY h.hotel_id order BY h.hotel_rank ,h.hotel_id DESC ";
671
        $sql .= "$where     order BY h.hotel_rank ,h.hotel_id DESC ";
0 ignored issues
show
The variable $where 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...
672
        $query    = $this->db->query($sql, $limit, $start);
673
        $cityList = &self::getCityList();
674 View Code Duplication
        while ($row = $this->db->fetchArray($query)) {
0 ignored issues
show
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...
675
            $city_ids = explode(',', $row['hotel_city_id']);
676
            foreach ($city_ids as $id) {
677
                $city_name[] = $cityList[$id];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$city_name was never initialized. Although not strictly required by PHP, it is generally a good practice to add $city_name = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
678
            }
679
            $hotel_ids[]            = $row['hotel_id'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$hotel_ids was never initialized. Although not strictly required by PHP, it is generally a good practice to add $hotel_ids = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
680
            $row['city_name']       = implode('、', $city_name);
0 ignored issues
show
The variable $city_name 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...
681
            $row['hotel_open_time'] = date('Y-m-d H:i:s', $row['hotel_open_time']);
682
            $row['hotel_add_time']  = date('Y-m-d H:i:s', $row['hotel_add_time']);
683
            $nrows[]                = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$nrows was never initialized. Although not strictly required by PHP, it is generally a good practice to add $nrows = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
684
            unset($row, $city_name);
685
        }
686
        $this->hotel_ids = &$hotel_ids;
0 ignored issues
show
The variable $hotel_ids 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...
687
688
        //echo '<pre>';print_r($nrows);
689
        return $nrows;
0 ignored issues
show
The variable $nrows 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...
690
    }
691
692
    /**
693
     * get hotel rooms
694
     * @access    public
695
     * @return void
696
     * @copyright 1997-2010 The Martin Group
697
     * @author    Martin <[email protected]>
698
     * @created   time :2010-06-25 15:27:34
699
     * */
700
    public function GethotelRooms()
701
    {
702
        if (empty($this->hotel_ids)) {
703
            return $this->hotel_ids;
704
        }
705
        $sql    = "SELECT r.*,rt.room_type_info FROM " . $this->db->prefix("martin_room") . " r INNER JOIN " . $this->db->prefix("martin_room_type") . " rt ON (r.room_type_id = rt.room_type_id)
706
            WHERE r.hotel_id IN (" . implode(",", $this->hotel_ids) . ") ";
707
        $rows   = array();
708
        $result = $this->db->query($sql);
709
        while ($row = $this->db->fetchArray($result)) {
710
            $rows[$row['hotel_id']][] = $row;
711
        }
712
713
        return $rows;
714
    }
715
716
    /**
717
     * @get       city list
718
     * @method:
719
     * @license   http://www.blags.org/
720
     * @created   :2010年06月18日 21时37分
721
     * @copyright 1997-2010 The Martin Group
722
     * @author    Martin <[email protected]>
723
     * @param null $WHERE
724
     * @return array
725
     */
726
    public function getCityList($WHERE = null)
727
    {
728
        $sql = 'SELECT * FROM ' . $this->db->prefix('martin_hotel_city');
729
        $sql .= !is_null($WHERE) ? ' ' . $WHERE . ' ' : '';
730
        $result = $this->db->query($sql);
731
        $rows   = array();
732
        while ($row = $this->db->fetchArray($result)) {
733
            $rows[$row['city_id']] = $row['city_name'];
734
        }
735
736
        return $rows;
737
    }
738
739
    /**
740
     * @method:save rank
741
     * @license   http://www.blags.org/
742
     * @created   :2010年05月29日 19时25分
743
     * @copyright 1997-2010 The Martin Group
744
     * @author    Martin <[email protected]>
745
     * @param $RankData
746
     * @return bool
747
     */
748
    public function saveRank($RankData)
749
    {
750
        if (!empty($RankData) && is_array($RankData)) {
751
            $result = true;
752
            foreach ($RankData as $hotel_id => $hotel_rank) {
753
                $sql = "UPDATE " . $this->db->prefix("martin_hotel") . " set hotel_rank = " . (int)($hotel_rank) . "
754
                    WHERE hotel_id = " . $hotel_id;
755
                if (!$this->db->query($sql)) {
756
                    $result = false;
757
                }
758
            }
759
760
            return $result;
761
        }
762
763
        return false;
764
    }
765
766
    /**
767
     * @检测是否存在
768
     * @license   http://www.blags.org/
769
     * @created   :2010年05月28日 21时02分
770
     * @copyright 1997-2010 The Martin Group
771
     * @author    Martin <[email protected]>
772
     * @param $id
773
     * @return bool
774
     */
775
    public function CheckExist($id)
776
    {
777
        $sql = "SELECT * FROM " . $this->db->prefix("martin_hotel") . " WHERE hotel_id = " . $id;
778
779
        return is_array($this->db->fetchArray($this->db->query($sql)));
780
    }
781
782
    /**
783
     * @
784
     * @method:
785
     * @license   http://www.blags.org/
786
     * @created   :2010年06月14日 20时47分
787
     * @copyright 1997-2010 The Martin Group
788
     * @author    Martin <[email protected]>
789
     * @param $hotel_alias
790
     * @param $hotel_id
791
     * @return bool
792
     */
793
    public function CheckAliasExist($hotel_alias, $hotel_id)
794
    {
795
        if (empty($hotel_alias)) {
796
            return false;
797
        }
798
        $sql = "SELECT count(*) FROM " . $this->db->prefix("martin_hotel") . " WHERE hotel_alias = '" . $hotel_alias . "'";
799
        list($exist) = $this->db->fetchRow($this->db->query($sql));
800
        if ($hotel_id > 0 && $exist > 1) {
801
            return true;
802
        }
803
        if ($hotel_id > 0 && $exist == 1) {
804
            return false;
805
        }
806
807
        return $exist;
808
    }
809
810
    /**
811
     * tag action
812
     * Update hotel tag links of the hotel
813
     *
814
     * @param $hotel
815
     * @return bool true on success
816
     */
817 View Code Duplication
    public function updateTags(&$hotel)
0 ignored issues
show
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...
818
    {
819
        if ($tag_handler = @xoops_getmodulehandler("tag", "tag", true)) {
820
            $tag_handler->updateByItem($hotel->getVar('hotel_tags'), $hotel->getVar('hotel_id'), MARTIN_DIRNAME);
821
        }
822
823
        return true;
824
    }
825
826
    /**
827
     * Delete hotel tags links of the article from database
828
     *
829
     * @param $hotel
830
     * @return bool true on success
831
     */
832 View Code Duplication
    public function deleteTags(&$hotel)
0 ignored issues
show
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...
833
    {
834
        if ($tag_handler = @xoops_getmodulehandler("tag", "tag", true)) {
835
            $tag_handler->updateByItem(array(), $hotel->getVar('hotel_id'), MARTIN_DIRNAME);
836
        }
837
838
        return true;
839
    }
840
841
    /**
842
     * @get       rank hotel count
843
     * @license   http://www.blags.org/
844
     * @created   :2010年06月20日 13时09分
845
     * @copyright 1997-2010 The Martin Group
846
     * @author    Martin <[email protected]>
847
     * */
848
    public function getHotelRankCount()
849
    {
850
        global $xoopsDB;
851
        $sql    = 'SELECT hotel_star ,count(hotel_id) as count FROM ' . $xoopsDB->prefix('martin_hotel') . ' GROUP BY hotel_star ORDER BY hotel_star  ';
852
        $result = $xoopsDB->query($sql);
853
        $rows   = array();
854
        while ($row = $xoopsDB->fetchArray($result)) {
855
            $rows[$row['hotel_star']] = $row['count'];
856
        }
857
858
        return $rows;
859
    }
860
861
    /**
862
     * @get       viewed hotels
863
     * @license   http://www.blags.org/
864
     * @created   :2010年06月20日 13时09分
865
     * @copyright 1997-2010 The Martin Group
866
     * @author    Martin <[email protected]>
867
     * @param     $hotel_ids
868
     * @param int $limit
869
     * @return array
870
     */
871
    public function GetViewedHotels($hotel_ids, $limit = 10)
872
    {
873
        global $xoopsDB;
874
        if (empty($hotel_ids) || !is_array($hotel_ids)) {
875
            return $hotel_ids;
876
        }
877
        $sql        = 'SELECT hotel_id,hotel_alias,hotel_name FROM ' . $xoopsDB->prefix('martin_hotel') . ' WHERE hotel_id IN (' . implode(',', $hotel_ids) . ') LIMIT ' . $limit;
878
        $rows       = $this->GetRows($sql, 'hotel_id');
879
        $viewedRows = array();
880
        foreach ($hotel_ids as $hotel_id) {
881
            $viewedRows[] = $rows[$hotel_id];
882
        }
883
884
        return $viewedRows;
885
    }
886
}
887