Conditions | 8 |
Paths | 9 |
Total Lines | 68 |
Code Lines | 47 |
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 declare(strict_types=1); |
||
94 | public function storeMsg(ParsedMessage $msg, \XoopsUser $user, DepartmentMailBox $mbox, &$errors) |
||
95 | { |
||
96 | //Remove any previous error messages |
||
97 | $this->clearErrors(); |
||
98 | |||
99 | $type = $msg->getMsgType(); |
||
100 | switch ($type) { |
||
101 | case _XHELP_MSGTYPE_TICKET: |
||
102 | $obj = $this->ticketHandler->create(); |
||
103 | $obj->setVar('uid', $user->getVar('uid')); |
||
104 | $obj->setVar('subject', $msg->getSubject()); |
||
105 | $obj->setVar('description', $msg->getMsg()); |
||
106 | $obj->setVar('department', $mbox->getVar('departmentid')); |
||
107 | $obj->setVar('priority', $mbox->getVar('priority')); |
||
108 | $obj->setVar('posted', \time()); |
||
109 | $obj->setVar('serverid', $mbox->getVar('id')); |
||
110 | $obj->setVar('userIP', 'via Email'); |
||
111 | $obj->setVar('email', $user->getVar('email')); |
||
112 | if (!$status = Utility::getMeta('default_status')) { |
||
113 | Utility::setMeta('default_status', '1'); |
||
114 | $status = 1; |
||
115 | } |
||
116 | $obj->setVar('status', $status); |
||
117 | $obj->createEmailHash($msg->getEmail()); |
||
|
|||
118 | if ($this->ticketHandler->insert($obj)) { |
||
119 | $obj->addSubmitter($user->getVar('email'), $user->getVar('uid')); |
||
120 | $this->saveAttachments($msg, $obj->getVar('id')); |
||
121 | |||
122 | $errors = $this->_getErrors(); |
||
123 | |||
124 | return [$obj]; |
||
125 | } |
||
126 | break; |
||
127 | case _XHELP_MSGTYPE_RESPONSE: |
||
128 | if (!$ticket = $this->ticketHandler->getTicketByHash($msg->getHash())) { |
||
129 | $this->_setError(\_XHELP_RESPONSE_NO_TICKET); |
||
130 | |||
131 | return false; |
||
132 | } |
||
133 | |||
134 | if ($msg->getEmail() != $ticket->getVar('email')) { |
||
135 | $this->_setError(\sprintf(\_XHELP_MISMATCH_EMAIL, $msg->getEmail(), $ticket->getVar('email'))); |
||
136 | |||
137 | return false; |
||
138 | } |
||
139 | |||
140 | $obj = $this->responseHandler->create(); |
||
141 | $obj->setVar('ticketid', $ticket->getVar('id')); |
||
142 | $obj->setVar('uid', $user->getVar('uid')); |
||
143 | $obj->setVar('message', $msg->getMsg()); |
||
144 | $obj->setVar('updateTime', \time()); |
||
145 | $obj->setVar('userIP', 'via Email'); |
||
146 | |||
147 | if ($this->responseHandler->insert($obj)) { |
||
148 | $this->saveAttachments($msg, $ticket->getVar('id'), $obj->getVar('id')); |
||
149 | $ticket->setVar('lastUpdated', \time()); |
||
150 | $this->ticketHandler->insert($ticket); |
||
151 | |||
152 | $errors = $this->_getErrors(); |
||
153 | |||
154 | return [$ticket, $obj]; |
||
155 | } |
||
156 | break; |
||
157 | default: |
||
158 | //Sanity Check, should never get here |
||
159 | } |
||
160 | |||
161 | return false; |
||
162 | } |
||
245 |