Conditions | 6 |
Paths | 24 |
Total Lines | 58 |
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 |
||
97 | public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { |
||
98 | $userId = $user->getUID(); |
||
99 | $lang = $this->config->getUserValue($userId, 'core', 'lang', 'en'); |
||
100 | if (!$this->l10nFactory->languageExists('settings', $lang)) { |
||
101 | $lang = 'en'; |
||
102 | } |
||
103 | |||
104 | $l10n = $this->l10nFactory->get('settings', $lang); |
||
105 | |||
106 | if ($generatePasswordResetToken) { |
||
107 | $token = $this->secureRandom->generate( |
||
108 | 21, |
||
109 | ISecureRandom::CHAR_DIGITS . |
||
110 | ISecureRandom::CHAR_LOWER . |
||
111 | ISecureRandom::CHAR_UPPER |
||
112 | ); |
||
113 | $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
||
114 | $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
||
115 | $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
||
116 | $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
||
117 | $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
||
118 | } else { |
||
119 | $link = $this->urlGenerator->getAbsoluteURL('/'); |
||
120 | } |
||
121 | $displayName = $user->getDisplayName(); |
||
122 | |||
123 | $emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [ |
||
124 | 'link' => $link, |
||
125 | 'displayname' => $displayName, |
||
126 | 'userid' => $userId, |
||
127 | 'instancename' => $this->themingDefaults->getName(), |
||
128 | 'resetTokenGenerated' => $generatePasswordResetToken, |
||
129 | ]); |
||
130 | |||
131 | $emailTemplate->setSubject($l10n->t('Your %s account was created', [$this->themingDefaults->getName()])); |
||
132 | $emailTemplate->addHeader(); |
||
133 | if ($displayName === $userId) { |
||
134 | $emailTemplate->addHeading($l10n->t('Welcome aboard')); |
||
135 | } else { |
||
136 | $emailTemplate->addHeading($l10n->t('Welcome aboard %s', [$displayName])); |
||
137 | } |
||
138 | $emailTemplate->addBodyText($l10n->t('Welcome to your %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); |
||
139 | $emailTemplate->addBodyText($l10n->t('Your username is: %s', [$userId])); |
||
140 | if ($generatePasswordResetToken) { |
||
141 | $leftButtonText = $l10n->t('Set your password'); |
||
142 | } else { |
||
143 | $leftButtonText = $l10n->t('Go to %s', [$this->themingDefaults->getName()]); |
||
144 | } |
||
145 | $emailTemplate->addBodyButtonGroup( |
||
146 | $leftButtonText, |
||
147 | $link, |
||
148 | $l10n->t('Install Client'), |
||
149 | 'https://nextcloud.com/install/#install-clients' |
||
150 | ); |
||
151 | $emailTemplate->addFooter(); |
||
152 | |||
153 | return $emailTemplate; |
||
154 | } |
||
155 | |||
172 |