| Conditions | 12 |
| Paths | 97 |
| Total Lines | 58 |
| Code Lines | 41 |
| 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 |
||
| 26 | public function process(): void |
||
| 27 | { |
||
| 28 | if ($this->checkExceptions() || ($prefix = RecordFinder::getRecordNumberFromString($this->message->getSubject(), 'HelpDesk')) && \App\Record::getIdByRecordNumber($prefix, 'HelpDesk')) { |
||
| 29 | return; |
||
| 30 | } |
||
| 31 | $owner = $this->account->getSource()->get('assigned_user_id'); |
||
| 32 | $fromEmail = $this->message->getEmail('from'); |
||
| 33 | $contactId = current(\App\Utils::flatten(RecordFinder::findByEmail($fromEmail, $this->getEmailsFields('Contacts')))); |
||
| 34 | $parentId = current(\App\Utils::flatten(RecordFinder::findByEmail($fromEmail, $this->getEmailsFields('Accounts')))); |
||
| 35 | if (!$parentId) { |
||
| 36 | $parentId = current(\App\Utils::flatten(RecordFinder::findByEmail($fromEmail, $this->getEmailsFields('Vendors')))); |
||
| 37 | } |
||
| 38 | if (!$parentId && $contactId) { |
||
| 39 | $parentId = \App\Record::getParentRecord($contactId, 'Contacts'); |
||
| 40 | } |
||
| 41 | $recordModel = \Vtiger_Record_Model::getCleanInstance('HelpDesk'); |
||
| 42 | $this->loadServiceContracts($recordModel, $parentId); |
||
| 43 | $recordModel->set('assigned_user_id', $owner); |
||
| 44 | $recordModel->set('created_user_id', \App\User::getCurrentUserRealId()); |
||
| 45 | $recordModel->setFromUserValue('ticket_title', \App\TextUtils::textTruncate($this->message->getSubject(), $recordModel->getField('ticket_title')->getMaxValue(), false)); |
||
| 46 | |||
| 47 | $mailId = $this->message->getMailCrmId($this->account->getSource()->getId()); |
||
| 48 | $this->message->getBody(); |
||
| 49 | if ($mailId) { |
||
| 50 | $this->attachments = $this->message->processData['CreatedMail']['attachments'] ?? (new \App\Db\Query())->select(['crmid' => 'documentsid'])->from('vtiger_ossmailview_files')->where(['ossmailviewid' => $mailId])->all(); |
||
|
|
|||
| 51 | } elseif ($this->message->hasAttachments()) { |
||
| 52 | $this->message->saveAttachments([ |
||
| 53 | 'assigned_user_id' => $owner, |
||
| 54 | 'modifiedby' => $owner, |
||
| 55 | ]); |
||
| 56 | } |
||
| 57 | $recordModel->set('description', \App\TextUtils::htmlTruncate($this->message->getBody(true), $recordModel->getField('description')->getMaxValue())); |
||
| 58 | $recordModel->set('ticketstatus', \Config\Modules\OSSMailScanner::$helpdeskCreateDefaultStatus); |
||
| 59 | |||
| 60 | if ($contactId) { |
||
| 61 | $recordModel->ext['relations'][] = [ |
||
| 62 | 'relatedModule' => 'Contacts', |
||
| 63 | 'relatedRecords' => [$contactId], |
||
| 64 | ]; |
||
| 65 | } |
||
| 66 | if ($mailId) { |
||
| 67 | $recordModel->ext['relations'][] = [ |
||
| 68 | 'reverse' => true, |
||
| 69 | 'relatedModule' => 'OSSMailView', |
||
| 70 | 'relatedRecords' => [$mailId], |
||
| 71 | 'params' => $this->message->getDate(), |
||
| 72 | ]; |
||
| 73 | } |
||
| 74 | |||
| 75 | foreach ($this->attachments as $file) { |
||
| 76 | $recordModel->ext['relations'][] = [ |
||
| 77 | 'relatedModule' => 'Documents', |
||
| 78 | 'relatedRecords' => [$file['crmid']], |
||
| 79 | ]; |
||
| 80 | } |
||
| 81 | |||
| 82 | $recordModel->save(); |
||
| 83 | $this->message->setProcessData($this->getName(), ['crmid' => $recordModel->getId()]); |
||
| 84 | } |
||
| 117 |