Complex classes like LDAPAuthenticator 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 LDAPAuthenticator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 67 | class LDAPAuthenticator extends Authenticator |
||
| 68 | { |
||
| 69 | /** The URL for the LDAP host */ |
||
| 70 | private $host; |
||
| 71 | /** The base DN for all users in the LDAP server */ |
||
| 72 | public $user_base; |
||
| 73 | /** The base DN for all groups in the LDAP server */ |
||
| 74 | public $group_base; |
||
| 75 | /** The DN to use to bind if binding as the read only user */ |
||
| 76 | private $bindRODistinguishedName; |
||
| 77 | /** The password to use to bind if binding as the read only user */ |
||
| 78 | private $bindROPassword; |
||
| 79 | /** The DN to use to bind if binding as the read/write user */ |
||
| 80 | private $bindRWDistinguishedName; |
||
|
|
|||
| 81 | /** The password to use to bind if binding as the read/write user */ |
||
| 82 | private $bindRWPassword; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Create an LDAP Authenticator |
||
| 86 | * |
||
| 87 | * @param array $params Parementers needed to initialize the authenticator |
||
| 88 | */ |
||
| 89 | public function __construct($params) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Return the host string for this authenticator |
||
| 103 | * |
||
| 104 | * @param array $params The initial parameters of the authenticator |
||
| 105 | * |
||
| 106 | * @return string The host string |
||
| 107 | * |
||
| 108 | * @SuppressWarnings("StaticAccess") |
||
| 109 | */ |
||
| 110 | private function getHostParam($params) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Return the required paramter for this authenticator |
||
| 122 | * |
||
| 123 | * @param array $params The initial parameters of the authenticator |
||
| 124 | * @param string $paramName The name of the parameter in the $paramsArray |
||
| 125 | * @param string $settingsLocation The location in the Settings class |
||
| 126 | * @param string $settingsName The name in the Settings class |
||
| 127 | * |
||
| 128 | * @return mixed The paramter value |
||
| 129 | * |
||
| 130 | * @SuppressWarnings("StaticAccess") |
||
| 131 | */ |
||
| 132 | private function getParam($params, $paramName, $settingsLocation = '$ldap', $settingsName = false) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Return an instance to the \LDAP\LDAPServer object instance |
||
| 148 | * |
||
| 149 | * @param boolean $bindWrite Should we be able to write to the server? |
||
| 150 | * |
||
| 151 | * @return \LDAP\LDAPServer|false The server instance if the binding was successful, otherwise false |
||
| 152 | * |
||
| 153 | * @SuppressWarnings("StaticAccess") |
||
| 154 | */ |
||
| 155 | public function getAndBindServer($bindWrite = false) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Log the user in provided the credetials |
||
| 185 | * |
||
| 186 | * @param string $username The UID or email address for the user |
||
| 187 | * @param string $password The password for the user |
||
| 188 | * |
||
| 189 | * @return mixed False if the login failed and array otherwise |
||
| 190 | */ |
||
| 191 | public function login($username, $password) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Does this array represent a successful login? |
||
| 216 | * |
||
| 217 | * @param array $data The array data stored in the session after a login call |
||
| 218 | * |
||
| 219 | * @return boolean True if the user is logged in, false otherwise |
||
| 220 | */ |
||
| 221 | public function isLoggedIn($data) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Obtain the currently logged in user from the session data |
||
| 232 | * |
||
| 233 | * @param \stdClass $data The AuthData from the session |
||
| 234 | * |
||
| 235 | * @return null|\Auth\LDAPUser The LDAPUser represented by this data |
||
| 236 | */ |
||
| 237 | public function getUser($data) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Obtain the group based on the group name |
||
| 244 | * |
||
| 245 | * @param string $name The Group's name |
||
| 246 | * |
||
| 247 | * @return null|\Auth\LDAPGroup The LDAPGroup represented by the name or null if not found |
||
| 248 | */ |
||
| 249 | public function getGroupByName($name) |
||
| 258 | |||
| 259 | public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
||
| 288 | |||
| 289 | public function getActiveUserCount() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @param array $data The array data to filter and sort |
||
| 301 | * @param boolean|array $select The fields to return |
||
| 302 | * @param boolean|integer $top The number of records to return |
||
| 303 | * @param boolean|integer $skip The number of records to skip |
||
| 304 | * @param boolean|array $orderby The fields to sort by |
||
| 305 | */ |
||
| 306 | private function processFilteringParams(&$data, &$select, $top, $skip, $orderby) |
||
| 329 | |||
| 330 | |||
| 331 | /** |
||
| 332 | * @param boolean|\Data\Filter $filter The filter to user when reading users |
||
| 333 | * @param boolean|array $select The fields to return |
||
| 334 | * @param boolean|integer $top The number of records to return |
||
| 335 | * @param boolean|integer $skip The number of records to skip |
||
| 336 | * @param boolean|array $orderby The fields to sort by |
||
| 337 | * |
||
| 338 | * @return array|boolean False if no users found, an array of user objects otherwise |
||
| 339 | */ |
||
| 340 | public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
||
| 370 | |||
| 371 | public function activatePendingUser($user) |
||
| 403 | |||
| 404 | public function getUserByResetHash($hash) |
||
| 413 | } |
||
| 414 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
| 415 |
This check marks private properties in classes that are never used. Those properties can be removed.