Conditions | 5 |
Paths | 4 |
Total Lines | 51 |
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 |
||
23 | protected function main() |
||
24 | { |
||
25 | $this->setHtmlTitle('Preferences'); |
||
26 | |||
27 | $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
||
28 | $database = $this->getDatabase(); |
||
29 | $user = User::getCurrent($database); |
||
30 | |||
31 | // Dual mode |
||
32 | if (WebRequest::wasPosted()) { |
||
33 | $this->validateCSRFToken(); |
||
34 | $user->setWelcomeSig(WebRequest::postString('sig')); |
||
35 | $user->setEmailSig(WebRequest::postString('emailsig')); |
||
36 | $user->setAbortPref(WebRequest::getBoolean('sig') ? 1 : 0); |
||
37 | $this->setCreationMode($user); |
||
38 | |||
39 | $email = WebRequest::postEmail('email'); |
||
40 | if ($email !== null) { |
||
41 | $user->setEmail($email); |
||
42 | } |
||
43 | |||
44 | $user->save(); |
||
45 | SessionAlert::success("Preferences updated!"); |
||
46 | |||
47 | $this->redirect(''); |
||
48 | } |
||
49 | else { |
||
50 | $this->assignCSRFToken(); |
||
51 | $this->setTemplate('preferences/prefs.tpl'); |
||
52 | $this->assign("enforceOAuth", $enforceOAuth); |
||
53 | |||
54 | $this->assign('canManualCreate', |
||
55 | $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
||
56 | $this->assign('canOauthCreate', |
||
57 | $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
||
58 | $this->assign('canBotCreate', |
||
59 | $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
||
60 | |||
61 | $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
||
62 | $this->getSiteConfiguration()); |
||
63 | $this->assign('oauth', $oauth); |
||
64 | |||
65 | $identity = null; |
||
66 | if ($oauth->isFullyLinked()) { |
||
67 | $identity = $oauth->getIdentity(); |
||
68 | } |
||
69 | |||
70 | $this->assign('identity', $identity); |
||
71 | $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
||
72 | } |
||
73 | } |
||
74 | |||
89 |