Conditions | 13 |
Paths | 12 |
Total Lines | 58 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
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 |
||
22 | public function run($request) |
||
23 | { |
||
24 | /** @var Kernel $kernel */ |
||
25 | $kernel = Injector::inst()->get(Kernel::class); |
||
26 | $kernel->setEnvironment('dev'); |
||
27 | $from = $request->getVar('from') ?: Config::inst()->get(Email::class, 'admin_email'); |
||
|
|||
28 | $to = $request->getVar('to') ?: Config::inst()->get(Email::class, 'admin_email'); |
||
29 | $adminEmail = Config::inst()->get(Email::class, 'admin_email'); |
||
30 | if(is_array($adminEmail)) { |
||
31 | $keys = array_keys($adminEmail); |
||
32 | $adminEmail = array_pop($keys); |
||
33 | } |
||
34 | $from = $request->getVar('from') ?: $adminEmail ; |
||
35 | $to = $request->getVar('to') ?: $adminEmail; |
||
36 | $subject = $request->getVar('subject') ?: 'testing email'; |
||
37 | $message = $request->getVar('message') ?: 'Message goes here'; |
||
38 | if (Director::is_cli()) { |
||
39 | echo ' |
||
40 | |||
41 | from: ' . Convert::raw2att($from) . ' |
||
42 | |||
43 | to: ' . Convert::raw2att($to) . ' |
||
44 | |||
45 | subject:' . Convert::raw2att($subject) . '" /><br/><br/> |
||
46 | |||
47 | message: ' . Convert::raw2att($message) . ' |
||
48 | |||
49 | Change values like this: sake dev/tasks/testemail [email protected] [email protected] subject=test message=hello |
||
50 | '; |
||
51 | } else { |
||
52 | echo ' |
||
53 | <style> |
||
54 | input {width: 80vw; max-width: 500px; padding: 5px;} |
||
55 | </style> |
||
56 | <form action="" method="get"> |
||
57 | from: <br/><input name="from" value="' . Convert::raw2att($from) . '" /><br/><br/> |
||
58 | to: <br/><input name="to" value="' . Convert::raw2att($to) . '" /><br/><br/> |
||
59 | subject: <br/><input name="subject" value="' . Convert::raw2att($subject) . '" /><br/><br/> |
||
60 | message: <br/><input name="message" value="' . Convert::raw2att($message) . '" /><br/><br/> |
||
61 | <input type="submit" /> |
||
62 | </form> |
||
63 | '; |
||
64 | } |
||
65 | if($request->getVar('from')) { |
||
66 | if (Director::is_cli()) { |
||
67 | echo ' |
||
68 | ========================== |
||
69 | Outcome |
||
70 | ========================== |
||
71 | '; |
||
72 | } else { |
||
73 | echo '<h1>Outcome</h1>'; |
||
74 | } |
||
75 | $outcome = mail($to, $subject . ' raw mail', $message); |
||
76 | echo 'PHP mail sent: ' . ($outcome ? 'YES' : 'NO') . $this->newLine(); |
||
77 | $email = new Email($from, $to, $subject . ' silverstripe message', $message); |
||
78 | $outcome = $email->sendPlain(); |
||
79 | echo 'Silverstripe e-mail sent: ' . ($outcome ? 'YES' : 'NO') . $this->newLine(); |
||
80 | } |
||
93 |