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