Conditions | 52 |
Paths | > 20000 |
Total Lines | 161 |
Code Lines | 100 |
Lines | 0 |
Ratio | 0 % |
Tests | 50 |
CRAP Score | 52 |
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 |
||
63 | 1 | function display(){ |
|
64 | 1 | global $popupMeta, $mod_strings; |
|
65 | |||
66 | 1 | if(($this->bean instanceOf SugarBean) && !$this->bean->ACLAccess('list')){ |
|
67 | ACLController::displayNoAccess(); |
||
68 | sugar_cleanup(true); |
||
69 | } |
||
70 | |||
71 | 1 | if(isset($_REQUEST['metadata']) && strpos($_REQUEST['metadata'], "..") !== false) |
|
72 | die("Directory navigation attack denied."); |
||
73 | 1 | if (!empty($_REQUEST['metadata']) && $_REQUEST['metadata'] != 'undefined' |
|
74 | 1 | && file_exists('custom/modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) { |
|
75 | require 'custom/modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php'; |
||
76 | 1 | } elseif (!empty($_REQUEST['metadata']) && $_REQUEST['metadata'] != 'undefined' |
|
77 | 1 | && file_exists('modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) { |
|
78 | require 'modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php'; |
||
79 | 1 | } elseif (file_exists('custom/modules/' . $this->module . '/metadata/popupdefs.php')) { |
|
80 | require 'custom/modules/' . $this->module . '/metadata/popupdefs.php'; |
||
81 | 1 | } elseif (file_exists('modules/' . $this->module . '/metadata/popupdefs.php')) { |
|
82 | 1 | require 'modules/' . $this->module . '/metadata/popupdefs.php'; |
|
83 | } |
||
84 | |||
85 | 1 | if(!empty($popupMeta) && !empty($popupMeta['listviewdefs'])){ |
|
86 | 1 | if(is_array($popupMeta['listviewdefs'])){ |
|
87 | //if we have an array, then we are not going to include a file, but rather the |
||
88 | //listviewdefs will be defined directly in the popupdefs file |
||
89 | 1 | $listViewDefs[$this->module] = $popupMeta['listviewdefs']; |
|
90 | }else{ |
||
91 | //otherwise include the file |
||
92 | 1 | require_once($popupMeta['listviewdefs']); |
|
93 | } |
||
94 | }elseif(file_exists('custom/modules/' . $this->module . '/metadata/listviewdefs.php')){ |
||
95 | require_once('custom/modules/' . $this->module . '/metadata/listviewdefs.php'); |
||
96 | }elseif(file_exists('modules/' . $this->module . '/metadata/listviewdefs.php')){ |
||
97 | require_once('modules/' . $this->module . '/metadata/listviewdefs.php'); |
||
98 | } |
||
99 | |||
100 | //check for searchdefs as well |
||
101 | 1 | if(!empty($popupMeta) && !empty($popupMeta['searchdefs'])){ |
|
102 | 1 | if(is_array($popupMeta['searchdefs'])){ |
|
103 | //if we have an array, then we are not going to include a file, but rather the |
||
104 | //searchdefs will be defined directly in the popupdefs file |
||
105 | 1 | $searchdefs[$this->module]['layout']['advanced_search'] = $popupMeta['searchdefs']; |
|
106 | }else{ |
||
107 | //otherwise include the file |
||
108 | 1 | require_once($popupMeta['searchdefs']); |
|
109 | } |
||
110 | }else if(empty($searchdefs) && file_exists('custom/modules/'.$this->module.'/metadata/searchdefs.php')){ |
||
|
|||
111 | require_once('custom/modules/'.$this->module.'/metadata/searchdefs.php'); |
||
112 | }else if(empty($searchdefs) && file_exists('modules/'.$this->module.'/metadata/searchdefs.php')){ |
||
113 | require_once('modules/'.$this->module.'/metadata/searchdefs.php'); |
||
114 | } |
||
115 | |||
116 | //if you click the pagination button, it will populate the search criteria here |
||
117 | 1 | if(!empty($this->bean) && isset($_REQUEST[$this->module.'2_'.strtoupper($this->bean->object_name).'_offset'])) { |
|
118 | if(!empty($_REQUEST['current_query_by_page'])) { |
||
119 | $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', |
||
120 | 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page'); |
||
121 | $current_query_by_page = sugar_unserialize(base64_decode($_REQUEST['current_query_by_page'])); |
||
122 | foreach($current_query_by_page as $search_key=>$search_value) { |
||
123 | if($search_key != $this->module.'2_'.strtoupper($this->bean->object_name).'_offset' |
||
124 | && !in_array($search_key, $blockVariables)) { |
||
125 | if (!is_array($search_value)) { |
||
126 | $_REQUEST[$search_key] = securexss($search_value); |
||
127 | } |
||
128 | else { |
||
129 | foreach ($search_value as $key=>&$val) { |
||
130 | $val = securexss($val); |
||
131 | } |
||
132 | $_REQUEST[$search_key] = $search_value; |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | |||
139 | 1 | if(!empty($listViewDefs) && !empty($searchdefs)){ |
|
140 | 1 | require_once('include/Popups/PopupSmarty.php'); |
|
141 | 1 | $displayColumns = array(); |
|
142 | 1 | $filter_fields = array(); |
|
143 | 1 | $popup = new PopupSmarty($this->bean, $this->module); |
|
144 | 1 | foreach($listViewDefs[$this->module] as $col => $params) { |
|
145 | 1 | $filter_fields[strtolower($col)] = true; |
|
146 | 1 | if(!empty($params['related_fields'])) { |
|
147 | foreach($params['related_fields'] as $field) { |
||
148 | //id column is added by query construction function. This addition creates duplicates |
||
149 | //and causes issues in oracle. #10165 |
||
150 | if ($field != 'id') { |
||
151 | $filter_fields[$field] = true; |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | 1 | if(!empty($params['default']) && $params['default']) |
|
156 | 1 | $displayColumns[$col] = $params; |
|
157 | } |
||
158 | 1 | $popup->displayColumns = $displayColumns; |
|
159 | 1 | $popup->filter_fields = $filter_fields; |
|
160 | 1 | $popup->mergeDisplayColumns = true; |
|
161 | //check to see if popupdefs contains searchdefs |
||
162 | 1 | $popup->_popupMeta = $popupMeta; |
|
163 | 1 | $popup->listviewdefs = $listViewDefs; |
|
164 | 1 | $popup->searchdefs = $searchdefs; |
|
165 | |||
166 | 1 | if(isset($_REQUEST['query'])){ |
|
167 | $popup->searchForm->populateFromRequest(); |
||
168 | } |
||
169 | |||
170 | 1 | $massUpdateData = ''; |
|
171 | 1 | if(isset($_REQUEST['mass'])) { |
|
172 | foreach(array_unique($_REQUEST['mass']) as $record) { |
||
173 | $massUpdateData .= "<input style='display: none' checked type='checkbox' name='mass[]' value='$record'>\n"; |
||
174 | } |
||
175 | } |
||
176 | 1 | $popup->massUpdateData = $massUpdateData; |
|
177 | |||
178 | 1 | $tpl = 'include/Popups/tpls/PopupGeneric.tpl'; |
|
179 | 1 | if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl"))) |
|
180 | { |
||
181 | $tpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl"); |
||
182 | } |
||
183 | |||
184 | 1 | if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl"))) |
|
185 | { |
||
186 | $popup->headerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl"); |
||
187 | } |
||
188 | |||
189 | 1 | if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl"))) |
|
190 | { |
||
191 | $popup->footerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl"); |
||
192 | } |
||
193 | |||
194 | 1 | $popup->setup($tpl); |
|
195 | |||
196 | //We should at this point show the header and javascript even if to_pdf is true. |
||
197 | //The insert_popup_header javascript is incomplete and shouldn't be relied on. |
||
198 | 1 | if (isset($this->options['show_all']) && $this->options['show_all'] == false) |
|
199 | { |
||
200 | unset($this->options['show_all']); |
||
201 | $this->options['show_javascript'] = true; |
||
202 | $this->options['show_header'] = true; |
||
203 | $this->_displayJavascript(); |
||
204 | } |
||
205 | 1 | insert_popup_header(null, false); |
|
206 | 1 | if(isset($this->override_popup['template_data']) && is_array($this->override_popup['template_data'])) |
|
207 | { |
||
208 | $popup->th->ss->assign($this->override_popup['template_data']); |
||
209 | } |
||
210 | 1 | echo $popup->display(); |
|
211 | |||
212 | }else{ |
||
213 | if(file_exists('modules/' . $this->module . '/Popup_picker.php')){ |
||
214 | require_once('modules/' . $this->module . '/Popup_picker.php'); |
||
215 | }else{ |
||
216 | require_once('include/Popups/Popup_picker.php'); |
||
217 | } |
||
218 | |||
219 | $popup = new Popup_Picker(); |
||
220 | $popup->_hide_clear_button = true; |
||
221 | echo $popup->process_page(); |
||
222 | } |
||
223 | 1 | } |
|
224 | } |
||
226 |
This check looks for calls to
isset(...)
orempty()
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.