| Conditions | 13 |
| Paths | 123 |
| Total Lines | 73 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 32 | public function execute() |
||
| 33 | { |
||
| 34 | $this->request = $this->getRequest(); |
||
| 35 | $user = $this->getTriggerUser(); |
||
| 36 | $parameters = $this->getParameters(); |
||
| 37 | |||
| 38 | if ($this->request->getStatus() !== RequestStatus::JOBQUEUE) { |
||
| 39 | $this->markCancelled('Request is not deferred to the job queue'); |
||
| 40 | |||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($this->request->getEmailSent() != 0 && !isset($parameters->emailText)) { |
||
| 45 | $this->markFailed('Request has already been sent a templated email'); |
||
| 46 | |||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($this->request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
||
| 51 | $this->markFailed('Private data of request has been purged.'); |
||
| 52 | |||
| 53 | return; |
||
| 54 | } |
||
| 55 | |||
| 56 | $emailText = null; |
||
| 57 | $ccMailingList = null; |
||
| 58 | $logTarget = null; |
||
| 59 | |||
| 60 | if (isset($parameters->emailText) && isset($parameters->ccMailingList)) { |
||
| 61 | $emailText = $parameters->emailText; |
||
| 62 | $ccMailingList = $parameters->ccMailingList; |
||
| 63 | $logTarget = "custom-y"; |
||
| 64 | } |
||
| 65 | |||
| 66 | if ($this->getEmailTemplate() !== null) { |
||
| 67 | $emailText = $this->getEmailTemplate()->getText(); |
||
| 68 | $ccMailingList = false; |
||
| 69 | $logTarget = $this->getEmailTemplate()->getId(); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($emailText === null || $ccMailingList === null) { |
||
| 73 | $this->markFailed('Unable to get closure email text'); |
||
| 74 | |||
| 75 | return; |
||
| 76 | } |
||
| 77 | |||
| 78 | try { |
||
| 79 | $this->performCreation($user); |
||
| 80 | |||
| 81 | $this->request->setStatus(RequestStatus::CLOSED); |
||
| 82 | $this->request->setQueue(null); |
||
| 83 | $this->request->setReserved(null); |
||
| 84 | $this->request->setEmailSent(true); |
||
| 85 | $this->request->save(); |
||
| 86 | |||
| 87 | // Log the closure as the user |
||
| 88 | $logComment = $this->getEmailTemplate() === null ? $emailText : null; |
||
| 89 | Logger::closeRequest($this->getDatabase(), $this->request, $logTarget, $logComment, $this->getTriggerUser()); |
||
|
|
|||
| 90 | |||
| 91 | $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
||
| 92 | $requestEmailHelper->sendMail($this->request, $emailText, $this->getTriggerUser(), $ccMailingList); |
||
| 93 | } |
||
| 94 | catch (Exception $ex) { |
||
| 95 | if (mb_strlen($ex->getMessage()) > 255) { |
||
| 96 | ExceptionHandler::logExceptionToDisk($ex, $this->getSiteConfiguration()); |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->markFailed(substr($ex->getMessage(), 0, 255)); |
||
| 100 | |||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | $this->markComplete(); |
||
| 105 | } |
||
| 176 | } |