Complex classes like XmlProcessor 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 XmlProcessor, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class XmlProcessor |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * Contains any kind of configuration. |
||
| 32 | * @var object |
||
| 33 | */ |
||
| 34 | public $config; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The xml object containing the settings. |
||
| 38 | * Required (for now) to convert IPs (v4/6) |
||
| 39 | * @var object |
||
| 40 | */ |
||
| 41 | public $xml; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The step running in this very moment. |
||
| 45 | * @var object |
||
| 46 | */ |
||
| 47 | public $current_step; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Holds all the methods required to perform the conversion. |
||
| 51 | * @var object |
||
| 52 | */ |
||
| 53 | public $step1_importer; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The object defining the intermediate array between source and destination. |
||
| 57 | * @var object |
||
| 58 | */ |
||
| 59 | public $skeleton; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * If the step is completed of not. |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | public $completed; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * This is the database object of the destination system. |
||
| 69 | * @var object |
||
| 70 | */ |
||
| 71 | protected $db; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * This is the database object of the source system. |
||
| 75 | * @var object |
||
| 76 | */ |
||
| 77 | protected $source_db; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * XmlProcessor constructor. |
||
| 81 | * Initialize the main Importer object |
||
| 82 | * |
||
| 83 | * @param Database $db |
||
| 84 | * @param Database $source_db |
||
| 85 | * @param Configurator $config |
||
| 86 | * @param \SimpleXMLElement $xml |
||
| 87 | */ |
||
| 88 | public function __construct(Database $db, Database $source_db, Configurator $config, \SimpleXMLElement $xml) |
||
| 95 | |||
| 96 | public function setImporter($step1_importer) |
||
| 100 | |||
| 101 | public function setSkeleton($skeleton) |
||
| 105 | |||
| 106 | public function processSource($step, $key) |
||
| 128 | |||
| 129 | protected function doCode() |
||
| 142 | |||
| 143 | protected function doSql() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Used to replace {$from_prefix} and {$to_prefix} with its real values. |
||
| 172 | * |
||
| 173 | * @param string string in which parameters are replaced |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | protected function fixParams($string) |
||
| 188 | |||
| 189 | protected function prepareSpecialResult($current_data, $special_limit) |
||
| 204 | |||
| 205 | public function processDestination($id, $rows) |
||
| 209 | |||
| 210 | public function stillRunning() |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Counts the records in a table of the source database |
||
| 217 | * @todo move to ProgressTracker |
||
| 218 | * |
||
| 219 | * @param object $step |
||
| 220 | * |
||
| 221 | * @return bool|int the number of records in the table |
||
| 222 | */ |
||
| 223 | public function getCurrent($step) |
||
| 245 | |||
| 246 | public function doPreSqlStep($id) |
||
| 259 | |||
| 260 | public function detect($step) |
||
| 286 | |||
| 287 | public function insertRows($rows) |
||
| 309 | |||
| 310 | public function getStepTable($id) |
||
| 314 | |||
| 315 | protected function insertStatement($options) |
||
| 330 | |||
| 331 | protected function shouldIgnore($options) |
||
| 340 | |||
| 341 | protected function shouldReplace($options) |
||
| 345 | |||
| 346 | protected function ignoreSlashes($options) |
||
| 350 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.