| Conditions | 12 |
| Paths | 28 |
| Total Lines | 68 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 22 | ||
| 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 |
||
| 24 | public function run($request) |
||
| 25 | { |
||
| 26 | /** @var Kernel $kernel */ |
||
| 27 | $kernel = Injector::inst()->get(Kernel::class); |
||
| 28 | $kernel->setEnvironment('dev'); |
||
| 29 | |||
| 30 | $adminEmail = Config::inst()->get(Email::class, 'admin_email'); |
||
| 31 | if (is_array($adminEmail)) { |
||
| 32 | $keys = array_keys($adminEmail); |
||
| 33 | $adminEmail = array_pop($keys); |
||
| 34 | } |
||
| 35 | |||
| 36 | $from = $request->requestVar('from') ?: $adminEmail; |
||
| 37 | $to = $request->requestVar('to') ?: $adminEmail; |
||
| 38 | $subject = $request->requestVar('subject') ?: 'testing email'; |
||
| 39 | $message = $request->requestVar('message') ?: 'Message goes here'; |
||
| 40 | $mailProvider = Injector::inst()->get(MailerInterface::class); |
||
| 41 | if (Director::is_cli()) { |
||
| 42 | echo ' |
||
| 43 | |||
| 44 | from: ' . Convert::raw2att($from) . ' |
||
| 45 | |||
| 46 | to: ' . Convert::raw2att($to) . ' |
||
| 47 | |||
| 48 | subject:' . Convert::raw2att($subject) . '" /><br/><br/> |
||
| 49 | |||
| 50 | message: ' . Convert::raw2att($message) . ' |
||
| 51 | |||
| 52 | Change values like this: sake dev/tasks/testemail [email protected] [email protected] subject=test message=hello |
||
| 53 | '; |
||
| 54 | } else { |
||
| 55 | echo ' |
||
| 56 | <style> |
||
| 57 | input {width: 80vw; max-width: 500px; padding: 5px;} |
||
| 58 | </style> |
||
| 59 | <form action="" method="' . $this->formMethod() . '"> |
||
| 60 | from: <br/><input name="from" value="' . Convert::raw2att($from) . '" /><br/><br/> |
||
| 61 | to: <br/><input name="to" value="' . Convert::raw2att($to) . '" /><br/><br/> |
||
| 62 | subject: <br/><input name="subject" value="' . Convert::raw2att($subject) . '" /><br/><br/> |
||
| 63 | message: <br/><input name="message" value="' . Convert::raw2att($message) . '" /><br/><br/> |
||
| 64 | <input type="submit" /> |
||
| 65 | </form> |
||
| 66 | '; |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($request->requestVar('from')) { |
||
| 70 | if (Director::is_cli()) { |
||
| 71 | echo ' |
||
| 72 | ========================== |
||
| 73 | Outcome |
||
| 74 | ========================== |
||
| 75 | '; |
||
| 76 | } else { |
||
| 77 | echo '<h1>Outcome</h1>'; |
||
| 78 | } |
||
| 79 | |||
| 80 | $outcome = mail($to, $subject . ' raw mail', $message); |
||
| 81 | echo 'PHP mail sent: ' . ($outcome ? 'NO' : 'CHECK EMAIL TO VERIFY') . $this->newLine(); |
||
| 82 | |||
| 83 | try { |
||
| 84 | $email = new Email($from, $to, $subject . ' silverstripe message', $message); |
||
| 85 | $email->sendPlain(); |
||
| 86 | $outcome = true; |
||
| 87 | } catch (\Exception $e) { |
||
| 88 | die('<div>Mail send error: <span style="color:red">' . $e->getMessage() . '</span></div>'); |
||
| 89 | } |
||
| 90 | echo 'Silverstripe e-mail sent: ' . ($outcome ? 'NO' : 'CHECK EMAIL TO VERIFY') . $this->newLine(); |
||
| 91 | echo 'Mail Service Provider: ' . get_class($mailProvider) . $this->newLine(); |
||
| 92 | } |
||
| 115 |
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