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