Conditions | 12 |
Paths | 73 |
Total Lines | 82 |
Code 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 |
||
76 | public function saveInDB($data) { |
||
77 | $errorMessage = ''; |
||
78 | $userName = $GLOBALS['mapisession']->getSMTPAddress(); |
||
79 | $newPassword = $data['new_password']; |
||
80 | |||
81 | // When a session password is available it may not correspond to the user's |
||
82 | // actual password (e.g. when authenticated via grommunio-auth/Keycloak). We rely |
||
83 | // on the backend to verify the provided current password instead of validating it |
||
84 | // against the session value. |
||
85 | if (defined('PLUGIN_PASSWD_USE_ZCORE') && PLUGIN_PASSWD_USE_ZCORE) { |
||
86 | try { |
||
87 | $result = nsp_setuserpasswd($userName, $data['current_password'], $newPassword); |
||
88 | // password changed successfully |
||
89 | if ($result) { |
||
90 | $this->sendFeedback(true, [ |
||
91 | 'info' => [ |
||
92 | 'display_message' => _('Password is changed successfully.'), |
||
93 | ], |
||
94 | ]); |
||
95 | // write new password to session because we don't want user to re-authenticate |
||
96 | session_start(); |
||
97 | $encryptionStore = EncryptionStore::getInstance(); |
||
98 | $encryptionStore->add('password', $newPassword); |
||
99 | session_write_close(); |
||
100 | |||
101 | return; |
||
102 | } |
||
103 | } |
||
104 | catch (MAPIException) { |
||
105 | if (mapi_last_hresult() == MAPI_E_NO_ACCESS) { |
||
106 | $errorMessage = _('Your password is wrong or you have insufficient permission to change password'); |
||
107 | } |
||
108 | } |
||
109 | if (empty($errorMessage)) { |
||
110 | $errorMessage = _('Password is not changed.'); |
||
111 | } |
||
112 | } |
||
113 | else { |
||
114 | $url = (defined('PLUGIN_PASSWD_ADMIN_API_ENDPOINT') && PLUGIN_PASSWD_ADMIN_API_ENDPOINT) ? |
||
115 | PLUGIN_PASSWD_ADMIN_API_ENDPOINT : |
||
116 | 'http://[::1]:8080/api/v1/passwd'; |
||
117 | $result = file_get_contents($url, false, stream_context_create([ |
||
118 | 'http' => [ |
||
119 | 'header' => [ |
||
120 | 'Content-type: application/json', |
||
121 | ], |
||
122 | 'method' => 'PUT', |
||
123 | 'content' => json_encode([ |
||
124 | "user" => $userName, |
||
125 | "old" => $data['current_password'], |
||
126 | "new" => $newPassword, |
||
127 | ]), |
||
128 | ], |
||
129 | ])); |
||
130 | |||
131 | if ($result === false) { |
||
132 | $errorMessage = _('Error changing password. Please verify your password or contact the system administrator.'); |
||
133 | } |
||
134 | else { |
||
135 | $this->sendFeedback(true, [ |
||
136 | 'info' => [ |
||
137 | 'display_message' => _('Password has been changed successfully.'), |
||
138 | ], |
||
139 | ]); |
||
140 | // write new password to session because we don't want user to re-authenticate |
||
141 | session_start(); |
||
142 | $encryptionStore = EncryptionStore::getInstance(); |
||
143 | $encryptionStore->add('password', $newPassword); |
||
144 | session_write_close(); |
||
145 | |||
146 | return; |
||
147 | } |
||
148 | if (empty($errorMessage)) { |
||
149 | $errorMessage = _('Password is not changed.'); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | if (!empty($errorMessage)) { |
||
154 | $this->sendFeedback(false, [ |
||
155 | 'type' => ERROR_ZARAFA, |
||
156 | 'info' => [ |
||
157 | 'display_message' => $errorMessage, |
||
158 | ], |
||
163 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.