| Conditions | 2 |
| Paths | 9 |
| Total Lines | 64 |
| Code Lines | 43 |
| 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 |
||
| 58 | public function notifyUser(EmailChangedEvent $event): void |
||
| 59 | { |
||
| 60 | $user = $event->getUser(); |
||
| 61 | $oldEmail = $event->getOldEmail(); |
||
| 62 | $newEmail = $event->getNewEmail(); |
||
| 63 | |||
| 64 | $this->logger->debug('Sending email change notifications', [ |
||
| 65 | 'user_id' => $user->getId(), |
||
| 66 | 'username' => $user->getUsername() |
||
| 67 | ]); |
||
| 68 | |||
| 69 | try { |
||
| 70 | $locale = $user->getLanguage(); |
||
| 71 | |||
| 72 | // Email to old email |
||
| 73 | $oldEmailBody = $this->translator->trans( |
||
| 74 | 'email_change.notification_old_email', |
||
| 75 | [ |
||
| 76 | '%username%' => $user->getUsername(), |
||
| 77 | '%old_email%' => $oldEmail, |
||
| 78 | '%new_email%' => $newEmail |
||
| 79 | ], |
||
| 80 | 'email', |
||
| 81 | $locale |
||
| 82 | ); |
||
| 83 | |||
| 84 | $emailToOld = (new Email()) |
||
| 85 | ->to($oldEmail) |
||
| 86 | ->subject($this->translator->trans('email_change.subject', [], 'email', $locale)) |
||
| 87 | ->text($oldEmailBody) |
||
| 88 | ->html($oldEmailBody); |
||
| 89 | |||
| 90 | $this->mailer->send($emailToOld); |
||
| 91 | |||
| 92 | // Email to new email |
||
| 93 | $newEmailBody = $this->translator->trans( |
||
| 94 | 'email_change.notification_new_email', |
||
| 95 | [ |
||
| 96 | '%username%' => $user->getUsername(), |
||
| 97 | '%old_email%' => $oldEmail, |
||
| 98 | '%new_email%' => $newEmail |
||
| 99 | ], |
||
| 100 | 'email', |
||
| 101 | $locale |
||
| 102 | ); |
||
| 103 | |||
| 104 | $emailToNew = (new Email()) |
||
| 105 | ->to($newEmail) |
||
| 106 | ->subject($this->translator->trans('email_change.subject', [], 'email', $locale)) |
||
| 107 | ->text($newEmailBody) |
||
| 108 | ->html($newEmailBody); |
||
| 109 | |||
| 110 | $this->mailer->send($emailToNew); |
||
| 111 | |||
| 112 | $this->logger->info('Email change notifications sent successfully', [ |
||
| 113 | 'user_id' => $user->getId(), |
||
| 114 | 'username' => $user->getUsername() |
||
| 115 | ]); |
||
| 116 | } catch (\Exception $e) { |
||
| 117 | $this->logger->error('Error sending email change notifications', [ |
||
| 118 | 'user_id' => $user->getId(), |
||
| 119 | 'username' => $user->getUsername(), |
||
| 120 | 'error' => $e->getMessage(), |
||
| 121 | 'trace' => $e->getTraceAsString() |
||
| 122 | ]); |
||
| 126 |