Complex classes like SQLAuthenticator 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 SQLAuthenticator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 4 | class SQLAuthenticator extends Authenticator |
||
| 5 | { |
||
| 6 | public $dataSet = null; |
||
| 7 | public $pendingDataSet = null; |
||
| 8 | private $dataTables = array(); |
||
| 9 | private $params; |
||
| 10 | |||
| 11 | public function __construct($params) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @SuppressWarnings("StaticAccess") |
||
| 27 | */ |
||
| 28 | private function getCurrentDataSet() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @SuppressWarnings("StaticAccess") |
||
| 39 | */ |
||
| 40 | private function getPendingDataSet() |
||
| 48 | |||
| 49 | private function getDataTable($name, $pending = false) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the data table for Pending Users |
||
| 75 | * |
||
| 76 | * @return boolean|\Data\DataTable The Pending User Data Table |
||
| 77 | */ |
||
| 78 | private function getPendingUserDataTable() |
||
| 86 | |||
| 87 | public function login($username, $password) |
||
| 106 | |||
| 107 | public function isLoggedIn($data) |
||
| 115 | |||
| 116 | public function getUser($data) |
||
| 124 | |||
| 125 | private function getEntityByFilter($tableName, $filterStr, $className) |
||
| 136 | |||
| 137 | public function getGroupByName($name) |
||
| 141 | |||
| 142 | public function getUserByName($name) |
||
| 146 | |||
| 147 | private function getDataByFilter($dataTableName, $filter, $select, $top, $skip, $orderby) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param string $dataTableName The Data Table to serach |
||
| 155 | * @param string $className The class to obtain data in |
||
| 156 | * @param boolean|array $select The fields to read |
||
| 157 | * @param boolean|integer $top The number of entities to read |
||
| 158 | * @param boolean|integer $skip The number of entities to skip |
||
| 159 | * @param boolean|array $orderby The fields to sort by |
||
| 160 | */ |
||
| 161 | private function convertDataToClass($dataTableName, $className, $filter, $select, $top, $skip, $orderby) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param boolean|array $select The fields to read |
||
| 178 | * @param boolean|integer $top The number of entities to read |
||
| 179 | * @param boolean|integer $skip The number of entities to skip |
||
| 180 | * @param boolean|array $orderby The fields to sort by |
||
| 181 | */ |
||
| 182 | public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param boolean|array $select The fields to read |
||
| 189 | * @param boolean|integer $top The number of entities to read |
||
| 190 | * @param boolean|integer $skip The number of entities to skip |
||
| 191 | * @param boolean|array $orderby The fields to sort by |
||
| 192 | */ |
||
| 193 | public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
||
| 197 | |||
| 198 | public function getPendingUserCount() |
||
| 211 | |||
| 212 | private function searchPendingUsers($filter, $select, $top, $skip, $orderby) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @param \Data\Filter $filter The filter to read with |
||
| 245 | * @param boolean|array $select The fields to read |
||
| 246 | * @param boolean|integer $top The number of entities to read |
||
| 247 | * @param boolean|integer $skip The number of entities to skip |
||
| 248 | * @param boolean|array $orderby The fields to sort by |
||
| 249 | */ |
||
| 250 | public function getPendingUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
||
| 273 | |||
| 274 | public function createPendingUser($user) |
||
| 300 | |||
| 301 | public function getTempUserByHash($hash) |
||
| 310 | } |
||
| 311 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
| 312 |
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: