| Conditions | 3 |
| Paths | 8 |
| Total Lines | 54 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 113 | public function sendTestEmail(Request $request) |
||
| 114 | { |
||
| 115 | |||
| 116 | // echo $request->host; |
||
| 117 | // echo ' '; |
||
| 118 | // die(); |
||
| 119 | Log::info(config('mail.host')); |
||
| 120 | |||
| 121 | // Make sure that all of the information properly validates |
||
| 122 | $request->validate([ |
||
| 123 | 'host' => 'required', |
||
| 124 | 'port' => 'required|numeric', |
||
| 125 | 'encryption' => 'required', |
||
| 126 | 'username' => 'required' |
||
| 127 | ]); |
||
| 128 | |||
| 129 | // Temporarily set the email settings |
||
| 130 | // config([ |
||
| 131 | // 'mail.host' => $request->host, |
||
| 132 | // 'mail.port' => $request->port, |
||
| 133 | // 'mail.encryption' => $request->encryption, |
||
| 134 | // 'mail.username' => $request->username, |
||
| 135 | // ]); |
||
| 136 | |||
| 137 | Config::set('mail.host', $request->host); |
||
| 138 | |||
| 139 | |||
| 140 | // |
||
| 141 | // echo config('mail.host'); |
||
| 142 | // die(); |
||
| 143 | |||
| 144 | if(!empty($request->password)) |
||
| 145 | { |
||
| 146 | config(['mail.password' => $request->password]); |
||
| 147 | } |
||
| 148 | |||
| 149 | // Try and send the test email |
||
| 150 | try |
||
| 151 | { |
||
| 152 | // Log::info('Test Email Successfully Sent to '.Auth::user()->email); |
||
| 153 | Log::info(config('mail.host')); |
||
| 154 | Mail::to(Auth::user()->email)->send(new TestEmail()); |
||
| 155 | // return 'success'; |
||
| 156 | return response()->json([ |
||
| 157 | 'success' => true, |
||
| 158 | 'sentTo' => Auth::user()->email |
||
| 159 | ]); |
||
| 160 | } |
||
| 161 | catch(Exception $e) |
||
|
|
|||
| 162 | { |
||
| 163 | Log::notice('Test Email Failed. Message: '.$e); |
||
| 164 | $msg = '['.$e->getCode().'] "'.$e->getMessage().'" on line '.$e->getTrace()[0]['line'].' of file '.$e->getTrace()[0]['file']; |
||
| 165 | // return $msg; |
||
| 166 | return response()->json(['message' => $msg]); |
||
| 167 | } |
||
| 176 |