| Conditions | 16 |
| Paths | 84 |
| Total Lines | 69 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 84.0252 |
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 | 1 | public function save(&$bean, $params, $field, $vardef, $prefix = '') |
|
| 46 | { |
||
| 47 | |||
| 48 | 1 | $fakeDisplayParams = array(); |
|
| 49 | 1 | $this->fillInOptions($vardef, $fakeDisplayParams); |
|
| 50 | |||
| 51 | 1 | require_once('include/upload_file.php'); |
|
| 52 | 1 | $upload_file = new UploadFile($prefix . $field . '_file'); |
|
| 53 | //remove file |
||
| 54 | 1 | if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) { |
|
| 55 | $upload_file->unlink_file($bean->$field); |
||
| 56 | $bean->$field = ""; |
||
| 57 | } |
||
| 58 | |||
| 59 | 1 | $move = false; |
|
| 60 | 1 | if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) { |
|
| 61 | if($this->verify_image($upload_file)) { |
||
| 62 | $bean->$field = $upload_file->get_stored_file_name(); |
||
| 63 | $move = true; |
||
| 64 | }else{ |
||
| 65 | //not valid image. |
||
| 66 | $GLOBALS['log']->fatal("Image Field : Not a Valid Image."); |
||
| 67 | $temp = $vardef['vname']; |
||
| 68 | $temp = translate($temp, $bean->module_name); |
||
| 69 | SugarApplication::appendErrorMessage($temp . " Field : Not a valid image format."); |
||
| 70 | } |
||
| 71 | |||
| 72 | } |
||
| 73 | |||
| 74 | 1 | if (empty($bean->id)) { |
|
| 75 | 1 | $bean->id = create_guid(); |
|
| 76 | 1 | $bean->new_with_id = true; |
|
| 77 | } |
||
| 78 | |||
| 79 | 1 | if ($move) { |
|
| 80 | $upload_file->final_move($bean->id . '_' . $field); //BEAN ID IS THE FILE NAME IN THE INSTANCE. |
||
| 81 | |||
| 82 | $upload_file->upload_doc($bean, $bean->id, $params[$prefix . $vardef['docType']], $bean->$field, $upload_file->mime_type); |
||
| 83 | 1 | } else if (!empty($old_id)) { |
|
|
|
|||
| 84 | // It's a duplicate, I think |
||
| 85 | |||
| 86 | if (empty($params[$prefix . $vardef['docUrl']])) { |
||
| 87 | $upload_file->duplicate_file($old_id, $bean->id, $bean->$field); |
||
| 88 | } else { |
||
| 89 | $docType = $vardef['docType']; |
||
| 90 | $bean->$docType = $params[$prefix . $field . '_old_doctype']; |
||
| 91 | } |
||
| 92 | 1 | } else if (!empty($params[$prefix . $field . '_remoteName'])) { |
|
| 93 | // We aren't moving, we might need to do some remote linking |
||
| 94 | $displayParams = array(); |
||
| 95 | $this->fillInOptions($vardef, $displayParams); |
||
| 96 | |||
| 97 | if (isset($params[$prefix . $vardef['docId']]) |
||
| 98 | && !empty($params[$prefix . $vardef['docId']]) |
||
| 99 | && isset($params[$prefix . $vardef['docType']]) |
||
| 100 | && !empty($params[$prefix . $vardef['docType']]) |
||
| 101 | ) { |
||
| 102 | $bean->$field = $params[$prefix . $field . '_remoteName']; |
||
| 103 | |||
| 104 | require_once('include/utils/file_utils.php'); |
||
| 105 | $extension = get_file_extension($bean->$field); |
||
| 106 | if (!empty($extension)) { |
||
| 107 | $bean->file_ext = $extension; |
||
| 108 | $bean->file_mime_type = get_mime_content_type_from_filename($bean->$field); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | 1 | } |
|
| 114 | |||
| 159 | ?> |
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.