| Conditions | 6 |
| Paths | 8 |
| Total Lines | 183 |
| 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 |
||
| 50 | public function createElements() |
||
| 51 | { |
||
| 52 | //var_dump($this->Obj);exit; |
||
| 53 | //编辑器 |
||
| 54 | include_once XOOPS_ROOT_PATH . "/modules/martin/class/xoopsformloader.php"; |
||
| 55 | include_once MARTIN_ROOT_PATH . '/include/formdatetime.php'; |
||
| 56 | |||
| 57 | $Order = new XoopsFormElementTray(_AM_MARTIN_ORDER_ID); |
||
| 58 | $Order->addElement(new XoopsFormElementTray($this->Obj->order_id())); |
||
| 59 | $this->addElement($Order, false); |
||
| 60 | |||
| 61 | $order_type = new XoopsFormElementTray(_AM_MARTIN_PREDETERMINED_MANNER); |
||
| 62 | $orderIniType = $this->Obj->order_type(); |
||
| 63 | $order_type->addElement(new XoopsFormElementTray($this->OrderType[$orderIniType])); |
||
| 64 | $this->addElement($order_type, false); |
||
| 65 | |||
| 66 | $order_status = new XoopsFormElementTray(_AM_MARTIN_ORDER_STATUS); |
||
| 67 | $StatusElement = new XoopsFormSelect(_AM_MARTIN_CURRENT_CONDITION . ':' . $this->OrderStatus[$this->Obj->order_status()] . '<br>', 'order_status', $this->Obj->order_status(), 1); |
||
| 68 | $StatusElement->addOptionArray($this->OrderStatus); |
||
| 69 | $order_status->addElement($StatusElement, false); |
||
| 70 | |||
| 71 | if ($qrooms = $this->Obj->qrooms) { |
||
| 72 | $orderqrooms = '<br><br>'; |
||
| 73 | foreach ($qrooms as $room) { |
||
| 74 | $orderqrooms .= $orderqroomsPrefix . _AM_MARTIN_HOTEL_NAME . ': <a href="martin.hotel.php?action=add&id=' . $room['hotel_id'] . '">' . $room['hotel_name'] . '</a> '; |
||
|
|
|||
| 75 | $orderqrooms .= _AM_MARTIN_ROOM_COUNT . ': <a href="martin.room.php?action=add&id=' . $room['room_id'] . '">' . $room['room_name'] . '</a> '; |
||
| 76 | $orderqrooms .= _AM_MARTIN_THE_NUMBER_OF_ROOMS . ': <b>' . $room['room_count'] . '</b> '; |
||
| 77 | $orderqrooms .= _AM_MARTIN_RESERVATION_TIME . ': <b>' . date('Y-m-d', $room['room_date']) . '</b> '; |
||
| 78 | $orderqrooms .= _AM_MARTIN_PRICE_SETTING . ' : <input type="text" name="room_price[' . $room['room_id'] . '-' . $room['room_date'] . ']" value= ' . $room['room_price'] . '> '; |
||
| 79 | $orderqroomsPrefix = '<br><br>'; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | //$orderqrooms .= '<br><br><input type="button" value="'._AM_MARTIN_SAVE_PRICE.'">'; |
||
| 84 | |||
| 85 | $order_status->addElement(new XoopsFormElementTray($orderqrooms)); |
||
| 86 | |||
| 87 | $this->addElement($order_status, false); |
||
| 88 | |||
| 89 | $order_pay_method = new XoopsFormElementTray(_AM_MARTIN_PAYMENT_ORDER); |
||
| 90 | $order_pay_method->addElement(new XoopsFormElementTray($this->OrderPayMethod[$this->Obj->order_pay_method()])); |
||
| 91 | $this->addElement($order_pay_method, false); |
||
| 92 | |||
| 93 | $order_total_price = new XoopsFormElementTray(_AM_MARTIN_THE_TOTAL_AMOUNT_OF_ORDERS); |
||
| 94 | $order_total_price->addElement(new XoopsFormElementTray($this->Obj->order_total_price())); |
||
| 95 | $this->addElement($order_total_price, false); |
||
| 96 | |||
| 97 | $order_pay_money = new XoopsFormElementTray(_AM_MARTIN_THE_ACTUAL_PAYMENT_AMOUNT); |
||
| 98 | $order_pay_money->addElement(new XoopsFormElementTray($this->Obj->order_pay_money())); |
||
| 99 | $this->addElement($order_pay_money, false); |
||
| 100 | |||
| 101 | $order_coupon = new XoopsFormElementTray(_AM_MARTIN_CASH_VOLUME_PAYMENT_AMOUNT); |
||
| 102 | $order_coupon->addElement(new XoopsFormElementTray($this->Obj->order_coupon())); |
||
| 103 | $this->addElement($order_coupon, false); |
||
| 104 | |||
| 105 | $order_sented_coupon = new XoopsFormElementTray(_AM_MARTIN_GET_MONEY); |
||
| 106 | $order_sented_coupon->addElement(new XoopsFormElementTray($this->Obj->order_sented_coupon())); |
||
| 107 | $this->addElement($order_sented_coupon, false); |
||
| 108 | |||
| 109 | $order_mode = new XoopsFormElementTray(_AM_MARTIN_ORDER_MODE); |
||
| 110 | $order_mode->addElement(new XoopsFormElementTray('<a href=' . XOOPS_URL . '/userinfo.php?uid=' . $this->Obj->order_uid() . '>' . $this->Obj->uname() . '</a>')); |
||
| 111 | $this->addElement($order_mode, false); |
||
| 112 | |||
| 113 | $order_real_name = new XoopsFormElementTray(_AM_MARTIN_ACTUAL_NAME); |
||
| 114 | $order_real_name->addElement(new XoopsFormElementTray($this->Obj->order_real_name())); |
||
| 115 | $this->addElement($order_real_name, false); |
||
| 116 | |||
| 117 | $order_document_type = new XoopsFormElementTray(_AM_MARTIN_CERTIFICATION_TYPE); |
||
| 118 | $order_document_type->addElement(new XoopsFormElementTray($this->OrderDocumentType[$this->Obj->order_document_type()])); |
||
| 119 | $this->addElement($order_document_type, false); |
||
| 120 | |||
| 121 | $order_document = new XoopsFormElementTray(_AM_MARTIN_CREDENTIALS); |
||
| 122 | $order_document->addElement(new XoopsFormElementTray($this->Obj->order_document())); |
||
| 123 | $this->addElement($order_document, false); |
||
| 124 | |||
| 125 | $order_phone = new XoopsFormElementTray(_AM_MARTIN_PHONE); |
||
| 126 | $order_phone->addElement(new XoopsFormElementTray($this->Obj->order_phone())); |
||
| 127 | $this->addElement($order_phone, false); |
||
| 128 | |||
| 129 | $order_telephone = new XoopsFormElementTray(_AM_MARTIN_PHONE); |
||
| 130 | $order_telephone->addElement(new XoopsFormElementTray($this->Obj->order_telephone())); |
||
| 131 | $this->addElement($order_telephone, false); |
||
| 132 | |||
| 133 | $extraPersons = $this->Obj->order_extra_persons(); |
||
| 134 | if (is_array($extraPersons)) { |
||
| 135 | var_dump($extraPersons); |
||
| 136 | } |
||
| 137 | $order_extra_persons = new XoopsFormElementTray(_AM_MARTIN_INCIDENTAL_PERSONNEL_INFORMATION); |
||
| 138 | $order_extra_persons->addElement(new XoopsFormElementTray($$extraPersons)); |
||
| 139 | $this->addElement($order_extra_persons, false); |
||
| 140 | |||
| 141 | $order_note = new XoopsFormElementTray(_AM_MARTIN_ORDER_NOTES); |
||
| 142 | $order_note->addElement(new XoopsFormElementTray($this->Obj->order_note())); |
||
| 143 | $this->addElement($order_note, false); |
||
| 144 | |||
| 145 | $order_status_time = new XoopsFormElementTray(_AM_MARTIN_ORDERS_LAST_MODIFIED); |
||
| 146 | $order_status_time->addElement(new XoopsFormElementTray(date('Y-m-d H:i:s', $this->Obj->order_status_time()))); |
||
| 147 | $this->addElement($order_status_time, false); |
||
| 148 | |||
| 149 | $order_submit_time = new XoopsFormElementTray(_AM_MARTIN_ORDER_SUBMISSION_TIME); |
||
| 150 | $order_submit_time->addElement(new XoopsFormElementTray(date('Y-m-d H:i;s', $this->Obj->order_submit_time()))); |
||
| 151 | $this->addElement($order_submit_time, false); |
||
| 152 | |||
| 153 | $orderrooms = ''; |
||
| 154 | if ($rooms = $this->Obj->rooms) { |
||
| 155 | foreach ($rooms as $room) { |
||
| 156 | $orderrooms .= $orderroomsPrefix . _AM_MARTIN_HOTEL_NAME . ': <a href="martin.hotel.php?action=add&id=' . $room['hotel_id'] . '">' . $room['hotel_name'] . '</a> '; |
||
| 157 | $orderrooms .= _AM_MARTIN_ROOM_COUNT . ': <a href="martin.room.php?action=add&id=' . $room['room_id'] . '">' . $room['room_name'] . '</a> '; |
||
| 158 | $orderrooms .= _AM_MARTIN_THE_NUMBER_OF_ROOMS . ': <b>' . $room['room_count'] . '</b> '; |
||
| 159 | $orderrooms .= _AM_MARTIN_RESERVATION_TIME . ': <b>' . date('Y-m-d', $room['room_date']) . '</b> '; |
||
| 160 | $orderrooms .= _AM_MARTIN_PRICE . ': <b>' . $room['room_price'] . '</b> '; |
||
| 161 | $orderroomsPrefix = '<br>'; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | $order_rooms = new XoopsFormElementTray(_AM_MARTIN_ORDER_ROOM_INFORMATION); |
||
| 165 | $order_rooms->addElement(new XoopsFormElementTray($orderrooms)); |
||
| 166 | $this->addElement($order_rooms, false); |
||
| 167 | |||
| 168 | /*$this->addElement( new XoopsFormText('酒店排序', 'hotel_rank', 11, 11, $this->Obj->hotel_rank()), true); |
||
| 169 | |||
| 170 | $this->addElement( new XoopsFormText(_AM_MARTIN_HOTEL_NAME, 'hotel_name', 50, 255, $this->Obj->hotel_name()), true); |
||
| 171 | |||
| 172 | $this->addElement( new XoopsFormText('酒店英文名称', 'hotel_enname', 50, 255, $this->Obj->hotel_enname()), true); |
||
| 173 | |||
| 174 | $this->addElement( new XoopsFormText('酒店别名', 'hotel_alias', 50, 255, $this->Obj->hotel_alias()), true); |
||
| 175 | |||
| 176 | $this->addElement( new XoopsFormText(_AM_MARTIN_HOTEL_KEYWORDS_SEO, 'hotel_keywords', 50, 255, $this->Obj->hotel_keywords()), true); |
||
| 177 | |||
| 178 | $this->addElement( new XoopsFormTextArea(_AM_MARTIN_HOTEL_DESC_SEO, 'hotel_description', $this->Obj->hotel_description()) , true); |
||
| 179 | |||
| 180 | //hotel star |
||
| 181 | $rankElement = new XoopsFormSelect(_AM_MARTIN_HOTEL_STARS, 'hotel_star', $this->Obj->hotel_star() , 1 ); |
||
| 182 | $rankElement->addOptionArray($this->Ranks); |
||
| 183 | $this->addElement($rankElement , true); |
||
| 184 | |||
| 185 | $this->addElement( new XoopsFormText('酒店地址', 'hotel_address', 50, 255, $this->Obj->hotel_address()), true); |
||
| 186 | |||
| 187 | $this->addElement( new XoopsFormText('酒店电话', 'hotel_telephone', 50, 255, $this->Obj->hotel_telephone()), true); |
||
| 188 | |||
| 189 | $this->addElement( new XoopsFormText('酒店 FAX', 'hotel_fax', 50, 255, $this->Obj->hotel_fax()), true); |
||
| 190 | |||
| 191 | $this->addElement( new XoopsFormText('酒店特色', 'hotel_characteristic', 50, 255, $this->Obj->hotel_characteristic()), true); |
||
| 192 | |||
| 193 | $this->addElement( new XoopsFormText('酒店房间数', 'hotel_room_count', 11, 11, $this->Obj->hotel_room_count()), true); |
||
| 194 | |||
| 195 | //$this->addElement( new XoopsFormText(_AM_MARTIN_HOTEL_ROOM_PHOTOS, 'hotel_image', 50, 255, $this->Obj->hotel_image()), true); |
||
| 196 | |||
| 197 | //特殊处理 |
||
| 198 | //酒店地图 |
||
| 199 | $Coordinate = $this->Obj->hotel_google(); |
||
| 200 | $google = new XoopsFormElementTray('google 地图'); |
||
| 201 | $google->addElement(new XoopsFormText('纬度', 'GmapLatitude', 25, 25, $Coordinate[0]), true); |
||
| 202 | $google->addElement(new XoopsFormText('经度', 'GmapLongitude', 25, 25, $Coordinate[1]), true); |
||
| 203 | $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) )); |
||
| 204 | |||
| 205 | //酒店图片 |
||
| 206 | $Img = new XoopsFormElementTray('酒店图片'); |
||
| 207 | $Img->addElement(new XoopsFormLabel("", $this->Swfupload() )); |
||
| 208 | |||
| 209 | $this->addElement($Img); |
||
| 210 | $this->addElement($google , true); |
||
| 211 | //特殊处理 |
||
| 212 | |||
| 213 | //编辑器 酒店详细信息 |
||
| 214 | $this->addElement( new XoopsFormTextArea('酒店特别提醒', 'hotel_reminded', $this->Obj->hotel_reminded()) , true); |
||
| 215 | $editor = 'tinymce'; |
||
| 216 | $hotel_info = $this->Obj->hotel_info(); |
||
| 217 | $editor_configs = array(); |
||
| 218 | $editor_configs["name"] ="hotel_info"; |
||
| 219 | $editor_configs["value"] = $hotel_info; |
||
| 220 | $editor_configs["rows"] = empty($xoopsModuleConfig["editor_rows"])? 35 : $xoopsModuleConfig["editor_rows"]; |
||
| 221 | $editor_configs["cols"] = empty($xoopsModuleConfig["editor_cols"])? 60 : $xoopsModuleConfig["editor_cols"]; |
||
| 222 | $editor_configs["width"] = empty($xoopsModuleConfig["editor_width"])? "100%" : $xoopsModuleConfig["editor_width"]; |
||
| 223 | $editor_configs["height"] = empty($xoopsModuleConfig["editor_height"])? "400px" : $xoopsModuleConfig["editor_height"]; |
||
| 224 | |||
| 225 | $this->addElement(new XoopsFormEditor("酒店详细信息", $editor, $editor_configs, false, $onfailure = null) , false); |
||
| 226 | //$this->addElement(new XoopsFormHidden("hotel_info", $hotel_info) , true ); |
||
| 227 | |||
| 228 | $this->addElement( new XoopsFormRadioYN("酒店编辑状态", 'hotel_status', $this->Obj->hotel_status(), _AM_MARTIN_PUBLISHED, _AM_MARTIN_DRAFT) , true); |
||
| 229 | $this->addElement( new MartinFormDateTime("酒店发布时间", 'hotel_open_time', $size = 15, $this->Obj->hotel_open_time() ) ,true);*/ |
||
| 230 | |||
| 231 | $this->addElement(new XoopsFormHidden('id', $this->Obj->order_id())); |
||
| 232 | } |
||
| 233 | |||
| 298 |
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:
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
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: