| Conditions | 10 |
| Paths | 13 |
| Total Lines | 59 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 114 | public function process(array &$state): void |
||
| 115 | { |
||
| 116 | if (!array_key_exists($this->stateData->usernameAttrib, $state['Attributes'])) { |
||
| 117 | Logger::warning('webauthn: cannot determine if user needs second factor, missing attribute "' . |
||
| 118 | $this->stateData->usernameAttrib . '".'); |
||
| 119 | return; |
||
| 120 | } |
||
| 121 | |||
| 122 | $state['saml:AuthnContextClassRef'] = $this->authnContextClassRef ?? |
||
| 123 | 'urn:rsa:names:tc:SAML:2.0:ac:classes:FIDO'; |
||
| 124 | Logger::debug('webauthn: userid: ' . $state['Attributes'][$this->stateData->usernameAttrib][0]); |
||
| 125 | |||
| 126 | $localToggle = !empty($state['Attributes'][$this->toggleAttrib]) && |
||
| 127 | !empty($state['Attributes'][$this->toggleAttrib][0]); |
||
| 128 | |||
| 129 | if ( |
||
| 130 | $this->stateData->store->is2FAEnabled( |
||
| 131 | $state['Attributes'][$this->stateData->usernameAttrib][0], |
||
| 132 | $this->defaultEnabled, |
||
| 133 | $this->useDatabase, |
||
| 134 | $localToggle, |
||
| 135 | $this->force, |
||
| 136 | ) === false |
||
| 137 | ) { |
||
| 138 | // nothing to be done here, end authprocfilter processing |
||
| 139 | return; |
||
| 140 | } |
||
| 141 | |||
| 142 | if // did we do Passwordless mode successfully before? |
||
| 143 | ( |
||
| 144 | isset($state['Attributes']['internal:FIDO2PasswordlessAuthentication']) && |
||
| 145 | // phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 146 | $state['Attributes']['internal:FIDO2PasswordlessAuthentication'][0] == $state['Attributes'][$this->stateData->usernameAttrib][0] |
||
| 147 | ) { |
||
| 148 | // then no need to trigger a second 2-Factor via authproc |
||
| 149 | // just delete the internal attribute then |
||
| 150 | unset($state['Attributes']['internal:FIDO2PasswordlessAuthentication']); |
||
| 151 | return; |
||
| 152 | } |
||
| 153 | $session = Session::getSessionFromRequest(); |
||
| 154 | $lastSecondFactor = $session->getData("DateTime", 'LastSuccessfulSecondFactor'); |
||
| 155 | if // do we need to do secondFactor in interval, or even every time? |
||
| 156 | // we skip only if an interval is configured AND we did successfully authenticate, |
||
| 157 | // AND are within the interval |
||
| 158 | ( |
||
| 159 | $this->SecondFactorMaxAge >= 0 && $lastSecondFactor instanceof \DateTime |
||
| 160 | ) { |
||
| 161 | $interval = $lastSecondFactor->diff(new \DateTime()); |
||
| 162 | if ($interval->invert == 1) { |
||
| 163 | throw new \Exception("We are talking to a future self. Amazing."); |
||
| 164 | } |
||
| 165 | // phpcs:ignore Generic.Files.LineLength.TooLong |
||
| 166 | $totalAge = $interval->s + 60 * $interval->i + 3600 * $interval->h + 86400 * $interval->d + 86400 * 30 * $interval->m + 86400 * 365 * $interval->y; |
||
| 167 | if ($totalAge < $this->SecondFactorMaxAge) { // we are within the interval indeed, skip calling the AuthProc |
||
| 168 | return; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | StaticProcessHelper::prepareState($this->stateData, $state); |
||
| 172 | StaticProcessHelper::saveStateAndRedirect($state); |
||
| 173 | } |
||
| 175 |