| Conditions | 11 |
| Paths | 26 |
| Total Lines | 98 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 132 |
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 |
||
| 224 | function set_custom_field($session, $module_name, $type, $properties, $add_to_layout) { |
||
| 225 | global $current_user; |
||
| 226 | global $beanList, $beanFiles; |
||
| 227 | global $custom_field_meta; |
||
| 228 | |||
| 229 | $error = new SoapError(); |
||
| 230 | |||
| 231 | $request_arr = array( |
||
| 232 | 'action' => 'SaveField', |
||
| 233 | 'is_update' => 'true', |
||
| 234 | 'module' => 'ModuleBuilder', |
||
| 235 | 'view_module' => $module_name, |
||
| 236 | 'view_package' => 'studio' |
||
| 237 | ); |
||
| 238 | |||
| 239 | // ERROR CHECKING |
||
| 240 | if(!validate_authenticated($session)) { |
||
| 241 | $error->set_error('invalid_login'); |
||
| 242 | return $error->get_soap_array(); |
||
| 243 | } |
||
| 244 | |||
| 245 | if (!is_admin($current_user)) { |
||
| 246 | $error->set_error('no_admin'); |
||
| 247 | return $error->get_soap_array(); |
||
| 248 | } |
||
| 249 | |||
| 250 | if(empty($beanList[$module_name])){ |
||
| 251 | $error->set_error('no_module'); |
||
| 252 | return $error->get_soap_array(); |
||
| 253 | } |
||
| 254 | |||
| 255 | if (empty($custom_field_meta[$type])) { |
||
| 256 | $error->set_error('custom_field_type_not_supported'); |
||
| 257 | return $error->get_soap_array(); |
||
| 258 | } |
||
| 259 | |||
| 260 | $new_properties = array(); |
||
| 261 | foreach($properties as $value) { |
||
| 262 | $new_properties[$value['name']] = $value['value']; |
||
| 263 | } |
||
| 264 | |||
| 265 | foreach ($custom_field_meta[$type] as $property) { |
||
| 266 | if (!isset($new_properties[$property])) { |
||
| 267 | $error->set_error('custom_field_property_not_supplied'); |
||
| 268 | return $error->get_soap_array(); |
||
| 269 | } |
||
| 270 | |||
| 271 | $request_arr[$property] = $new_properties[$property]; |
||
| 272 | } |
||
| 273 | |||
| 274 | // $request_arr should now contain all the necessary information to create a custom field |
||
| 275 | // merge $request_arr with $_POST/$_REQUEST, where the action_saveField() method expects them |
||
| 276 | $_REQUEST = array_merge($_REQUEST, $request_arr); |
||
| 277 | $_POST = array_merge($_POST, $request_arr); |
||
| 278 | |||
| 279 | require_once('include/MVC/Controller/SugarController.php'); |
||
| 280 | require_once('modules/ModuleBuilder/controller.php'); |
||
| 281 | require_once('modules/ModuleBuilder/parsers/ParserFactory.php'); |
||
| 282 | |||
| 283 | $mbc = new ModuleBuilderController(); |
||
| 284 | $mbc->setup(); |
||
| 285 | $mbc->action_SaveField(); |
||
| 286 | |||
| 287 | // add the field to the given module's EditView and DetailView layouts |
||
| 288 | if ($add_to_layout == 1) { |
||
| 289 | $layout_properties = array( |
||
| 290 | 'name' => $new_properties['name'], |
||
| 291 | 'label' => $new_properties['label'] |
||
| 292 | ); |
||
| 293 | |||
| 294 | if (isset($new_properties['customCode'])) { |
||
| 295 | $layout_properties['customCode'] = $new_properties['customCode']; |
||
| 296 | } |
||
| 297 | if (isset($new_properties['customLabel'])) { |
||
| 298 | $layout_properties['customLabel'] = $new_properties['customLabel']; |
||
| 299 | } |
||
| 300 | |||
| 301 | // add the field to the DetailView |
||
| 302 | $parser = ParserFactory::getParser('layoutview', FALSE); |
||
| 303 | $parser->init($module_name, 'DetailView', FALSE); |
||
|
|
|||
| 304 | |||
| 305 | $parser->_addField($layout_properties); |
||
| 306 | $parser->writeWorkingFile(); |
||
| 307 | $parser->handleSave(); |
||
| 308 | |||
| 309 | unset($parser); |
||
| 310 | |||
| 311 | // add the field to the EditView |
||
| 312 | $parser = ParserFactory::getParser('layoutview', FALSE); |
||
| 313 | $parser->init($module_name, 'EditView', FALSE); |
||
| 314 | |||
| 315 | $parser->_addField($layout_properties); |
||
| 316 | $parser->writeWorkingFile(); |
||
| 317 | $parser->handleSave(); |
||
| 318 | } |
||
| 319 | |||
| 320 | return $error->get_soap_array(); |
||
| 321 | } |
||
| 322 | ?> |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.