Complex classes like auth_plugin_authplain often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use auth_plugin_authplain, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class auth_plugin_authplain extends DokuWiki_Auth_Plugin |
||
12 | { |
||
13 | /** @var array user cache */ |
||
14 | protected $users = null; |
||
15 | |||
16 | /** @var array filter pattern */ |
||
17 | protected $pattern = array(); |
||
18 | |||
19 | /** @var bool safe version of preg_split */ |
||
20 | protected $pregsplit_safe = false; |
||
21 | |||
22 | /** |
||
23 | * Constructor |
||
24 | * |
||
25 | * Carry out sanity checks to ensure the object is |
||
26 | * able to operate. Set capabilities. |
||
27 | * |
||
28 | * @author Christopher Smith <[email protected]> |
||
29 | */ |
||
30 | public function __construct() |
||
54 | |||
55 | /** |
||
56 | * Check user+password |
||
57 | * |
||
58 | * Checks if the given user exists and the given |
||
59 | * plaintext password is correct |
||
60 | * |
||
61 | * @author Andreas Gohr <[email protected]> |
||
62 | * @param string $user |
||
63 | * @param string $pass |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function checkPass($user, $pass) |
||
73 | |||
74 | /** |
||
75 | * Return user info |
||
76 | * |
||
77 | * Returns info about the given user needs to contain |
||
78 | * at least these fields: |
||
79 | * |
||
80 | * name string full name of the user |
||
81 | * mail string email addres of the user |
||
82 | * grps array list of groups the user is in |
||
83 | * |
||
84 | * @author Andreas Gohr <[email protected]> |
||
85 | * @param string $user |
||
86 | * @param bool $requireGroups (optional) ignored by this plugin, grps info always supplied |
||
87 | * @return array|false |
||
88 | */ |
||
89 | public function getUserData($user, $requireGroups = true) |
||
94 | |||
95 | /** |
||
96 | * Creates a string suitable for saving as a line |
||
97 | * in the file database |
||
98 | * (delimiters escaped, etc.) |
||
99 | * |
||
100 | * @param string $user |
||
101 | * @param string $pass |
||
102 | * @param string $name |
||
103 | * @param string $mail |
||
104 | * @param array $grps list of groups the user is in |
||
105 | * @return string |
||
106 | */ |
||
107 | protected function createUserLine($user, $pass, $name, $mail, $grps) |
||
116 | |||
117 | /** |
||
118 | * Create a new User |
||
119 | * |
||
120 | * Returns false if the user already exists, null when an error |
||
121 | * occurred and true if everything went well. |
||
122 | * |
||
123 | * The new user will be added to the default group by this |
||
124 | * function if grps are not specified (default behaviour). |
||
125 | * |
||
126 | * @author Andreas Gohr <[email protected]> |
||
127 | * @author Chris Smith <[email protected]> |
||
128 | * |
||
129 | * @param string $user |
||
130 | * @param string $pwd |
||
131 | * @param string $name |
||
132 | * @param string $mail |
||
133 | * @param array $grps |
||
134 | * @return bool|null|string |
||
135 | */ |
||
136 | public function createUser($user, $pwd, $name, $mail, $grps = null) |
||
163 | |||
164 | /** |
||
165 | * Modify user data |
||
166 | * |
||
167 | * @author Chris Smith <[email protected]> |
||
168 | * @param string $user nick of the user to be changed |
||
169 | * @param array $changes array of field/value pairs to be changed (password will be clear text) |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function modifyUser($user, $changes) |
||
220 | |||
221 | /** |
||
222 | * Remove one or more users from the list of registered users |
||
223 | * |
||
224 | * @author Christopher Smith <[email protected]> |
||
225 | * @param array $users array of users to be deleted |
||
226 | * @return int the number of users deleted |
||
227 | */ |
||
228 | public function deleteUsers($users) |
||
260 | |||
261 | /** |
||
262 | * Return a count of the number of user which meet $filter criteria |
||
263 | * |
||
264 | * @author Chris Smith <[email protected]> |
||
265 | * |
||
266 | * @param array $filter |
||
267 | * @return int |
||
268 | */ |
||
269 | public function getUserCount($filter = array()) |
||
285 | |||
286 | /** |
||
287 | * Bulk retrieval of user data |
||
288 | * |
||
289 | * @author Chris Smith <[email protected]> |
||
290 | * |
||
291 | * @param int $start index of first user to be returned |
||
292 | * @param int $limit max number of users to be returned |
||
293 | * @param array $filter array of field/pattern pairs |
||
294 | * @return array userinfo (refer getUserData for internal userinfo details) |
||
295 | */ |
||
296 | public function retrieveUsers($start = 0, $limit = 0, $filter = array()) |
||
321 | |||
322 | /** |
||
323 | * Retrieves groups. |
||
324 | * Loads complete user data into memory before searching for groups. |
||
325 | * |
||
326 | * @param int $start index of first group to be returned |
||
327 | * @param int $limit max number of groups to be returned |
||
328 | * @return array |
||
329 | */ |
||
330 | public function retrieveGroups($start = 0, $limit = 0) |
||
344 | |||
345 | /** |
||
346 | * Only valid pageid's (no namespaces) for usernames |
||
347 | * |
||
348 | * @param string $user |
||
349 | * @return string |
||
350 | */ |
||
351 | public function cleanUser($user) |
||
356 | |||
357 | /** |
||
358 | * Only valid pageid's (no namespaces) for groupnames |
||
359 | * |
||
360 | * @param string $group |
||
361 | * @return string |
||
362 | */ |
||
363 | public function cleanGroup($group) |
||
368 | |||
369 | /** |
||
370 | * Load all user data |
||
371 | * |
||
372 | * loads the user file into a datastructure |
||
373 | * |
||
374 | * @author Andreas Gohr <[email protected]> |
||
375 | */ |
||
376 | protected function loadUserData() |
||
391 | |||
392 | /** |
||
393 | * Read user data from given file |
||
394 | * |
||
395 | * ignores non existing files |
||
396 | * |
||
397 | * @param string $file the file to load data from |
||
398 | * @return array |
||
399 | */ |
||
400 | protected function readUserFile($file) |
||
424 | |||
425 | /** |
||
426 | * Get the user line split into it's parts |
||
427 | * |
||
428 | * @param string $line |
||
429 | * @return string[] |
||
430 | */ |
||
431 | protected function splitUserData($line) |
||
458 | |||
459 | /** |
||
460 | * return true if $user + $info match $filter criteria, false otherwise |
||
461 | * |
||
462 | * @author Chris Smith <[email protected]> |
||
463 | * |
||
464 | * @param string $user User login |
||
465 | * @param array $info User's userinfo array |
||
466 | * @return bool |
||
467 | */ |
||
468 | protected function filter($user, $info) |
||
481 | |||
482 | /** |
||
483 | * construct a filter pattern |
||
484 | * |
||
485 | * @param array $filter |
||
486 | */ |
||
487 | protected function constructPattern($filter) |
||
494 | } |
||
495 |