Conditions | 25 |
Paths | 1216 |
Total Lines | 169 |
Code Lines | 107 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
33 | function change($content = null) |
||
34 | { |
||
35 | if ($GLOBALS['egw']->acl->check('nopasswordchange', 1)) |
||
36 | { |
||
37 | Framework::window_close('Password change is disabled!'); |
||
38 | } |
||
39 | $GLOBALS['egw_info']['flags']['app_header'] = lang('Change your password'); |
||
40 | $tmpl = new Etemplate('preferences.password'); |
||
41 | |||
42 | $readonlys = $sel_options = []; |
||
43 | try { |
||
44 | // PHP 7.1+: using SVG image backend (requiring XMLWriter) and not ImageMagic extension |
||
45 | if (class_exists('BaconQrCode\Renderer\Image\SvgImageBackEnd')) |
||
46 | { |
||
47 | $image_backend = new \BaconQrCode\Renderer\Image\SvgImageBackEnd; |
||
48 | } |
||
49 | $google2fa = new Google2FA($image_backend); |
||
50 | $prefs = new Api\Preferences($GLOBALS['egw_info']['user']['account_id']); |
||
51 | $prefs->read_repository(); |
||
52 | |||
53 | if (!is_array($content)) |
||
54 | { |
||
55 | $content = []; |
||
56 | $content['2fa'] = $this->generateQRCode($google2fa)+[ |
||
57 | 'gauth_android' => self::GAUTH_ANDROID, |
||
58 | 'gauth_ios' => self::GAUTH_IOS, |
||
59 | ]; |
||
60 | } |
||
61 | else |
||
62 | { |
||
63 | $secret_key = $content['2fa']['secret_key']; |
||
64 | unset($content['2fa']['secret_key']); |
||
65 | |||
66 | switch($content['tabs']) |
||
67 | { |
||
68 | case 'change_password': |
||
69 | if ($content['button']['save']) |
||
70 | { |
||
71 | if (($errors = self::do_change($content['password'], $content['n_passwd'], $content['n_passwd_2']))) |
||
72 | { |
||
73 | Framework::message(implode("\n", $errors), 'error'); |
||
74 | $content = array(); |
||
75 | } |
||
76 | else |
||
77 | { |
||
78 | Framework::refresh_opener(lang('Password changed'), 'preferences'); |
||
79 | Framework::window_close(); |
||
80 | } |
||
81 | } |
||
82 | break; |
||
83 | |||
84 | case 'two_factor_auth': |
||
85 | $auth = new Api\Auth(); |
||
86 | if (!$auth->authenticate($GLOBALS['egw_info']['user']['account_lid'], $content['password'])) |
||
87 | { |
||
88 | $tmpl->set_validation_error('password', lang('Password is invalid'), '2fa'); |
||
89 | break; |
||
90 | } |
||
91 | switch(key($content['2fa']['action'])) |
||
92 | { |
||
93 | case 'show': |
||
94 | $content['2fa'] = $this->generateQRCode($google2fa, false); |
||
95 | break; |
||
96 | case 'reset': |
||
97 | $content['2fa'] = $this->generateQRCode($google2fa, true); |
||
98 | Framework::message(lang('New secret generated, you need to save it to disable the old one!')); |
||
99 | break; |
||
100 | case 'disable': |
||
101 | if (Credentials::delete(0, $GLOBALS['egw_info']['user']['account_id'], Credentials::TWOFA)) |
||
102 | { |
||
103 | Framework::refresh_opener(lang('Secret deleted, two factor authentication disabled.'), 'preferences'); |
||
104 | Framework::window_close(); |
||
105 | } |
||
106 | else |
||
107 | { |
||
108 | Framework::message(lang('Failed to delete secret!'), 'error'); |
||
109 | } |
||
110 | break; |
||
111 | default: // no action, save secret |
||
112 | if (!$google2fa->verifyKey($secret_key, $content['2fa']['code'])) |
||
113 | { |
||
114 | $tmpl->set_validation_error('code', lang('Code is invalid'), '2fa'); |
||
115 | break 2; |
||
116 | } |
||
117 | if (($content['2fa']['cred_id'] = Credentials::write(0, |
||
118 | $GLOBALS['egw_info']['user']['account_lid'], |
||
119 | $secret_key, Credentials::TWOFA, |
||
120 | $GLOBALS['egw_info']['user']['account_id'], |
||
121 | $content['2fa']['cred_id']))) |
||
122 | { |
||
123 | Framework::refresh_opener(lang('Two Factor Auth enabled.'), 'preferences'); |
||
124 | Framework::window_close(); |
||
125 | } |
||
126 | else |
||
127 | { |
||
128 | Framework::message(lang('Failed to store secret!'), 'error'); |
||
129 | } |
||
130 | break; |
||
131 | } |
||
132 | unset($content['2fa']['action']); |
||
133 | break; |
||
134 | |||
135 | case 'tokens': |
||
136 | if (is_array($content) && $content['nm']['selected']) |
||
137 | { |
||
138 | try { |
||
139 | switch($content['nm']['action']) |
||
140 | { |
||
141 | case 'delete': |
||
142 | $token_repo = new AccessTokenRepository(); |
||
143 | $token_repo->revokeAccessToken(['access_token_id' => $content['nm']['selected']]); |
||
144 | $refresh_token_repo = new RefreshTokenRepository(); |
||
145 | $refresh_token_repo->revokeRefreshToken(['access_token_id' => $content['nm']['selected']]); |
||
146 | $msg = (count($content['nm']['selected']) > 1 ? |
||
147 | count($content['nm']['selected']).' ' : ''). |
||
148 | lang('Access Token revoked.'); |
||
149 | break; |
||
150 | } |
||
151 | } |
||
152 | catch(\Exception $e) { |
||
153 | $msg = lang('Error').': '.$e->getMessage(); |
||
154 | break; |
||
155 | } |
||
156 | } |
||
157 | break; |
||
158 | } |
||
159 | } |
||
160 | } |
||
161 | catch (Exception $e) { |
||
162 | Framework::message($e->getMessage(), 'error'); |
||
163 | } |
||
164 | |||
165 | // display tokens, if we have openid installed (currently no run-rights needed!) |
||
166 | if ($GLOBALS['egw_info']['apps']['openid'] && class_exists(AccessTokenRepository::class)) |
||
167 | { |
||
168 | $content['nm'] = [ |
||
169 | 'get_rows' => 'preferences.'.__CLASS__.'.getTokens', |
||
170 | 'no_cat' => true, |
||
171 | 'no_filter' => true, |
||
172 | 'no_filter2' => true, |
||
173 | 'filter_no_lang' => true, |
||
174 | 'order' => 'access_token_updated', |
||
175 | 'sort' => 'DESC', |
||
176 | 'row_id' => 'access_token_id', |
||
177 | 'default_cols' => '!client_id', |
||
178 | 'actions' => self::tokenActions(), |
||
179 | ]; |
||
180 | $sel_options += [ |
||
181 | 'client_status' => ['Disabled', 'Active'], |
||
182 | 'access_token_revoked' => ['Active', 'Revoked'], |
||
183 | 'access_token_scopes' => (new ScopeRepository())->selOptions(), |
||
184 | ]; |
||
185 | } |
||
186 | else |
||
187 | { |
||
188 | $readonlys['tabs']['tokens'] = true; |
||
189 | } |
||
190 | |||
191 | // disable 2FA tab, if admin disabled it |
||
192 | if ($GLOBALS['egw_info']['server']['2fa_required'] === 'disabled') |
||
193 | { |
||
194 | $readonlys['tabs']['two_factor_auth'] = true; |
||
195 | } |
||
196 | |||
197 | $tmpl->exec('preferences.preferences_password.change', $content, $sel_options, $readonlys, [ |
||
198 | '2fa' => $content['2fa']+[ |
||
199 | 'secret_key' => $secret_key, |
||
200 | ], |
||
201 | ], 2); |
||
202 | } |
||
360 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths