| Conditions | 20 |
| Paths | 269 |
| Total Lines | 68 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 64 | protected function tryReset( \User $user, array $reqs ) { |
||
| 65 | $data = $this->manager->getAuthenticationSessionData( 'reset-pass' ); |
||
| 66 | if ( !$data ) { |
||
| 67 | return AuthenticationResponse::newAbstain(); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ( is_array( $data ) ) { |
||
| 71 | $data = (object)$data; |
||
| 72 | } |
||
| 73 | if ( !is_object( $data ) ) { |
||
| 74 | throw new \UnexpectedValueException( 'reset-pass is not valid' ); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ( !isset( $data->msg ) ) { |
||
| 78 | throw new \UnexpectedValueException( 'reset-pass msg is missing' ); |
||
| 79 | } elseif ( !$data->msg instanceof \Message ) { |
||
| 80 | throw new \UnexpectedValueException( 'reset-pass msg is not valid' ); |
||
| 81 | } elseif ( !isset( $data->hard ) ) { |
||
| 82 | throw new \UnexpectedValueException( 'reset-pass hard is missing' ); |
||
| 83 | } elseif ( isset( $data->req ) && ( |
||
| 84 | !$data->req instanceof PasswordAuthenticationRequest || |
||
| 85 | !array_key_exists( 'retype', $data->req->getFieldInfo() ) |
||
| 86 | ) ) { |
||
| 87 | throw new \UnexpectedValueException( 'reset-pass req is not valid' ); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ( !$data->hard ) { |
||
| 91 | $req = ButtonAuthenticationRequest::getRequestByName( $reqs, 'skipReset' ); |
||
| 92 | if ( $req ) { |
||
| 93 | $this->manager->removeAuthenticationSessionData( 'reset-pass' ); |
||
| 94 | return AuthenticationResponse::newPass(); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | $needReq = isset( $data->req ) ? $data->req : new PasswordAuthenticationRequest(); |
||
| 99 | if ( !$needReq->action ) { |
||
|
|
|||
| 100 | $needReq->action = AuthManager::ACTION_CHANGE; |
||
| 101 | } |
||
| 102 | $needReq->required = $data->hard ? AuthenticationRequest::REQUIRED |
||
| 103 | : AuthenticationRequest::OPTIONAL; |
||
| 104 | $needReqs = [ $needReq ]; |
||
| 105 | if ( !$data->hard ) { |
||
| 106 | $needReqs[] = new ButtonAuthenticationRequest( |
||
| 107 | 'skipReset', |
||
| 108 | wfMessage( 'authprovider-resetpass-skip-label' ), |
||
| 109 | wfMessage( 'authprovider-resetpass-skip-help' ) |
||
| 110 | ); |
||
| 111 | } |
||
| 112 | |||
| 113 | $req = AuthenticationRequest::getRequestByClass( $reqs, get_class( $needReq ) ); |
||
| 114 | if ( !$req || !array_key_exists( 'retype', $req->getFieldInfo() ) ) { |
||
| 115 | return AuthenticationResponse::newUI( $needReqs, $data->msg ); |
||
| 116 | } |
||
| 117 | |||
| 118 | if ( $req->password !== $req->retype ) { |
||
| 119 | return AuthenticationResponse::newUI( $needReqs, new \Message( 'badretype' ) ); |
||
| 120 | } |
||
| 121 | |||
| 122 | $req->username = $user->getName(); |
||
| 123 | $status = $this->manager->allowsAuthenticationDataChange( $req ); |
||
| 124 | if ( !$status->isGood() ) { |
||
| 125 | return AuthenticationResponse::newUI( $needReqs, $status->getMessage() ); |
||
| 126 | } |
||
| 127 | $this->manager->changeAuthenticationData( $req ); |
||
| 128 | |||
| 129 | $this->manager->removeAuthenticationSessionData( 'reset-pass' ); |
||
| 130 | return AuthenticationResponse::newPass(); |
||
| 131 | } |
||
| 132 | } |
||
| 133 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: