| Conditions | 21 |
| Paths | 265 |
| Total Lines | 110 |
| Code Lines | 86 |
| Lines | 11 |
| Ratio | 10 % |
| 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 |
||
| 70 | private static function sendNotificationMail($username) { |
||
| 71 | $userObject = \OC::$server->getUserManager()->get($username); |
||
| 72 | $email = $userObject->getEMailAddress(); |
||
| 73 | $defaults = new \OC_Defaults(); |
||
| 74 | $from = \OCP\Util::getDefaultEmailAddress('lostpassword-noreply'); |
||
| 75 | $mailer = \OC::$server->getMailer(); |
||
| 76 | $lion = \OC::$server->getL10N('lib'); |
||
| 77 | |||
| 78 | if ($email !== null && $email !== '') { |
||
| 79 | $tmpl = new \OC_Template('core', 'lostpassword/notify'); |
||
| 80 | $msg = $tmpl->fetchPage(); |
||
| 81 | |||
| 82 | try { |
||
| 83 | $message = $mailer->createMessage(); |
||
| 84 | $message->setTo([$email => $username]); |
||
| 85 | $message->setSubject($lion->t('%s password changed successfully', [$defaults->getName()])); |
||
| 86 | $message->setPlainBody($msg); |
||
| 87 | $message->setFrom([$from => $defaults->getName()]); |
||
| 88 | $mailer->send($message); |
||
| 89 | } catch (\Exception $e) { |
||
| 90 | throw new \Exception($lion->t( |
||
| 91 | 'Couldn\'t send reset email. Please contact your administrator.' |
||
| 92 | )); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.