| Conditions | 10 |
| Paths | 14 |
| Total Lines | 37 |
| Code Lines | 26 |
| Lines | 10 |
| Ratio | 27.03 % |
| 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 |
||
| 106 | private function requireAdminAuth() { |
||
| 107 | $adminusers = $this->config->getSecret('admin_users'); |
||
| 108 | if ($this->requireAdminAuthAdminHome && (empty($adminusers) || !count($adminusers))) { |
||
| 109 | return true; |
||
| 110 | } elseif (count($adminusers) { |
||
|
|
|||
| 111 | $user = filter_input(INPUT_SERVER, 'PHP_AUTH_USER'); |
||
| 112 | $pass = filter_input(INPUT_SERVER, 'PHP_AUTH_PW'); |
||
| 113 | if (filter_input(INPUT_SERVER, 'REDIRECT_HTTP_AUTHORIZATION') !== null) { // fix for php cgi mode |
||
| 114 | list($user, $pass) = explode(':' , base64_decode(substr(filter_input(INPUT_SERVER, 'REDIRECT_HTTP_AUTHORIZATION'), 6))); |
||
| 115 | } |
||
| 116 | |||
| 117 | if (!empty($user) && !empty($pass)) { |
||
| 118 | $validated = !empty( |
||
| 119 | $adminusers[$user]) |
||
| 120 | && password_verify($pass, $adminusers[$user] |
||
| 121 | ); |
||
| 122 | } else { |
||
| 123 | $validated = false; |
||
| 124 | } |
||
| 125 | |||
| 126 | if (!$validated) { |
||
| 127 | header('WWW-Authenticate: Basic realm="'.$this->config->getSecret('admin_authrealm').'"'); |
||
| 128 | header('HTTP/1.0 401 Unauthorized'); |
||
| 129 | $this->helper->terminateScript('Not authorized'); |
||
| 130 | } |
||
| 131 | |||
| 132 | } else { |
||
| 133 | header('WWW-Authenticate: Basic realm="'.$this->config->getSecret('admin_authrealm').'"'); |
||
| 134 | header('HTTP/1.0 401 Unauthorized'); |
||
| 135 | $this->helper->terminateScript('Not authorized'); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 |