Complex classes like AnyDataset 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 AnyDataset, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
42 | class AnyDataset |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * Internal structure represent the current Row |
||
47 | * |
||
48 | * @var Row[] |
||
49 | */ |
||
50 | private $collection; |
||
51 | |||
52 | /** |
||
53 | * Current node anydataset works |
||
54 | * @var int |
||
55 | */ |
||
56 | private $currentRow; |
||
57 | |||
58 | /** |
||
59 | * Path to anydataset file |
||
60 | * @var string |
||
61 | */ |
||
62 | private $path; |
||
63 | |||
64 | /** |
||
65 | * @param string $file |
||
66 | * @throws \ByJG\Serializer\Exception\InvalidArgumentException |
||
67 | * @throws \ByJG\Util\Exception\XmlUtilException |
||
68 | */ |
||
69 | 14 | public function __construct($file = null) |
|
89 | |||
90 | /** |
||
91 | * Private method used to read and populate anydataset class from specified file |
||
92 | * |
||
93 | * @param string $filepath Path and Filename to be read |
||
94 | * @throws \ByJG\Serializer\Exception\InvalidArgumentException |
||
95 | * @throws \ByJG\Util\Exception\XmlUtilException |
||
96 | */ |
||
97 | 7 | private function createFrom($filepath) |
|
121 | |||
122 | /** |
||
123 | * Returns the AnyDataset XML representative structure. |
||
124 | * |
||
125 | * @return string XML String |
||
126 | * @throws \ByJG\Util\Exception\XmlUtilException |
||
127 | */ |
||
128 | 1 | public function xml() |
|
132 | |||
133 | /** |
||
134 | * Returns the AnyDataset XmlDocument representive object |
||
135 | * |
||
136 | * @return \DOMDocument XmlDocument object |
||
137 | * @throws \ByJG\Util\Exception\XmlUtilException |
||
138 | */ |
||
139 | 2 | public function getAsDom() |
|
152 | |||
153 | /** |
||
154 | * @param string $file |
||
155 | * @throws DatabaseException |
||
156 | * @throws \ByJG\Util\Exception\XmlUtilException |
||
157 | */ |
||
158 | 1 | public function save($file = null) |
|
174 | |||
175 | /** |
||
176 | * Append one row to AnyDataset. |
||
177 | * |
||
178 | * @param Row $singleRow |
||
179 | * @return void |
||
180 | * @throws \ByJG\Serializer\Exception\InvalidArgumentException |
||
181 | */ |
||
182 | 9 | public function appendRow($singleRow = null) |
|
200 | |||
201 | /** |
||
202 | * Enter description here... |
||
203 | * |
||
204 | * @param GenericIterator $iterator |
||
205 | * @throws \ByJG\Serializer\Exception\InvalidArgumentException |
||
206 | */ |
||
207 | 1 | public function import($iterator) |
|
213 | |||
214 | /** |
||
215 | * Insert one row before specified position. |
||
216 | * |
||
217 | * @param int $rowNumber |
||
218 | * @param mixed $row |
||
219 | * @throws \ByJG\Serializer\Exception\InvalidArgumentException |
||
220 | */ |
||
221 | 1 | public function insertRowBefore($rowNumber, $row = null) |
|
234 | |||
235 | /** |
||
236 | * |
||
237 | * @param mixed $row |
||
238 | * @throws \ByJG\Serializer\Exception\InvalidArgumentException |
||
239 | */ |
||
240 | 2 | public function removeRow($row = null) |
|
263 | |||
264 | /** |
||
265 | * Add a single string field to an existing row |
||
266 | * |
||
267 | * @param string $name - Field name |
||
268 | * @param string $value - Field value |
||
269 | * @return void |
||
270 | * @throws \ByJG\Serializer\Exception\InvalidArgumentException |
||
271 | */ |
||
272 | 5 | public function addField($name, $value) |
|
279 | |||
280 | /** |
||
281 | * Get an Iterator filtered by an IteratorFilter |
||
282 | * @param IteratorFilter $itf |
||
283 | * @return GenericIterator |
||
284 | */ |
||
285 | 13 | public function getIterator(IteratorFilter $itf = null) |
|
293 | |||
294 | /** |
||
295 | * @desc |
||
296 | * @param IteratorFilter $itf |
||
297 | * @param string $fieldName |
||
298 | * @return array |
||
299 | */ |
||
300 | 1 | public function getArray($itf, $fieldName) |
|
310 | |||
311 | /** |
||
312 | * |
||
313 | * @param string $field |
||
314 | * @return void |
||
315 | */ |
||
316 | 1 | public function sort($field) |
|
326 | |||
327 | /** |
||
328 | * @param Row[] $seq |
||
329 | * @param $field |
||
330 | * @return array |
||
331 | */ |
||
332 | 1 | protected function quickSortExec($seq, $field) |
|
356 | } |
||
357 |