| Conditions | 17 |
| Paths | > 20000 |
| Total Lines | 49 |
| Lines | 13 |
| Ratio | 26.53 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 74 | public function Search($Data) |
||
| 75 | { |
||
| 76 | global $hotel_handler, $xoopsModuleConfig; |
||
| 77 | //var_dump($xoopsModuleConfig); |
||
| 78 | |||
| 79 | $rows = array(); |
||
| 80 | $dateTime = strtotime(date('Y-m-d')); |
||
| 81 | foreach ($Data as $key => $value) { |
||
| 82 | ${$key} = $value; |
||
| 83 | } |
||
| 84 | $city_ids = $this->GetCityIds($hotel_address); |
||
| 85 | //var_dump($Data); |
||
| 86 | $sql = "SELECT h.*,hc.city_name as hotel_city FROM " . $this->db->prefix("martin_hotel") . " h "; |
||
| 87 | $sql .= "INNER JOIN " . $this->db->prefix("martin_room") . " r ON (h.hotel_id = r.hotel_id) "; |
||
| 88 | $sql .= "INNER JOIN " . $this->db->prefix("martin_room_price") . " rp ON (r.room_id = rp.room_id) "; |
||
| 89 | $sql .= "INNER JOIN " . $this->db->prefix("martin_hotel_city") . " hc ON (h.hotel_city = hc.city_id) "; |
||
| 90 | $sql .= " WHERE 1 = 1 "; |
||
| 91 | $sql .= (empty($hotel_address) || empty($hotel_ids)) ? "" : $city_ids . " IN h.hotel_city_id "; |
||
| 92 | $sql .= empty($hotel_name) ? "" : "AND h.hotel_name LIKE '%$hotel_name%' "; |
||
| 93 | $sql .= $city_id > 0 ? "AND h.hotel_city IN (SELECT city_id FROM " . $this->db->prefix("martin_hotel_city") . " WHERE city_parentid = $city_id ) " : ""; |
||
| 94 | $sql .= $hotel_star > 0 ? "AND h.hotel_star = $hotel_star " : ""; |
||
| 95 | $sql .= (is_array($price) && $price[0] > 0 && $price[1] > 0) ? "AND rp.room_price >= {$price[0]} AND rp.room_price <= {$price[1]} " : ""; |
||
| 96 | $sql .= (is_array($check_date) && $check_date[0] > 0 && $check_date[1] > 0) ? "AND rp.room_date >= {$check_date[0]} AND rp.room_date <= {$check_date[1]} " : ""; |
||
| 97 | $sql .= "GROUP BY h.hotel_id "; |
||
| 98 | $sql .= (empty($order) || empty($by)) ? " ORDER BY h.hotel_rank DESC , h.hotel_id DESC " : " ORDER BY $order $by ,h.hotel_rank DESC "; |
||
| 99 | $rows['count'] = $this->GetCount(str_replace("h.*", "count(h.hotel_id) as count", $sql)); |
||
| 100 | $sql .= "LIMIT $start,{$xoopsModuleConfig['perpage']}"; |
||
| 101 | //echo $sql; |
||
| 102 | |||
| 103 | $result = $this->db->query($sql); |
||
| 104 | $this->hotel_ids = &$hotel_ids; |
||
| 105 | $cityList = &$hotel_handler->getCityList(); |
||
| 106 | View Code Duplication | while ($row = $this->db->fetchArray($result)) { |
|
| 107 | $hotel_ids[] = $row['hotel_id']; |
||
| 108 | $city_ids = explode(',', $row['hotel_city_id']); |
||
| 109 | foreach ($city_ids as $id) { |
||
| 110 | $city_name[] = $cityList[$id]; |
||
| 111 | } |
||
| 112 | $row['city_name'] = implode('、', $city_name); |
||
| 113 | $row['hotel_image'] = unserialize($row['hotel_image']); |
||
| 114 | $row['hotel_google'] = unserialize(unserialize($row['hotel_google'])); |
||
| 115 | //var_dump($row['hotel_google']); |
||
| 116 | $rows[] = $row; |
||
| 117 | unset($city_name); |
||
| 118 | } |
||
| 119 | |||
| 120 | //$rows = $this->GetRows($sql,'hotel_id'); |
||
| 121 | return $rows; |
||
| 122 | } |
||
| 123 | |||
| 233 |
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.