Conditions | 38 |
Paths | > 20000 |
Total Lines | 162 |
Code Lines | 95 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 1482 |
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 |
||
106 | function &_get_form($defines, $additionalFormFields = null, $asUrl = false) |
||
107 | { |
||
108 | global $app_strings; |
||
109 | global $currentModule; |
||
110 | |||
111 | // Create the additional form fields with real values if they were not passed in |
||
112 | if(empty($additionalFormFields) && $this->additional_form_fields) |
||
113 | { |
||
114 | foreach($this->additional_form_fields as $key=>$value) |
||
115 | { |
||
116 | if(!empty($defines['focus']->$value)) |
||
117 | { |
||
118 | $additionalFormFields[$key] = $defines['focus']->$value; |
||
119 | } |
||
120 | else |
||
121 | { |
||
122 | $additionalFormFields[$key] = ''; |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | |||
127 | |||
128 | if(!empty($this->module)) |
||
129 | { |
||
130 | $defines['child_module_name'] = $this->module; |
||
131 | } |
||
132 | else |
||
133 | { |
||
134 | $defines['child_module_name'] = $defines['module']; |
||
135 | } |
||
136 | |||
137 | $defines['parent_bean_name'] = get_class( $defines['focus']); |
||
138 | $relationship_name = $this->get_subpanel_relationship_name($defines); |
||
139 | |||
140 | |||
141 | $formValues = array(); |
||
142 | |||
143 | //module_button is used to override the value of module name |
||
144 | $formValues['module'] = $defines['child_module_name']; |
||
145 | $formValues[strtolower($defines['parent_bean_name'])."_id"] = $defines['focus']->id; |
||
146 | |||
147 | if(isset($defines['focus']->name)) |
||
148 | { |
||
149 | $formValues[strtolower($defines['parent_bean_name'])."_name"] = $defines['focus']->name; |
||
150 | // #26451,add these fields for custom one-to-many relate field. |
||
151 | if(!empty($defines['child_module_name'])){ |
||
152 | $formValues[$relationship_name."_name"] = $defines['focus']->name; |
||
153 | $childFocusName = !empty($GLOBALS['beanList'][$defines['child_module_name']]) ? $GLOBALS['beanList'][$defines['child_module_name']] : ""; |
||
154 | if(!empty($GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name'])){ |
||
155 | $formValues[$GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name']] = $defines['focus']->id; |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 | $formValues['return_module'] = $currentModule; |
||
161 | |||
162 | if($currentModule == 'Campaigns'){ |
||
163 | $formValues['return_action'] = "DetailView"; |
||
164 | }else{ |
||
165 | $formValues['return_action'] = $defines['action']; |
||
166 | if ( $formValues['return_action'] == 'SubPanelViewer' ) { |
||
167 | $formValues['return_action'] = 'DetailView'; |
||
168 | } |
||
169 | } |
||
170 | |||
171 | $formValues['return_id'] = $defines['focus']->id; |
||
172 | $formValues['return_relationship'] = $relationship_name; |
||
173 | switch ( strtolower( $currentModule ) ) |
||
174 | { |
||
175 | case 'prospects' : |
||
|
|||
176 | $name = $defines['focus']->account_name ; |
||
177 | break ; |
||
178 | case 'documents' : |
||
179 | $name = $defines['focus']->document_name ; |
||
180 | break ; |
||
181 | case 'kbdocuments' : |
||
182 | $name = $defines['focus']->kbdocument_name ; |
||
183 | break ; |
||
184 | case 'leads' : |
||
185 | case 'contacts' : |
||
186 | $name = $defines['focus']->first_name . " " .$defines['focus']->last_name ; |
||
187 | break ; |
||
188 | default : |
||
189 | $name = (isset($defines['focus']->name)) ? $defines['focus']->name : ""; |
||
190 | } |
||
191 | $formValues['return_name'] = $name; |
||
192 | |||
193 | // TODO: move this out and get $additionalFormFields working properly |
||
194 | if(empty($additionalFormFields['parent_type'])) |
||
195 | { |
||
196 | if($defines['focus']->object_name=='Contact') { |
||
197 | $additionalFormFields['parent_type'] = 'Accounts'; |
||
198 | } |
||
199 | else { |
||
200 | $additionalFormFields['parent_type'] = $defines['focus']->module_dir; |
||
201 | } |
||
202 | } |
||
203 | if(empty($additionalFormFields['parent_name'])) |
||
204 | { |
||
205 | if($defines['focus']->object_name=='Contact') { |
||
206 | $additionalFormFields['parent_name'] = $defines['focus']->account_name; |
||
207 | $additionalFormFields['account_name'] = $defines['focus']->account_name; |
||
208 | } |
||
209 | else { |
||
210 | $additionalFormFields['parent_name'] = $defines['focus']->name; |
||
211 | } |
||
212 | } |
||
213 | if(empty($additionalFormFields['parent_id'])) |
||
214 | { |
||
215 | if($defines['focus']->object_name=='Contact') { |
||
216 | $additionalFormFields['parent_id'] = $defines['focus']->account_id; |
||
217 | $additionalFormFields['account_id'] = $defines['focus']->account_id; |
||
218 | } else if($defines['focus']->object_name=='Contract') { |
||
219 | $additionalFormFields['contract_id'] = $defines['focus']->id; |
||
220 | } else { |
||
221 | $additionalFormFields['parent_id'] = $defines['focus']->id; |
||
222 | } |
||
223 | } |
||
224 | |||
225 | if ($defines['focus']->object_name=='Opportunity') { |
||
226 | $additionalFormFields['account_id'] = $defines['focus']->account_id; |
||
227 | $additionalFormFields['account_name'] = $defines['focus']->account_name; |
||
228 | } |
||
229 | |||
230 | if (!empty($defines['child_module_name']) and $defines['child_module_name']=='Contacts' and !empty($defines['parent_bean_name']) and $defines['parent_bean_name']=='contact' ) { |
||
231 | if (!empty($defines['focus']->id ) and !empty($defines['focus']->name)) { |
||
232 | $formValues['reports_to_id'] = $defines['focus']->id; |
||
233 | $formValues['reports_to_name'] = $defines['focus']->name; |
||
234 | } |
||
235 | } |
||
236 | $formValues['action'] = "EditView"; |
||
237 | |||
238 | if ( $asUrl ) { |
||
239 | $returnLink = ''; |
||
240 | foreach($formValues as $key => $value ) { |
||
241 | $returnLink .= $key.'='.$value.'&'; |
||
242 | } |
||
243 | foreach($additionalFormFields as $key => $value ) { |
||
244 | $returnLink .= $key.'='.$value.'&'; |
||
245 | } |
||
246 | $returnLink = rtrim($returnLink,'&'); |
||
247 | |||
248 | return $returnLink; |
||
249 | } else { |
||
250 | |||
251 | $form = 'form' . $relationship_name; |
||
252 | $button = '<form action="index.php" method="post" name="form" id="' . $form . "\">\n"; |
||
253 | foreach($formValues as $key => $value) { |
||
254 | $button .= "<input type='hidden' name='" . $key . "' value='" . $value . "' />\n"; |
||
255 | } |
||
256 | |||
257 | // fill in additional form fields for all but action |
||
258 | foreach($additionalFormFields as $key => $value) { |
||
259 | if($key != 'action') { |
||
260 | $button .= "<input type='hidden' name='" . $key . "' value='" . $value . "' />\n"; |
||
261 | } |
||
262 | } |
||
263 | |||
264 | |||
265 | return $button; |
||
266 | } |
||
267 | } |
||
268 | |||
331 |
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.