Conditions | 7 |
Paths | 4 |
Total Lines | 56 |
Code Lines | 34 |
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 |
||
69 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
70 | { |
||
71 | $username = $request->getQueryParams()['username'] ?? ''; |
||
72 | $token = $request->getQueryParams()['token'] ?? ''; |
||
73 | |||
74 | $title = I18N::translate('User verification'); |
||
75 | |||
76 | $user = $this->user_service->findByUserName($username); |
||
77 | |||
78 | if ($user instanceof User && $user->getPreference('reg_hashcode') === $token) { |
||
79 | foreach ($this->user_service->administrators() as $administrator) { |
||
80 | // switch language to administrator settings |
||
81 | I18N::init($administrator->getPreference('language')); |
||
82 | |||
83 | $base_url = $request->getAttribute('base_url'); |
||
84 | |||
85 | /* I18N: %s is a server name/URL */ |
||
86 | $subject = I18N::translate('New user at %s', $base_url); |
||
87 | |||
88 | $this->mail_service->send( |
||
89 | new SiteUser(), |
||
90 | $administrator, |
||
91 | new NoReplyUser(), |
||
92 | $subject, |
||
93 | view('emails/verify-notify-text', ['user' => $user]), |
||
94 | view('emails/verify-notify-html', ['user' => $user]) |
||
95 | ); |
||
96 | |||
97 | $mail1_method = $administrator->getPreference('CONTACT_METHOD'); |
||
98 | |||
99 | if ($mail1_method !== 'messaging3' && $mail1_method !== 'mailto' && $mail1_method !== 'none') { |
||
100 | DB::table('message')->insert([ |
||
101 | 'sender' => $username, |
||
102 | 'ip_address' => $request->getAttribute('client_ip'), |
||
103 | 'user_id' => $administrator->id(), |
||
104 | 'subject' => $subject, |
||
105 | 'body' => view('emails/verify-notify-text', ['user' => $user]), |
||
106 | ]); |
||
107 | } |
||
108 | I18N::init(WT_LOCALE); |
||
109 | } |
||
110 | |||
111 | $user |
||
112 | ->setPreference('verified', '1') |
||
113 | ->setPreference('reg_timestamp', date('U')) |
||
114 | ->setPreference('reg_hashcode', ''); |
||
115 | |||
116 | Log::addAuthenticationLog('User ' . $username . ' verified their email address'); |
||
117 | |||
118 | return $this->viewResponse('verify-success-page', [ |
||
119 | 'title' => $title, |
||
120 | ]); |
||
121 | } |
||
122 | |||
123 | return $this->viewResponse('verify-failure-page', [ |
||
124 | 'title' => $title, |
||
125 | ]); |
||
128 |