| Conditions | 42 |
| Paths | > 20000 |
| Total Lines | 111 |
| Code Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 65 | public static function getComposeParam(App\Request $request) |
||
| 66 | { |
||
| 67 | $moduleName = $request->getByType('crmModule'); |
||
| 68 | $record = $request->getInteger('crmRecord'); |
||
| 69 | $type = $request->getByType('type'); |
||
| 70 | $return = []; |
||
| 71 | if (('Users' === $moduleName && $record === \App\User::getCurrentUserRealId()) || ('Users' !== $moduleName && !empty($record) && \App\Record::isExists($record) && \App\Privilege::isPermitted($moduleName, 'DetailView', $record))) { |
||
| 72 | $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName); |
||
| 73 | $eventHandler = new App\EventHandler(); |
||
| 74 | $eventHandler->setRecordModel($recordModel)->setModuleName($moduleName)->setParams($return); |
||
| 75 | $eventHandler->trigger('MailComposeParamBefore'); |
||
| 76 | $return = $eventHandler->getParams(); |
||
| 77 | |||
| 78 | $recordModel_OSSMailView = OSSMailView_Record_Model::getCleanInstance('OSSMailView'); |
||
| 79 | if ($request->isEmpty('to') && ($email = $recordModel_OSSMailView->findEmail($record, $moduleName))) { |
||
| 80 | $return['to'] = $email; |
||
| 81 | } |
||
| 82 | foreach (['_to', '_cc'] as $name) { |
||
| 83 | $content = $request->has($name) ? $request->getRaw($name) : ($return[$name] ?? ''); |
||
| 84 | if ($content) { |
||
| 85 | $emailParser = \App\EmailParser::getInstanceByModel($recordModel); |
||
| 86 | $emailParser->emailoptout = false; |
||
| 87 | $fromEmailDetails = $emailParser->setContent($content)->parse()->getContent(); |
||
| 88 | if ($fromEmailDetails) { |
||
| 89 | $return[substr($name, -2)] = $fromEmailDetails; |
||
| 90 | } |
||
| 91 | if (isset($return[$name])) { |
||
| 92 | unset($return[$name]); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | if (!\in_array($moduleName, array_keys(array_merge(\App\ModuleHierarchy::getModulesByLevel(0), \App\ModuleHierarchy::getModulesByLevel(3)))) || 'Campaigns' === $moduleName) { |
||
| 97 | $subject = ''; |
||
| 98 | if ('new' === $type || 'Campaigns' === $moduleName) { |
||
| 99 | $return['title'] = $recordModel->getName(); |
||
| 100 | $subject .= $recordModel->getName(); |
||
| 101 | } |
||
| 102 | $recordNumber = $recordModel->getRecordNumber(); |
||
| 103 | if (!empty($recordNumber)) { |
||
| 104 | $return['recordNumber'] = $recordNumber; |
||
| 105 | $subject = "[$recordNumber] $subject"; |
||
| 106 | } |
||
| 107 | if (($templateId = $request->getInteger('template', 0)) && \App\Record::isExists($templateId, 'EmailTemplates')) { |
||
| 108 | $params = $request->getArray('templateParams', \App\Purifier::TEXT, [], App\Purifier::ALNUM); |
||
| 109 | $templateModel = \Vtiger_Record_Model::getInstanceById($templateId, 'EmailTemplates'); |
||
| 110 | $textParser = \App\TextParser::getInstanceByModel($recordModel); |
||
| 111 | foreach ($params as $key => $value) { |
||
| 112 | $textParser->setParam($key, $value); |
||
| 113 | } |
||
| 114 | if ('Calendar' === $moduleName && !$recordModel->isEmpty('meeting_url') && !\array_key_exists('meetingUrl', $params) ) { |
||
| 115 | $textParser->setParam('meetingUrl', $recordModel->get('meeting_url')); |
||
| 116 | } |
||
| 117 | $subject = $textParser->setContent($templateModel->get('subject'))->parse()->getContent(); |
||
| 118 | $return['html'] = true; |
||
| 119 | $return['body'] = $textParser->setContent($templateModel->get('content'))->parse()->getContent(); |
||
| 120 | } |
||
| 121 | $return['subject'] = $subject; |
||
| 122 | if ('Calendar' === $moduleName && $request->getBoolean('ics')) { |
||
| 123 | $filePath = \App\Config::main('tmp_dir'); |
||
| 124 | $tmpFileName = tempnam($filePath, 'ics'); |
||
| 125 | $filePath .= basename($tmpFileName); |
||
| 126 | if (false !== file_put_contents($filePath, $recordModel->getICal())) { |
||
| 127 | $fileName = \App\Fields\File::sanitizeUploadFileName($recordModel->getName()) . '.ics'; |
||
| 128 | $return['filePath'] = [['path' => $filePath, 'name' => $fileName]]; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | $eventHandler->setParams($return); |
||
| 134 | $eventHandler->trigger('MailComposeParamAfter'); |
||
| 135 | $return = $eventHandler->getParams(); |
||
| 136 | } |
||
| 137 | if (!empty($moduleName)) { |
||
| 138 | $return['crmmodule'] = $moduleName; |
||
| 139 | } |
||
| 140 | if (!empty($record)) { |
||
| 141 | $return['crmrecord'] = $record; |
||
| 142 | } |
||
| 143 | if (!$request->isEmpty('crmView')) { |
||
| 144 | $return['crmview'] = $request->getByType('crmView'); |
||
| 145 | } |
||
| 146 | if (!$request->isEmpty('mid') && !empty($type)) { |
||
| 147 | $return['mailId'] = (int) $request->getInteger('mid'); |
||
| 148 | $return['type'] = $type; |
||
| 149 | } |
||
| 150 | if (!$request->isEmpty('pdf_path')) { |
||
| 151 | $return['filePath'] = $request->get('pdf_path'); |
||
| 152 | } |
||
| 153 | if (!empty($moduleName)) { |
||
| 154 | $currentUser = Users_Record_Model::getCurrentUserModel(); |
||
| 155 | $moduleConfig = App\Config::module($moduleName); |
||
| 156 | if ($moduleConfig && isset($moduleConfig['SEND_IDENTITY'][$currentUser->get('roleid')])) { |
||
| 157 | $return['from'] = $moduleConfig['SEND_IDENTITY'][$currentUser->get('roleid')]; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | if (!$request->isEmpty('to')) { |
||
| 161 | $return['to'] = $request->get('to'); |
||
| 162 | } |
||
| 163 | if (!$request->isEmpty('cc')) { |
||
| 164 | $return['cc'] = $request->get('cc'); |
||
| 165 | } |
||
| 166 | if (!$request->isEmpty('bcc')) { |
||
| 167 | $return['bcc'] = $request->get('bcc'); |
||
| 168 | } |
||
| 169 | if (!$request->isEmpty('subject')) { |
||
| 170 | $return['subject'] = $request->get('subject'); |
||
| 171 | } |
||
| 172 | if (!$request->isEmpty('emails')) { |
||
| 173 | $return['bcc'] = implode(',', $request->get('emails')); |
||
| 174 | } |
||
| 175 | return $return; |
||
| 176 | } |
||
| 345 |