Conditions | 27 |
Paths | > 20000 |
Total Lines | 154 |
Code Lines | 94 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 756 |
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 |
||
91 | function display() { |
||
92 | global $current_user, $app_list_strings; |
||
93 | |||
94 | |||
95 | //lets set the return values |
||
96 | if(isset($_REQUEST['return_module'])){ |
||
97 | $this->ss->assign('RETURN_MODULE',$_REQUEST['return_module']); |
||
98 | } |
||
99 | |||
100 | $this->ss->assign('IS_ADMIN', $current_user->is_admin ? true : false); |
||
101 | |||
102 | //make sure we can populate user type dropdown. This usually gets populated in predisplay unless this is a quickeditform |
||
103 | if(!isset($this->fieldHelper)){ |
||
104 | $this->fieldHelper = new UserViewHelper($this->ss, $this->bean, 'EditView'); |
||
105 | $this->fieldHelper->setupAdditionalFields(); |
||
106 | } |
||
107 | |||
108 | if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') { |
||
109 | $this->ss->assign('RETURN_MODULE', $_REQUEST['return_module']); |
||
110 | $this->ss->assign('RETURN_ACTION', $_REQUEST['return_action']); |
||
111 | $this->ss->assign('RETURN_ID', $_REQUEST['record']); |
||
112 | $this->bean->id = ""; |
||
113 | $this->bean->user_name = ""; |
||
114 | $this->ss->assign('ID',''); |
||
115 | } else { |
||
116 | if(isset($_REQUEST['return_module'])) |
||
117 | { |
||
118 | $this->ss->assign('RETURN_MODULE', $_REQUEST['return_module']); |
||
119 | } else { |
||
120 | $this->ss->assign('RETURN_MODULE', $this->bean->module_dir); |
||
121 | } |
||
122 | |||
123 | $return_id = isset($_REQUEST['return_id'])?$_REQUEST['return_id']:$this->bean->id; |
||
124 | if (isset($return_id)) { |
||
125 | $return_action = isset($_REQUEST['return_action'])?$_REQUEST['return_action']:'DetailView'; |
||
126 | $this->ss->assign('RETURN_ID', $return_id); |
||
127 | $this->ss->assign('RETURN_ACTION', $return_action); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | |||
132 | /////////////////////////////////////////////////////////////////////////////// |
||
133 | //// REDIRECTS FROM COMPOSE EMAIL SCREEN |
||
134 | if(isset($_REQUEST['type']) && (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Emails')) { |
||
135 | $this->ss->assign('REDIRECT_EMAILS_TYPE', $_REQUEST['type']); |
||
136 | } |
||
137 | //// END REDIRECTS FROM COMPOSE EMAIL SCREEN |
||
138 | /////////////////////////////////////////////////////////////////////////////// |
||
139 | |||
140 | /////////////////////////////////////////////////////////////////////////////// |
||
141 | //// NEW USER CREATION ONLY |
||
142 | if(empty($this->bean->id)) { |
||
143 | $this->ss->assign('SHOW_ADMIN_CHECKBOX','height="30"'); |
||
144 | $this->ss->assign('NEW_USER','1'); |
||
145 | }else{ |
||
146 | $this->ss->assign('NEW_USER','0'); |
||
147 | $this->ss->assign('NEW_USER_TYPE','DISABLED'); |
||
148 | } |
||
149 | |||
150 | //// END NEW USER CREATION ONLY |
||
151 | /////////////////////////////////////////////////////////////////////////////// |
||
152 | |||
153 | |||
154 | // FIXME: Translate error prefix |
||
155 | if(isset($_REQUEST['error_string'])) $this->ss->assign('ERROR_STRING', '<span class="error">Error: '.$_REQUEST['error_string'].'</span>'); |
||
156 | if(isset($_REQUEST['error_password'])) $this->ss->assign('ERROR_PASSWORD', '<span id="error_pwd" class="error">Error: '.$_REQUEST['error_password'].'</span>'); |
||
157 | |||
158 | |||
159 | |||
160 | |||
161 | // Build viewable versions of a few fields for non-admins |
||
162 | if(!empty($this->bean->id)) { |
||
163 | if( !empty($this->bean->status) ) { |
||
164 | $this->ss->assign('STATUS_READONLY',$app_list_strings['user_status_dom'][$this->bean->status]); } |
||
165 | if( !empty($this->bean->employee_status) ) { |
||
166 | $this->ss->assign('EMPLOYEE_STATUS_READONLY', $app_list_strings['employee_status_dom'][$this->bean->employee_status]); |
||
167 | } |
||
168 | if( !empty($this->bean->reports_to_id) ) { |
||
169 | $reportsToUser = get_assigned_user_name($this->bean->reports_to_id); |
||
170 | $reportsToUserField = "<input type='text' name='reports_to_name' id='reports_to_name' value='{$reportsToUser}' disabled>\n"; |
||
171 | $reportsToUserField .= "<input type='hidden' name='reports_to_id' id='reports_to_id' value='{$this->bean->reports_to_id}'>"; |
||
172 | $this->ss->assign('REPORTS_TO_READONLY', $reportsToUserField); |
||
173 | } |
||
174 | if( !empty($this->bean->title) ) { |
||
175 | $this->ss->assign('TITLE_READONLY', $this->bean->title); |
||
176 | } |
||
177 | if( !empty($this->bean->department) ) { |
||
178 | $this->ss->assign('DEPT_READONLY', $this->bean->department); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | $processSpecial = false; |
||
183 | $processFormName = ''; |
||
184 | if ( isset($this->fieldHelper->usertype) && ($this->fieldHelper->usertype == 'GROUP' |
||
185 | )) { |
||
186 | $this->ev->formName = 'EditViewGroup'; |
||
187 | |||
188 | $processSpecial = true; |
||
189 | $processFormName = 'EditViewGroup'; |
||
190 | } |
||
191 | |||
192 | //Bug#51609 Replace {php} code block in EditViewHeader.tpl |
||
193 | $action_button = array(); |
||
194 | $APP = $this->ss->get_template_vars('APP'); |
||
195 | $PWDSETTINGS = $this->ss->get_template_vars('PWDSETTINGS'); |
||
196 | $REGEX = $this->ss->get_template_vars('REGEX'); |
||
197 | $CHOOSER_SCRIPT = $this->ss->get_template_vars('CHOOSER_SCRIPT'); |
||
198 | $REASSIGN_JS = $this->ss->get_template_vars('REASSIGN_JS'); |
||
199 | $RETURN_ACTION = $this->ss->get_template_vars('RETURN_ACTION'); |
||
200 | $RETURN_MODULE = $this->ss->get_template_vars('RETURN_MODULE'); |
||
201 | $RETURN_ID = $this->ss->get_template_vars('RETURN_ID'); |
||
202 | |||
203 | $minpwdlength = !empty($PWDSETTINGS['minpwdlength']) ? $PWDSETTINGS['minpwdlength'] : ''; |
||
204 | $maxpwdlength = !empty($PWDSETTINGS['maxpwdlength']) ? $PWDSETTINGS['maxpwdlength'] : ''; |
||
205 | $action_button_header[] = <<<EOD |
||
206 | <input type="button" id="SAVE_HEADER" title="{$APP['LBL_SAVE_BUTTON_TITLE']}" accessKey="{$APP['LBL_SAVE_BUTTON_KEY']}" |
||
207 | class="button primary" onclick="var _form = $('#EditView')[0]; if (!set_password(_form,newrules('{$minpwdlength}','{$maxpwdlength}','{$REGEX}'))) return false; if (!Admin_check()) return false; _form.action.value='Save'; {$CHOOSER_SCRIPT} {$REASSIGN_JS} if(verify_data(EditView)) _form.submit();" |
||
208 | name="button" value="{$APP['LBL_SAVE_BUTTON_LABEL']}"> |
||
209 | EOD |
||
210 | ; |
||
211 | $action_button_header[] = <<<EOD |
||
212 | <input title="{$APP['LBL_CANCEL_BUTTON_TITLE']}" id="CANCEL_HEADER" accessKey="{$APP['LBL_CANCEL_BUTTON_KEY']}" |
||
213 | class="button" onclick="var _form = $('#EditView')[0]; _form.action.value='{$RETURN_ACTION}'; _form.module.value='{$RETURN_MODULE}'; _form.record.value='{$RETURN_ID}'; _form.submit()" |
||
214 | type="button" name="button" value="{$APP['LBL_CANCEL_BUTTON_LABEL']}"> |
||
215 | EOD |
||
216 | ; |
||
217 | $action_button_header = array_merge($action_button_header, $this->ss->get_template_vars('BUTTONS_HEADER')); |
||
218 | $this->ss->assign('ACTION_BUTTON_HEADER', $action_button_header); |
||
219 | |||
220 | $action_button_footer[] = <<<EOD |
||
221 | <input type="button" id="SAVE_FOOTER" title="{$APP['LBL_SAVE_BUTTON_TITLE']}" accessKey="{$APP['LBL_SAVE_BUTTON_KEY']}" |
||
222 | class="button primary" onclick="var _form = $('#EditView')[0]; if (!set_password(_form,newrules('{$minpwdlength}','{$maxpwdlength}','{$REGEX}'))) return false; if (!Admin_check()) return false; _form.action.value='Save'; {$CHOOSER_SCRIPT} {$REASSIGN_JS} if(verify_data(EditView)) _form.submit();" |
||
223 | name="button" value="{$APP['LBL_SAVE_BUTTON_LABEL']}"> |
||
224 | EOD |
||
225 | ; |
||
226 | $action_button_footer[] = <<<EOD |
||
227 | <input title="{$APP['LBL_CANCEL_BUTTON_TITLE']}" id="CANCEL_FOOTER" accessKey="{$APP['LBL_CANCEL_BUTTON_KEY']}" |
||
228 | class="button" onclick="var _form = $('#EditView')[0]; _form.action.value='{$RETURN_ACTION}'; _form.module.value='{$RETURN_MODULE}'; _form.record.value='{$RETURN_ID}'; _form.submit()" |
||
229 | type="button" name="button" value="{$APP['LBL_CANCEL_BUTTON_LABEL']}"> |
||
230 | EOD |
||
231 | ; |
||
232 | $action_button_footer = array_merge($action_button_footer, $this->ss->get_template_vars('BUTTONS_FOOTER')); |
||
233 | $this->ss->assign('ACTION_BUTTON_FOOTER', $action_button_footer); |
||
234 | |||
235 | //if the request object has 'scrolltocal' set, then we are coming here from the tour window box and need to set flag to true |
||
236 | // so that footer.tpl fires off script to scroll to calendar section |
||
237 | if(!empty($_REQUEST['scrollToCal'])){ |
||
238 | $this->ss->assign('scroll_to_cal', true); |
||
239 | } |
||
240 | $this->ev->process($processSpecial,$processFormName); |
||
|
|||
241 | |||
242 | echo $this->ev->display($this->showTitle); |
||
243 | |||
244 | } |
||
245 | |||
275 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.