| Conditions | 14 |
| Paths | 176 |
| Total Lines | 41 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 16 | public function process(App\Request $request) |
||
| 17 | { |
||
| 18 | $moduleName = $request->getModule(); |
||
| 19 | $uid = $request->getInteger('uid'); |
||
| 20 | $account = OSSMail_Record_Model::getAccountByHash($request->getForSql('rcId')); |
||
| 21 | if (!$account || !\App\Record::isExists($account['crm_ma_id'], 'MailAccount') || !\App\Privilege::isPermitted('MailAccount', 'DetailView', $account['crm_ma_id'])) { |
||
| 22 | throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406); |
||
| 23 | } |
||
| 24 | $mailAccount = \App\Mail\Account::getInstanceById($account['crm_ma_id']); |
||
| 25 | try { |
||
| 26 | $mailViewModel = OSSMailView_Record_Model::getCleanInstance('OSSMailView'); |
||
| 27 | $folderDecode = \App\Utils::convertCharacterEncoding($request->getRaw('folder'), 'UTF7-IMAP', 'UTF-8'); |
||
| 28 | $folderDecode = \App\Purifier::purifyByType($folderDecode, 'Text'); |
||
| 29 | $folderDecode = \App\Purifier::decodeHtml($folderDecode); |
||
| 30 | $imap = $mailAccount->openImap(); |
||
| 31 | $message = $imap->getMessageByUid($folderDecode, $uid); |
||
| 32 | $record = $message ? $message->getMailCrmIdByCid() : 0; |
||
| 33 | if (!$record && \in_array('CreatedMail', $mailAccount->getActions()) && \in_array($folderDecode, $mailAccount->getFolders())) { |
||
|
|
|||
| 34 | $scanner = (new \App\Mail\Scanner())->setLimit(1); |
||
| 35 | foreach ($mailAccount->getActions() as $action) { |
||
| 36 | $scanner->getAction($action)->setAccount($mailAccount)->setMessage($message)->process(); |
||
| 37 | } |
||
| 38 | $record = (int) $message->getProcessData('CreatedMail')['mailViewId'] ?? 0; |
||
| 39 | } elseif ($record && !\App\Privilege::isPermitted('OSSMailView', 'DetailView', $record)) { |
||
| 40 | $recordModel = Vtiger_Record_Model::getInstanceById($record, $mailViewModel->getModule()); |
||
| 41 | $sharedOwner = $recordModel->isEmpty('shownerid') ? [] : explode(',', $recordModel->get('shownerid')); |
||
| 42 | $sharedOwner[] = \App\User::getCurrentUserId(); |
||
| 43 | $recordModel->set('shownerid', implode(',', $sharedOwner))->save(); |
||
| 44 | } |
||
| 45 | $viewer = $this->getViewer($request); |
||
| 46 | $viewer->assign('RECORD', $record); |
||
| 47 | if ($record) { |
||
| 48 | $relatedRecords = $mailViewModel->getRelatedRecords($record); |
||
| 49 | $viewer->assign('RELATED_RECORDS', $relatedRecords); |
||
| 50 | } |
||
| 51 | \App\ModuleHierarchy::getModulesByLevel(0); |
||
| 52 | $viewer->assign('MODULE_NAME', $moduleName); |
||
| 53 | $viewer->assign('URL', App\Config::main('site_URL')); |
||
| 54 | $viewer->view('MailActionBar.tpl', $moduleName); |
||
| 55 | } catch (\Throwable $e) { |
||
| 56 | \App\Log::error($e->getMessage() . PHP_EOL . $e->__toString(), 'OSSMail'); |
||
| 57 | } |
||
| 60 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: