r105346 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105345‎ | r105346 | r105347 >
Date:20:18, 6 December 2011
Author:reedy
Status:deferred
Tags:
Comment:
Stylize, more documentation update

Unfortunately, PHP still isn't a strongly typed language, and using comments that show you wish it was, doesn't help either
Modified paths:
  • /trunk/extensions/CrowdAuthentication/CrowdAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CrowdAuthentication/CrowdAuthentication.php
@@ -78,16 +78,36 @@
7979 /**
8080 * @var PasswordCredential
8181 */
82 - public /**/ $credential;
83 - public /*string*/ $name;
84 - public /*ValidationFactor[]*/ $validationFactors = null;
 82+ public $credential;
 83+
 84+ /**
 85+ * @var string
 86+ */
 87+ public $name;
 88+
 89+ /**
 90+ * @var array
 91+ */
 92+ public $validationFactors = null;
8593 }
8694
8795 class caPrincipalAuthenticationContext {
88 - public /*string*/ $application;
89 - public /*PasswordCredential*/ $credential;
90 - public /*string*/ $name;
91 - public /*ValidationFactor[]*/ $validationFactors = null;
 96+ public $application;
 97+
 98+ /**
 99+ * @var PasswordCredential
 100+ */
 101+ public $credential;
 102+
 103+ /**
 104+ * @var string
 105+ */
 106+ public $name;
 107+
 108+ /**
 109+ * @var array
 110+ */
 111+ public $validationFactors = null;
92112 }
93113
94114 class CrowdAuthenticator extends AuthPlugin {
@@ -133,7 +153,7 @@
134154
135155 /**
136156 * @param $name string
137 - * @return bool
 157+ * @return string|null
138158 */
139159 private function findUsername( $name ) {
140160 /*
@@ -159,12 +179,21 @@
160180 return null;
161181 }
162182
163 - public function /*bool*/ userExists( /*string*/ $name ) {
 183+ /**
 184+ * @param $name string
 185+ * @return bool
 186+ */
 187+ public function userExists( $name ) {
164188 return !is_null( $this->findUsername( $name ) );
165189 }
166190
167 - public function /*bool*/ authenticate( /*string*/ $username, /*string*/ $password ) {
168 - global $caApplicationName, $caImportGroups, $caOverwriteLocalGroups;
 191+ /**
 192+ * @param $username string
 193+ * @param $password string
 194+ * @return bool
 195+ */
 196+ public function authenticate( $username, $password ) {
 197+ global $caApplicationName;
169198
170199 $crowd = $this->getCrowd();
171200 $cred = new caPasswordCredential();
@@ -182,11 +211,16 @@
183212 }
184213 }
185214
186 - public function /*void*/ updateUser( /*User*/ &$user ) {
187 - global $caImportGroups, $caOverwriteLocalGroups;
 215+ /**
 216+ * @param $user User
 217+ * @return bool
 218+ */
 219+ public function updateUser( &$user ) {
 220+ global $caImportGroups, $caOverwriteLocalGroups;
188221
189 - if ( !$caImportGroups )
 222+ if ( !$caImportGroups ) {
190223 return true;
 224+ }
191225
192226 /*
193227 * Find the groups this user is a member of.
@@ -199,27 +233,43 @@
200234 $groups = $groups->out->SOAPGroup;
201235
202236 $dbw = wfGetDB( DB_MASTER );
203 - if ( $caOverwriteLocalGroups )
 237+ if ( $caOverwriteLocalGroups ) {
204238 $dbw->delete( 'user_group', array( 'ug_user' => $user->getId() ) );
 239+ }
205240
206241 foreach ( $groups as $group ) {
207242 $user->addGroup( $group->name );
208243 }
 244+ return true;
209245 }
210246
211 - public function /*bool*/ autoCreate( /*void*/ ) {
 247+ /**
 248+ * @return bool
 249+ */
 250+ public function autoCreate() {
212251 return true;
213252 }
214253
215 - public function /*bool*/ strict( /*void*/ ) {
 254+ /**
 255+ * @return bool
 256+ */
 257+ public function strict() {
216258 return true;
217259 }
218260
219 - public function /*bool*/ allowPasswordChange( /*void*/ ) {
 261+ /**
 262+ * @return bool
 263+ */
 264+ public function allowPasswordChange() {
220265 return true;
221266 }
222267
223 - public function /*bool*/ setPassword( /*User*/ $user, /*string*/ $password ) {
 268+ /**
 269+ * @param $user User
 270+ * @param $password string
 271+ * @return bool
 272+ */
 273+ public function setPassword( $user, $password ) {
224274 $newcred = new caPasswordCredential;
225275 $newcred->credential = $password;
226276 $username = $this->findUsername( $user->getName() );
@@ -235,21 +285,33 @@
236286 }
237287 }
238288
239 - public function /*bool*/ canCreateAccounts( /*void*/ ) {
 289+ /**
 290+ * @return bool
 291+ */
 292+ public function canCreateAccounts() {
240293 return true;
241294 }
242295
243 - public function /*bool*/ addUser( /*User*/ $user, /*string*/ $password,
244 - /*string*/ $email = '', /*string*/ $realname = '' ) {
245 - global $caDefaultGroups;
 296+ /**
 297+ * @param $user User
 298+ * @param $password string
 299+ * @param $email string
 300+ * @param $realname string
 301+ * @return bool
 302+ */
 303+ public function addUser( $user, $password, $email = '', $realname = '' ) {
 304+ global $caDefaultGroups;
246305 $crowd = $this->getCrowd();
247306 $nameparts = split( " ", $realname, 2 );
248307 $firstname = $user->getName();
249308 $lastname = "";
250 - if ( count( $nameparts ) > 0 )
 309+ if ( count( $nameparts ) > 0 ) {
251310 $firstname = $nameparts[0];
252 - if ( count( $nameparts ) > 1 )
253 - $lastname = $nameparts[1];
 311+
 312+ if ( count( $nameparts ) > 1 ) {
 313+ $lastname = $nameparts[1];
 314+ }
 315+ }
254316 $cred = new caPasswordCredential();
255317 $cred->credential = $password;
256318 $principal = new caPrincipal();
@@ -271,8 +333,9 @@
272334 $crowd->addPrincipal( array( "in0" => $this->token,
273335 "in1" => $principal,
274336 "in2" => $cred ) );
275 - foreach ( $caDefaultGroups as $group )
 337+ foreach ( $caDefaultGroups as $group ) {
276338 $crowd->addPrincipalToGroup( array( "in0" => $this->token, "in1" => $user->getName(), "in2" => $group ) );
 339+ }
277340
278341 return true;
279342 } catch ( Exception $e ) {

Status & tagging log