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