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 not binding as the user */ |
||
76 | private $bind_dn; |
||
77 | /** The password to use to bind if not binding as the user */ |
||
78 | private $bind_pass; |
||
79 | |||
80 | /** |
||
81 | * Create an LDAP Authenticator |
||
82 | * |
||
83 | * @param array $params Parementers needed to initialize the authenticator |
||
84 | */ |
||
85 | public function __construct($params) |
||
94 | |||
95 | /** |
||
96 | * Return the host string for this authenticator |
||
97 | * |
||
98 | * @param array $params The initial parameters of the authenticator |
||
99 | * |
||
100 | * @return string The host string |
||
101 | * |
||
102 | * @SuppressWarnings("StaticAccess") |
||
103 | */ |
||
104 | private function getHostParam($params) |
||
113 | |||
114 | /** |
||
115 | * Return the required paramter for this authenticator |
||
116 | * |
||
117 | * @param array $params The initial parameters of the authenticator |
||
118 | * @param string $paramName The name of the parameter in the $paramsArray |
||
119 | * @param string $settingsLocation The location in the Settings class |
||
120 | * @param string $settingsName The name in the Settings class |
||
121 | * |
||
122 | * @return mixed The paramter value |
||
123 | * |
||
124 | * @SuppressWarnings("StaticAccess") |
||
125 | */ |
||
126 | private function getParam($params, $paramName, $settingsLocation = '$ldap', $settingsName = false) |
||
139 | |||
140 | /** |
||
141 | * Return an instance to the \LDAP\LDAPServer object instance |
||
142 | * |
||
143 | * @param boolean $bind_write Should we be able to write to the server? |
||
144 | * |
||
145 | * @return \LDAP\LDAPServer|false The server instance if the binding was successful, otherwise false |
||
146 | * |
||
147 | * @SuppressWarnings("StaticAccess") |
||
148 | */ |
||
149 | public function get_and_bind_server($bind_write = false) |
||
169 | |||
170 | /** |
||
171 | * Log the user in provided the credetials |
||
172 | * |
||
173 | * @param string $username The UID or email address for the user |
||
174 | * @param string $password The password for the user |
||
175 | * |
||
176 | * @return mixed False if the login failed and array otherwise |
||
177 | */ |
||
178 | public function login($username, $password) |
||
200 | |||
201 | /** |
||
202 | * Does this array represent a successful login? |
||
203 | * |
||
204 | * @param array $data The array data stored in the session after a login call |
||
205 | * |
||
206 | * @return boolean True if the user is logged in, false otherwise |
||
207 | */ |
||
208 | public function isLoggedIn($data) |
||
216 | |||
217 | /** |
||
218 | * Obtain the currently logged in user from the session data |
||
219 | * |
||
220 | * @param \stdClass $data The AuthData from the session |
||
221 | * |
||
222 | * @return \Auth\LDAPUser The LDAPUser represented by this data |
||
223 | */ |
||
224 | public function getUser($data) |
||
228 | |||
229 | public function getGroupByName($name) |
||
238 | |||
239 | public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
||
268 | |||
269 | public function getActiveUserCount() |
||
278 | |||
279 | /** |
||
280 | * @param array $data The array data to filter and sort |
||
281 | * @param boolean|array $select The fields to return |
||
282 | * @param boolean|integer $top The number of records to return |
||
283 | * @param boolean|integer $skip The number of records to skip |
||
284 | * @param boolean|array $orderby The fields to sort by |
||
285 | */ |
||
286 | private function processFilteringParams(&$data, &$select, $top, $skip, $orderby) |
||
309 | |||
310 | |||
311 | /** |
||
312 | * @param boolean|\Data\Filter $filter The filter to user when reading users |
||
313 | * @param boolean|array $select The fields to return |
||
314 | * @param boolean|integer $top The number of records to return |
||
315 | * @param boolean|integer $skip The number of records to skip |
||
316 | * @param boolean|array $orderby The fields to sort by |
||
317 | */ |
||
318 | public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
||
348 | |||
349 | public function activatePendingUser($user) |
||
387 | |||
388 | public function getUserByResetHash($hash) |
||
397 | } |
||
398 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
399 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: