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