| Conditions | 12 |
| Paths | 96 |
| Total Lines | 55 |
| Code Lines | 31 |
| 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 |
||
| 103 | protected function triggerBasicAuthProtection() |
||
| 104 | { |
||
| 105 | $allowWithoutAuth = false; |
||
| 106 | |||
| 107 | // Allow whitelisting IPs for bypassing the basic auth. |
||
| 108 | if (Environment::getEnv('CWP_IP_BYPASS_BASICAUTH')) { |
||
| 109 | $remote = $_SERVER['REMOTE_ADDR']; |
||
| 110 | $bypass = explode(',', Environment::getEnv('CWP_IP_BYPASS_BASICAUTH')); |
||
| 111 | |||
| 112 | if (in_array($remote, $bypass)) { |
||
| 113 | $allowWithoutAuth = true; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | // First, see if we can get a member to act on, either from a changepassword token or the session |
||
| 118 | if (isset($_REQUEST['m']) && isset($_REQUEST['t'])) { |
||
| 119 | $member = Member::get()->filter('ID', (int) $_REQUEST['m'])->first(); |
||
| 120 | |||
| 121 | if (!$member->validateAutoLoginToken($_REQUEST['t'])) { |
||
| 122 | $member = null; |
||
| 123 | } |
||
| 124 | } elseif ($this->owner->getRequest()->getSession()->get('AutoLoginHash')) { |
||
| 125 | $member = Member::member_from_autologinhash( |
||
| 126 | $this->owner->getRequest()->getSession()->get('AutoLoginHash') |
||
| 127 | ); |
||
| 128 | } else { |
||
| 129 | $member = Security::getCurrentUser(); |
||
| 130 | } |
||
| 131 | |||
| 132 | // Then, if they have the right permissions, check the allowed URLs |
||
| 133 | $existingMemberCanAccessUAT = $member && $this->callWithSubsitesDisabled(function () use ($member) { |
||
| 134 | return Permission::checkMember($member, 'ACCESS_UAT_SERVER'); |
||
| 135 | }); |
||
| 136 | |||
| 137 | if ($existingMemberCanAccessUAT) { |
||
| 138 | $allowed = array( |
||
| 139 | '/^Security\/changepassword/', |
||
| 140 | '/^Security\/ChangePasswordForm/' |
||
| 141 | ); |
||
| 142 | |||
| 143 | $relativeURL = Director::makeRelative(Director::absoluteURL($_SERVER['REQUEST_URI'])); |
||
| 144 | |||
| 145 | foreach ($allowed as $pattern) { |
||
| 146 | $allowWithoutAuth = $allowWithoutAuth || preg_match($pattern, $relativeURL); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | // Finally if they weren't allowed to bypass Basic Auth, trigger it |
||
| 151 | if (!$allowWithoutAuth) { |
||
| 152 | $this->callWithSubsitesDisabled(function () { |
||
| 153 | BasicAuth::requireLogin( |
||
| 154 | $this->owner->getRequest(), |
||
| 155 | _t(__CLASS__ . '.LoginPrompt', "Please log in with your CMS credentials"), |
||
| 156 | 'ACCESS_UAT_SERVER', |
||
| 157 | true |
||
| 158 | ); |
||
| 212 |
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