Conditions | 6 |
Paths | 32 |
Total Lines | 74 |
Code Lines | 35 |
Lines | 3 |
Ratio | 4.05 % |
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 | //include_once MARTIN_ROOT_PATH . '/include/formdatetime.php'; |
||
48 | include_once XOOPS_ROOT_PATH . "/modules/martin/class/xoopsformloader.php"; |
||
49 | include_once MARTIN_ROOT_PATH . '/include/formdatetime.php'; |
||
50 | |||
51 | $RoomStr = ''; |
||
52 | View Code Duplication | foreach ($this->RoomList as $room) { |
|
53 | $RoomStr .= "<br><input type=checkbox name=room_id[] value={$room['room_id']} id=room_{$room['room_id']} checked=\"checked\" click=\"RoomRemove(this)\"> <label for=room_{$room['room_id']}>{$room['room_name']}</label> "._AM_MARTIN_NUMBER_OF_ROOMS.":<input type=text name=\"room_count_{$room['room_id']}\" value={$room['room_count']}>"; |
||
54 | } |
||
55 | $js = '<script type=\'text/javascript\'> |
||
56 | jQuery.noConflict(); |
||
57 | jQuery(document).ready(function($){ |
||
58 | $("#hotel_id").click(function(){ |
||
59 | var hotel_id = Number($(this).val()); |
||
60 | $.post("martin.ajax.php?action=getroomlist",{hotel_id:hotel_id},function(data){ |
||
61 | $("#room").html(data); |
||
62 | }); |
||
63 | }); |
||
64 | }); |
||
65 | function roomSelect(event) |
||
66 | { |
||
67 | var room_id = Number(jQuery("#ajaxroom").val()); |
||
68 | var room_name = jQuery.trim(jQuery("#ajaxroom option:selected").text()); |
||
69 | var roomExist = document.getElementById("room_"+room_id); |
||
70 | if(roomExist) return false; |
||
71 | if(room_id > 0) |
||
72 | { |
||
73 | var Str = "<br><input type=checkbox name=room_id[] value="+room_id+" id=room_"+room_id+" checked=\"checked\" click=\"RoomRemove(this)\"> "+"<label for=room_"+room_id+">" + room_name + "</label>"; |
||
74 | var inputStr = " "._AM_MARTIN_NUMBER_OF_ROOMS.":<input type=text name=\"room_count_"+room_id+"\" value=1>"; |
||
75 | jQuery("#rooms").append(Str + inputStr); |
||
76 | } |
||
77 | } |
||
78 | </script>'; |
||
79 | $Room = new XoopsFormElementTray($js . _AM_MARTIN_SELECT_ROOMS . '<br>' . _AM_MARTIN_FILTER_BY_HOTEL); |
||
80 | $RoomElement = new XoopsFormSelect('', 'hotel_id', $this->HotelList, 5, false); |
||
81 | $RoomElement->addOptionArray($this->HotelList); |
||
82 | //$RoomElement->addOption('class','hotel'); |
||
83 | $Room->addElement($RoomElement, false); |
||
84 | $Room->addElement(new XoopsFormElementTray('<br><br><div id="room"></div><div id="rooms">' . $RoomStr . '</div>'), false); |
||
85 | |||
86 | $this->addElement($Room, false); |
||
87 | |||
88 | $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_CHECK_IN, 'check_in_date', $size = 15, $this->Obj->check_in_date(), false), true); |
||
89 | |||
90 | $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_LAUNCH_TIME, 'check_out_date', $size = 15, $this->Obj->check_out_date(), false), true); |
||
91 | |||
92 | //$this->addElement( new XoopsFormTextDateSelect(_AM_MARTIN_START_BID_TIME, 'apply_start_date', $size = 15, $this->Obj->apply_start_date(),false ) ,true); |
||
93 | $this->addElement(new MartinFormDateTime(_AM_MARTIN_START_BID_TIME, 'apply_start_date', $size = 15, $this->Obj->apply_start_date()), true); |
||
94 | //$this->addElement( new XoopsFormTextDateSelect(_AM_MARTIN_END_TIME_BIDDING, 'apply_end_date', $size = 15, $this->Obj->apply_end_date() ) ,true); |
||
95 | $this->addElement(new MartinFormDateTime(_AM_MARTIN_END_TIME_BIDDING, 'apply_end_date', $size = 15, $this->Obj->apply_end_date()), true); |
||
96 | |||
97 | $this->addElement(new XoopsFormText(_AM_MARTIN_STARTING_PRICE, 'auction_price', 11, 11, $this->Obj->auction_price()), true); |
||
98 | $this->addElement(new XoopsFormText(_AM_MARTIN_CHEAP, 'auction_low_price', 11, 11, $this->Obj->auction_low_price()), true); |
||
99 | $this->addElement(new XoopsFormText(_AM_MARTIN_PRICE_MARKUP, 'auction_add_price', 11, 11, $this->Obj->auction_add_price()), true); |
||
100 | $this->addElement(new XoopsFormText(_AM_MARTIN_GIFT_VOUCHER . '?', 'auction_sented_coupon', 11, 11, (int)($this->Obj->auction_sented_coupon())), true); |
||
101 | $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_CAN_YOU_USE_CASH_VOLUME, 'auction_can_use_coupon', $this->Obj->auction_can_use_coupon(), _YES, _NO), true); |
||
102 | $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_STATUS, 'auction_status', $this->Obj->auction_status(), _AM_MARTIN_PUBLISHED, _AM_MARTIN_DRAFT), true); |
||
103 | |||
104 | $this->addElement(new XoopsFormText(_AM_MARTIN_TITLE, 'auction_name', 50, 255, $this->Obj->auction_name()), true); |
||
105 | $editor = 'tinymce'; |
||
106 | $auction_info = $this->Obj->auction_info(); |
||
107 | //var_dump($auction_info); |
||
108 | $editor_configs = array(); |
||
109 | $editor_configs["name"] = "auction_info"; |
||
110 | $editor_configs["value"] = $auction_info; |
||
111 | $editor_configs["rows"] = empty($xoopsModuleConfig["editor_rows"]) ? 35 : $xoopsModuleConfig["editor_rows"]; |
||
112 | $editor_configs["cols"] = empty($xoopsModuleConfig["editor_cols"]) ? 60 : $xoopsModuleConfig["editor_cols"]; |
||
113 | $editor_configs["width"] = empty($xoopsModuleConfig["editor_width"]) ? "100%" : $xoopsModuleConfig["editor_width"]; |
||
114 | $editor_configs["height"] = empty($xoopsModuleConfig["editor_height"]) ? "400px" : $xoopsModuleConfig["editor_height"]; |
||
115 | |||
116 | $this->addElement(new XoopsFormEditor(_AM_MARTIN_AUCTION_DETAILS, $editor, $editor_configs, false, $onfailure = null), false); |
||
117 | $this->addElement(new XoopsFormHidden('id', $this->Obj->auction_id())); |
||
118 | } |
||
119 | |||
161 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.