| Conditions | 8 |
| Paths | 24 |
| Total Lines | 54 |
| Code Lines | 34 |
| 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 |
||
| 59 | public function SendEmailing() |
||
| 60 | { |
||
| 61 | Environment::increaseTimeLimitTo(); |
||
| 62 | |||
| 63 | $id = (int) $this->getRequest()->getVar('id'); |
||
| 64 | |||
| 65 | /* @var $Emailing Emailing */ |
||
| 66 | $Emailing = self::getEmailingById($id); |
||
| 67 | $emails = $Emailing->getEmailsByLocales(); |
||
| 68 | |||
| 69 | $errors = 0; |
||
| 70 | $messages = []; |
||
| 71 | foreach ($emails as $locale => $emails) { |
||
| 72 | foreach ($emails as $email) { |
||
| 73 | $res = null; |
||
| 74 | $msg = null; |
||
| 75 | // Wrap with withLocale to make sure any environment variable (urls, etc) are properly set when sending |
||
| 76 | FluentHelper::withLocale($locale, function () use ($email, &$res, &$msg) { |
||
| 77 | try { |
||
| 78 | $res = $email->send(); |
||
| 79 | } catch (Exception $ex) { |
||
| 80 | $res = false; |
||
| 81 | $msg = $ex->getMessage(); |
||
| 82 | } |
||
| 83 | }); |
||
| 84 | if (!$res) { |
||
| 85 | $errors++; |
||
| 86 | $messages[] = $msg; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($errors == 0) { |
||
| 92 | $Emailing->LastSent = date('Y-m-d H:i:s'); |
||
| 93 | $Emailing->LastSentCount = count($emails); |
||
| 94 | $Emailing->write(); |
||
| 95 | $message = _t('EmailTemplatesAdmin.EMAILING_SENT', 'Emailing sent'); |
||
| 96 | } else { |
||
| 97 | $Emailing->LastError = implode(", ", $messages); |
||
| 98 | $Emailing->write(); |
||
| 99 | |||
| 100 | $message = _t('EmailTemplatesAdmin.EMAILING_ERROR', 'There was an error sending email'); |
||
| 101 | $message .= ": " . implode(", ", $messages); |
||
| 102 | } |
||
| 103 | |||
| 104 | if (Director::is_ajax()) { |
||
| 105 | $this->getResponse()->addHeader('X-Status', rawurlencode($message)); |
||
| 106 | if ($errors > 0) { |
||
| 107 | // $this->getResponse()->setStatusCode(400); |
||
| 108 | } |
||
| 109 | return $this->getResponse(); |
||
| 110 | } |
||
| 111 | |||
| 112 | return $message; |
||
| 113 | } |
||
| 230 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths