| Conditions | 7 |
| Paths | 12 |
| Total Lines | 51 |
| Code Lines | 39 |
| 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 |
||
| 33 | public static function sendEmail($type, $email, $userData, $data){ |
||
| 34 | |||
| 35 | $mail = new PHPMailer(); |
||
| 36 | $mail->IsSMTP(); |
||
| 37 | |||
| 38 | // good for debugging, otherwise keep it commented |
||
| 39 | // $mail->SMTPDebug = EMAIL_SMTP_DEBUG; |
||
| 40 | $mail->SMTPAuth = Config::get('EMAIL_SMTP_AUTH'); |
||
| 41 | $mail->SMTPSecure = Config::get('EMAIL_SMTP_SECURE'); |
||
| 42 | $mail->Host = Config::get('EMAIL_SMTP_HOST'); |
||
| 43 | $mail->Port = Config::get('EMAIL_SMTP_PORT'); |
||
| 44 | $mail->Username = Config::get('EMAIL_SMTP_USERNAME'); |
||
| 45 | $mail->Password = Config::get('EMAIL_SMTP_PASSWORD'); |
||
| 46 | |||
| 47 | $mail->SetFrom(Config::get('EMAIL_FROM'), Config::get('EMAIL_FROM_NAME')); |
||
| 48 | $mail->AddReplyTo(Config::get('EMAIL_REPLY_TO')); |
||
| 49 | |||
| 50 | switch($type){ |
||
| 51 | case (Config::get('EMAIL_EMAIL_VERIFICATION')): |
||
| 52 | $mail->Body = self::getEmailVerificationBody($userData, $data); |
||
| 53 | $mail->Subject = Config::get('EMAIL_EMAIL_VERIFICATION_SUBJECT'); |
||
| 54 | $mail->AddAddress($email); |
||
| 55 | break; |
||
| 56 | case (Config::get('EMAIL_REVOKE_EMAIL')): |
||
| 57 | $mail->Body = self::getRevokeEmailBody($userData, $data); |
||
| 58 | $mail->Subject = Config::get('EMAIL_REVOKE_EMAIL_SUBJECT'); |
||
| 59 | $mail->AddAddress($email); |
||
| 60 | break; |
||
| 61 | case (Config::get('EMAIL_UPDATE_EMAIL')): |
||
| 62 | $mail->Body = self::getUpdateEmailBody($userData, $data); |
||
| 63 | $mail->Subject = Config::get('EMAIL_UPDATE_EMAIL_SUBJECT'); |
||
| 64 | $mail->AddAddress($email); |
||
| 65 | break; |
||
| 66 | case (Config::get('EMAIL_PASSWORD_RESET')): |
||
| 67 | $mail->Body = self::getPasswordResetBody($userData, $data); |
||
| 68 | $mail->Subject = Config::get('EMAIL_PASSWORD_RESET_SUBJECT'); |
||
| 69 | $mail->AddAddress($email); |
||
| 70 | break; |
||
| 71 | case (Config::get('EMAIL_REPORT_BUG')): |
||
| 72 | $mail->Body = self::getReportBugBody($userData, $data); |
||
| 73 | $mail->Subject = "[".ucfirst($data["label"])."] " . Config::get('EMAIL_REPORT_BUG_SUBJECT') . " | " . $data["subject"]; |
||
| 74 | $mail->AddAddress($email); |
||
| 75 | break; |
||
| 76 | } |
||
| 77 | |||
| 78 | // If you don't have an email setup, you can instead save emails in log.txt file using Logger. |
||
| 79 | // Logger::log("EMAIL", $mail->Body); |
||
| 80 | if(!$mail->Send()) { |
||
| 81 | throw new Exception("Email couldn't be sent to ". $userData["id"] ." for type: ". $type); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 190 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.