| Conditions | 4 |
| Paths | 3 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 45 | public function resetaccount(HTTPRequest $request) |
||
| 46 | { |
||
| 47 | if (Security::getCurrentUser()) { |
||
| 48 | $output = $this->owner->renderWith( |
||
| 49 | 'Security', |
||
| 50 | [ |
||
| 51 | 'Title' => _t( |
||
| 52 | __CLASS__ . '.ALREADYAUTHENTICATEDTITLE', |
||
| 53 | 'Already authenticated' |
||
| 54 | ), |
||
| 55 | 'Content' => _t( |
||
| 56 | __CLASS__ . '.ALREADYAUTHENTICATEDBODY', |
||
| 57 | 'You must be logged out to reset your account.' |
||
| 58 | ), |
||
| 59 | ] |
||
| 60 | ); |
||
| 61 | return $this->owner->getResponse()->setBody($output)->setStatusCode(400); |
||
| 62 | } |
||
| 63 | |||
| 64 | $vars = $request->getVars(); |
||
| 65 | |||
| 66 | /** @var Member|MemberExtension $member */ |
||
| 67 | $member = Member::get()->byID(intval($vars['m'] ?? 0)); |
||
| 68 | |||
| 69 | if (is_null($member) || $member->verifyAccountResetToken($vars['t'] ?? '') === false) { |
||
| 70 | $output = $this->owner->renderWith( |
||
| 71 | 'Security', |
||
| 72 | [ |
||
| 73 | 'Title' => _t( |
||
| 74 | __CLASS__ . '.INVALIDTOKENTITLE', |
||
| 75 | 'Invalid member or token' |
||
| 76 | ), |
||
| 77 | 'Content' => _t( |
||
| 78 | __CLASS__ . '.INVALIDTOKENBODY', |
||
| 79 | 'Your account reset token may have expired. Please contact an administrator.' |
||
| 80 | ) |
||
| 81 | ] |
||
| 82 | ); |
||
| 83 | return $this->owner->getResponse()->setBody($output)->setStatusCode(400); |
||
| 84 | } |
||
| 85 | |||
| 86 | $request->getSession()->set('MemberID', $member->ID); |
||
| 87 | |||
| 88 | return $this->owner->getResponse()->setBody($this->owner->renderWith( |
||
| 89 | 'Security', |
||
| 90 | [ |
||
| 91 | 'Title' => _t( |
||
| 92 | __CLASS__ . '.ACCOUNT_RESET_TITLE', |
||
| 93 | 'Reset account' |
||
| 94 | ), |
||
| 95 | 'Message' => _t( |
||
| 96 | __CLASS__ . '.ACCOUNT_RESET_DESCRIPTION', |
||
| 97 | 'Your password will be changed, and any registered MFA methods will be removed.' |
||
| 98 | ), |
||
| 99 | 'Form' => $this->ResetAccountForm(), |
||
| 100 | ] |
||
| 207 |