| Conditions | 13 |
| Paths | 53 |
| Total Lines | 78 |
| Code Lines | 51 |
| 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 |
||
| 79 | protected function continueLinkAttempt( $user, $key, array $reqs ) { |
||
| 80 | $req = ButtonAuthenticationRequest::getRequestByName( $reqs, 'linkOk' ); |
||
| 81 | if ( $req ) { |
||
| 82 | return AuthenticationResponse::newPass(); |
||
| 83 | } |
||
| 84 | |||
| 85 | $req = AuthenticationRequest::getRequestByClass( $reqs, ConfirmLinkAuthenticationRequest::class ); |
||
| 86 | if ( !$req ) { |
||
| 87 | // WTF? Retry. |
||
| 88 | return $this->beginLinkAttempt( $user, $key ); |
||
| 89 | } |
||
| 90 | |||
| 91 | $session = $this->manager->getRequest()->getSession(); |
||
| 92 | $state = $session->getSecret( $key ); |
||
| 93 | if ( !is_array( $state ) ) { |
||
| 94 | return AuthenticationResponse::newAbstain(); |
||
| 95 | } |
||
| 96 | |||
| 97 | $maybeLink = []; |
||
| 98 | foreach ( $state['maybeLink'] as $linkReq ) { |
||
| 99 | $maybeLink[$linkReq->getUniqueId()] = $linkReq; |
||
| 100 | } |
||
| 101 | if ( !$maybeLink ) { |
||
| 102 | return AuthenticationResponse::newAbstain(); |
||
| 103 | } |
||
| 104 | |||
| 105 | $state['maybeLink'] = []; |
||
| 106 | $session->setSecret( $key, $state ); |
||
| 107 | |||
| 108 | $statuses = []; |
||
| 109 | $anyFailed = false; |
||
| 110 | foreach ( $req->confirmedLinkIDs as $id ) { |
||
| 111 | if ( isset( $maybeLink[$id] ) ) { |
||
| 112 | $req = $maybeLink[$id]; |
||
| 113 | $req->username = $user->getName(); |
||
| 114 | if ( !$req->action ) { |
||
| 115 | // Make sure the action is set, but don't override it if |
||
| 116 | // the provider filled it in. |
||
| 117 | $req->action = AuthManager::ACTION_CHANGE; |
||
| 118 | } |
||
| 119 | $status = $this->manager->allowsAuthenticationDataChange( $req ); |
||
| 120 | $statuses[] = [ $req, $status ]; |
||
| 121 | if ( $status->isGood() ) { |
||
| 122 | $this->manager->changeAuthenticationData( $req ); |
||
| 123 | } else { |
||
| 124 | $anyFailed = true; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 | if ( !$anyFailed ) { |
||
| 129 | return AuthenticationResponse::newPass(); |
||
| 130 | } |
||
| 131 | |||
| 132 | $combinedStatus = \Status::newGood(); |
||
| 133 | foreach ( $statuses as $data ) { |
||
| 134 | list( $req, $status ) = $data; |
||
| 135 | $descriptionInfo = $req->describeCredentials(); |
||
| 136 | $description = wfMessage( |
||
| 137 | 'authprovider-confirmlink-option', |
||
| 138 | $descriptionInfo['provider']->text(), $descriptionInfo['account']->text() |
||
| 139 | )->text(); |
||
| 140 | if ( $status->isGood() ) { |
||
| 141 | $combinedStatus->error( wfMessage( 'authprovider-confirmlink-success-line', $description ) ); |
||
| 142 | } else { |
||
| 143 | $combinedStatus->error( wfMessage( |
||
| 144 | 'authprovider-confirmlink-failed-line', $description, $status->getMessage()->text() |
||
| 145 | ) ); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | return AuthenticationResponse::newUI( |
||
| 149 | [ |
||
| 150 | new ButtonAuthenticationRequest( |
||
| 151 | 'linkOk', wfMessage( 'ok' ), wfMessage( 'authprovider-confirmlink-ok-help' ) |
||
| 152 | ) |
||
| 153 | ], |
||
| 154 | $combinedStatus->getMessage( 'authprovider-confirmlink-failed' ) |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | } |
||
| 158 |