| Conditions | 6 |
| Paths | 16 |
| Total Lines | 125 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 45 | public function createElements() |
||
| 46 | { |
||
| 47 | global $hotel_handler, $xoopsDB, $xoopsModuleConfig; |
||
| 48 | |||
| 49 | //编辑器 |
||
| 50 | include_once XOOPS_ROOT_PATH . "/modules/martin/class/xoopsformloader.php"; |
||
| 51 | include_once MARTIN_ROOT_PATH . '/include/formdatetime.php'; |
||
| 52 | |||
| 53 | $this->google_api = $xoopsModuleConfig['google_api']; |
||
| 54 | |||
| 55 | /*$this->City = $hotel_handler->GetCityList('WHERE city_parentid = 0'); |
||
| 56 | $CityElement = new XoopsFormSelect(_AM_MARTIN_HOTEL_CITY, 'hotel_city', $this->Obj->hotel_city() , 1 ); |
||
| 57 | $CityElement->addOptionArray($this->City); |
||
| 58 | $this->addElement($CityElement , true);*/ |
||
| 59 | |||
| 60 | $mytree = new XoopsTree($xoopsDB->prefix("martin_hotel_city"), "city_id", "city_parentid"); |
||
| 61 | // Parent Category |
||
| 62 | //multiple |
||
| 63 | |||
| 64 | $js = '<script type="text/javascript"> |
||
| 65 | jQuery(document).ready(function(){ |
||
| 66 | jQuery("#hotel_city").find("option").each(function(i){ |
||
| 67 | var v = jQuery(this).text(); |
||
| 68 | if(v.indexOf("----") != -1) jQuery(this).remove(); |
||
| 69 | }); |
||
| 70 | }); |
||
| 71 | </script>'; |
||
| 72 | |||
| 73 | ob_start(); |
||
| 74 | $mytree->makeMySelBox("city_name", "", $this->Obj->hotel_city(), 1, 'hotel_city'); |
||
| 75 | //makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange="") |
||
| 76 | $this->addElement(new XoopsFormLabel($js . _AM_MARTIN_ADMIN_AREA . "<br>" . _AM_MARTIN_SELECT_2ND_LEVEL, ob_get_contents())); |
||
| 77 | ob_end_clean(); |
||
| 78 | |||
| 79 | // Parent Category |
||
| 80 | //multiple |
||
| 81 | $mytree->_SetMultiple(true); |
||
| 82 | $hotel_city_id = explode(',', $this->Obj->hotel_city_id()); |
||
| 83 | |||
| 84 | ob_start(); |
||
| 85 | $mytree->makeMySelBox("city_name", '', $hotel_city_id, 1, 'hotel_city_id[]'); |
||
| 86 | //makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange=""); |
||
| 87 | $this->addElement(new XoopsFormLabel(_AM_MARTIN_CIRCLE . "<br>" . _AM_MARTIN_SELECT_3RD_LEVEL, ob_get_contents())); |
||
| 88 | ob_end_clean(); |
||
| 89 | // City Name |
||
| 90 | //$this->addElement( new XoopsFormText(_AM_MARTIN_ADMIN_CITY_AREA, 'hotel_environment', 50, 255, $this->Obj->hotel_environment()), true); |
||
| 91 | |||
| 92 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_RANK, 'hotel_rank', 11, 11, $this->Obj->hotel_rank()), true); |
||
| 93 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_NAME, 'hotel_name', 50, 255, $this->Obj->hotel_name()), true); |
||
| 94 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_NAME_ENGLISH, 'hotel_enname', 50, 255, $this->Obj->hotel_enname()), true); |
||
| 95 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_WEBSITE . "<br>" . _AM_MARTIN_NO_HTML, 'hotel_alias', 50, 255, $this->Obj->hotel_alias()), true); |
||
| 96 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_KEYWORDS_SEO, 'hotel_keywords', 50, 255, $this->Obj->hotel_keywords()), true); |
||
| 97 | $this->addElement(new XoopsFormTextArea(_AM_MARTIN_HOTEL_DESC_SEO, 'hotel_description', $this->Obj->hotel_description()), true); |
||
| 98 | //hotel tags |
||
| 99 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTELS_TAGS . "<br>" . _AM_MARTIN_USE_SPACE_AS_SEPARATOR, 'hotel_tags', 50, 255, $this->Obj->hotel_tags()), true); |
||
| 100 | |||
| 101 | //hotel star |
||
| 102 | $rankElement = new XoopsFormSelect(_AM_MARTIN_RANK, 'hotel_star', $this->Obj->hotel_star(), 1); |
||
| 103 | $rankElement->addOptionArray($this->Ranks); |
||
| 104 | $this->addElement($rankElement, true); |
||
| 105 | |||
| 106 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_ADDRESS, 'hotel_address', 50, 255, $this->Obj->hotel_address()), true); |
||
| 107 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_PHONE, 'hotel_telephone', 50, 255, $this->Obj->hotel_telephone()), true); |
||
| 108 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_FAX, 'hotel_fax', 50, 255, $this->Obj->hotel_fax()), true); |
||
| 109 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_FEATURES, 'hotel_characteristic', 50, 255, $this->Obj->hotel_characteristic()), true); |
||
| 110 | $this->addElement(new XoopsFormText(_AM_MARTIN_THE_NUMBER_OF_ROOMS, 'hotel_room_count', 11, 11, $this->Obj->hotel_room_count()), true); |
||
| 111 | $open_time = $this->Obj->hotel_open_time(); |
||
| 112 | $this->addElement(new XoopsFormText(_AM_MARTIN_HOTEL_OPENED, 'hotel_open_time', 50, 255, date('Y', $open_time > 0 ? $open_time : time())), true); |
||
| 113 | |||
| 114 | // $this->addElement( new XoopsFormText(_AM_MARTIN_HOTEL_ROOM_PHOTOS, 'hotel_image', 50, 255, $this->Obj->hotel_image()), true); |
||
| 115 | |||
| 116 | list($width, $height) = getimagesize('../images/hotelicon/' . $this->Obj->hotel_icon()); |
||
| 117 | $hotel_icon = '<script type="text/javascript"> |
||
| 118 | function showbox(src) |
||
| 119 | { |
||
| 120 | window.open(src , "_blank" , "width = \' . $width . \',height = \' . $height . \'"); |
||
| 121 | } |
||
| 122 | </script>'; |
||
| 123 | //Hotel Logo |
||
| 124 | $hotel_icon .= '<a href = "javascript:void(0);" onclick = "showbox(\'../images/hotelicon/' . $this->Obj->hotel_icon() . '\')"><img src = "../images/hotelicon/' . $this->Obj->hotel_icon() . '" width = 100 height = 100 class="showicon" ></a><br > '; |
||
| 125 | |||
| 126 | $hotelIcon = new XoopsFormElementTray(_AM_MARTIN_HOTEL_LOGO_IMAGE); |
||
| 127 | $hotelIcon->addElement(new XoopsFormFile("" . $hotel_icon, "hotel_icon", ""), false); |
||
| 128 | $this->addElement($hotelIcon, false); |
||
| 129 | |||
| 130 | //特殊处理 |
||
| 131 | //酒店地图 |
||
| 132 | $Coordinate = $this->Obj->hotel_google(); |
||
| 133 | $google = new XoopsFormElementTray(_AM_MARTIN_GOOGLE_MAP); |
||
| 134 | $google->addElement(new XoopsFormText(_AM_MARTIN_LATITTUDE, 'GmapLatitude', 25, 25, $Coordinate[0]), true); |
||
| 135 | $google->addElement(new XoopsFormText(_AM_MARTIN_LONGITUDE, 'GmapLongitude', 25, 25, $Coordinate[1]), true); |
||
| 136 | $google->addElement(new XoopsFormLabel("<br><br><font style='background - color:#2F5376;color:#FFFFFF;padding:2px;vertical-align:middle;'>google map:</font><br>", $this->googleMap($Coordinate))); |
||
| 137 | |||
| 138 | //酒店图片 |
||
| 139 | $Img = new XoopsFormElementTray(_AM_MARTIN_HOTEL_PHOTOS); |
||
| 140 | $Img->addElement(new XoopsFormLabel("", $this->Swfupload())); |
||
| 141 | |||
| 142 | $this->addElement($Img); |
||
| 143 | $this->addElement($google, true); |
||
| 144 | //特殊处理 |
||
| 145 | |||
| 146 | //编辑器 酒店详细信息 |
||
| 147 | $this->addElement(new XoopsFormTextArea(_AM_MARTIN_HOTELS_NOTES, 'hotel_reminded', $this->Obj->hotel_reminded()), true); |
||
| 148 | //hotel Facility |
||
| 149 | $this->addElement(new XoopsFormTextArea(_AM_MARTIN_FACILITIES_SERVICES, 'hotel_facility', $this->Obj->hotel_facility()), true); |
||
| 150 | |||
| 151 | $editor = 'tinymce'; |
||
| 152 | $hotel_info = $this->Obj->hotel_info(); |
||
| 153 | $editor_configs = array(); |
||
| 154 | $editor_configs["name"] = "hotel_info"; |
||
| 155 | $editor_configs["value"] = $hotel_info; |
||
| 156 | $editor_configs["rows"] = empty($xoopsModuleConfig["editor_rows"]) ? 35 : $xoopsModuleConfig["editor_rows"]; |
||
| 157 | $editor_configs["cols"] = empty($xoopsModuleConfig["editor_cols"]) ? 60 : $xoopsModuleConfig["editor_cols"]; |
||
| 158 | $editor_configs["width"] = empty($xoopsModuleConfig["editor_width"]) ? "100%" : $xoopsModuleConfig["editor_width"]; |
||
| 159 | $editor_configs["height"] = empty($xoopsModuleConfig["editor_height"]) ? "400px" : $xoopsModuleConfig["editor_height"]; |
||
| 160 | |||
| 161 | $this->addElement(new XoopsFormEditor(_AM_MARTIN_HOTEL_DETALS, $editor, $editor_configs, false, $onfailure = null), false); |
||
| 162 | //$this->addElement(new XoopsFormHidden("hotel_info", $hotel_info) , true ); |
||
| 163 | |||
| 164 | $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_HOTEL_EDIT_STATUS, 'hotel_status', $this->Obj->hotel_status(), _AM_MARTIN_PUBLISHED, _AM_MARTIN_DRAFT), true); |
||
| 165 | //$this->addElement( new MartinFormDateTime("酒店发布时间", 'hotel_open_time', $size = 15, $this->Obj->hotel_open_time() ) ,true); |
||
| 166 | |||
| 167 | $this->addElement(new XoopsFormHidden('hotel_icon_old', $this->Obj->hotel_icon())); |
||
| 168 | $this->addElement(new XoopsFormHidden('id', $this->Obj->hotel_id())); |
||
| 169 | } |
||
| 170 | |||
| 417 |
This checks looks for assignemnts to variables using the
list(...)function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$aand$care used. There was no need to assign$b.Instead, the list call could have been.