Complex classes like ResultSetBase 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 ResultSetBase, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | abstract class ResultSetBase implements ResultSetInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var int |
||
11 | */ |
||
12 | protected $num_rows = 0; |
||
13 | |||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | protected $cursor = 0; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $next_cursor = 0; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | protected $affected_rows = 0; // leave to 0 so SELECT etc. will be coherent |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $fields; |
||
33 | |||
34 | /** |
||
35 | * @var null|array |
||
36 | */ |
||
37 | protected $stored; |
||
38 | |||
39 | /** |
||
40 | * @var null|array |
||
41 | */ |
||
42 | protected $fetched; |
||
43 | |||
44 | /** |
||
45 | * @var null|\Foolz\SphinxQL\Drivers\ResultSetAdapterInterface |
||
46 | */ |
||
47 | protected $adapter; |
||
48 | |||
49 | /** |
||
50 | * Checks that a row actually exists |
||
51 | * |
||
52 | * @param int $num The number of the row to check on |
||
53 | * @return bool True if the row exists |
||
54 | */ |
||
55 | public function hasRow($num) |
||
59 | |||
60 | /** |
||
61 | * Checks that a next row exists |
||
62 | * |
||
63 | * @return bool True if there's another row with a higher index |
||
64 | */ |
||
65 | public function hasNextRow() |
||
69 | |||
70 | /** |
||
71 | * Returns the number of rows affected by the query |
||
72 | * This will be 0 for SELECT and any query not editing rows |
||
73 | * |
||
74 | * @return int |
||
75 | */ |
||
76 | public function getAffectedRows() |
||
80 | |||
81 | /** |
||
82 | * (PHP 5 >= 5.0.0)<br/> |
||
83 | * Whether a offset exists |
||
84 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
85 | * @param mixed $offset <p> |
||
86 | * An offset to check for. |
||
87 | * </p> |
||
88 | * @return boolean true on success or false on failure. |
||
89 | * </p> |
||
90 | * <p> |
||
91 | * The return value will be casted to boolean if non-boolean was returned. |
||
92 | */ |
||
93 | public function offsetExists($offset) |
||
97 | |||
98 | /** |
||
99 | * (PHP 5 >= 5.0.0)<br/> |
||
100 | * Offset to retrieve |
||
101 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
102 | * @param mixed $offset <p> |
||
103 | * The offset to retrieve. |
||
104 | * </p> |
||
105 | * @return mixed Can return all value types. |
||
106 | */ |
||
107 | public function offsetGet($offset) |
||
111 | |||
112 | /** |
||
113 | * (PHP 5 >= 5.0.0)<br/> |
||
114 | * Offset to set |
||
115 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
116 | * @param mixed $offset <p> |
||
117 | * The offset to assign the value to. |
||
118 | * </p> |
||
119 | * @param mixed $value <p> |
||
120 | * The value to set. |
||
121 | * </p> |
||
122 | * @return void |
||
123 | * |
||
124 | * @codeCoverageIgnore |
||
125 | */ |
||
126 | public function offsetSet($offset, $value) |
||
130 | |||
131 | /** |
||
132 | * (PHP 5 >= 5.0.0)<br/> |
||
133 | * Offset to unset |
||
134 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
135 | * @param mixed $offset <p> |
||
136 | * The offset to unset. |
||
137 | * </p> |
||
138 | * @return void |
||
139 | * |
||
140 | * @codeCoverageIgnore |
||
141 | */ |
||
142 | public function offsetUnset($offset) |
||
146 | |||
147 | /** |
||
148 | * (PHP 5 >= 5.0.0)<br/> |
||
149 | * Return the current element |
||
150 | * @link http://php.net/manual/en/iterator.current.php |
||
151 | * @return mixed Can return any type. |
||
152 | */ |
||
153 | public function current() |
||
159 | |||
160 | /** |
||
161 | * (PHP 5 >= 5.0.0)<br/> |
||
162 | * Move forward to next element |
||
163 | * @link http://php.net/manual/en/iterator.next.php |
||
164 | * @return void Any returned value is ignored. |
||
165 | */ |
||
166 | public function next() |
||
170 | |||
171 | /** |
||
172 | * (PHP 5 >= 5.0.0)<br/> |
||
173 | * Return the key of the current element |
||
174 | * @link http://php.net/manual/en/iterator.key.php |
||
175 | * @return mixed scalar on success, or null on failure. |
||
176 | */ |
||
177 | public function key() |
||
181 | |||
182 | /** |
||
183 | * (PHP 5 >= 5.0.0)<br/> |
||
184 | * Checks if current position is valid |
||
185 | * @link http://php.net/manual/en/iterator.valid.php |
||
186 | * @return boolean The return value will be casted to boolean and then evaluated. |
||
187 | * Returns true on success or false on failure. |
||
188 | */ |
||
189 | public function valid() |
||
197 | |||
198 | /** |
||
199 | * (PHP 5 >= 5.0.0)<br/> |
||
200 | * Rewind the Iterator to the first element |
||
201 | * @link http://php.net/manual/en/iterator.rewind.php |
||
202 | * @return void Any returned value is ignored. |
||
203 | */ |
||
204 | public function rewind() |
||
214 | |||
215 | /** |
||
216 | * Returns the number of rows in the result set |
||
217 | * @inheritdoc |
||
218 | */ |
||
219 | public function count() |
||
223 | |||
224 | protected function init() |
||
233 | |||
234 | /** |
||
235 | * @param array $numeric_array |
||
236 | * @return array |
||
237 | */ |
||
238 | protected function makeAssoc($numeric_array) |
||
247 | |||
248 | /** |
||
249 | * @param ResultSetAdapter::FETCH_ASSOC|ResultSetAdapter::FETCH_NUM $fetch_type |
||
|
|||
250 | * @return array|bool|null |
||
251 | */ |
||
252 | protected function fetchFromStore($fetch_type) |
||
266 | |||
267 | /** |
||
268 | * @param ResultSetAdapter::FETCH_ASSOC|ResultSetAdapter::FETCH_NUM $fetch_type |
||
269 | * @return array|bool |
||
270 | */ |
||
271 | protected function fetchAllFromStore($fetch_type) |
||
287 | |||
288 | /** |
||
289 | * @param ResultSetAdapter::FETCH_ASSOC|ResultSetAdapter::FETCH_NUM $fetch_type |
||
290 | * @return array |
||
291 | */ |
||
292 | protected function fetchAll($fetch_type) |
||
305 | |||
306 | /** |
||
307 | * Store all the data in this object and free the driver object |
||
308 | * |
||
309 | * @return static $this |
||
310 | */ |
||
311 | public function store() |
||
325 | |||
326 | /** |
||
327 | * Returns the array as in version 0.9.x |
||
328 | * |
||
329 | * @return array|int|mixed |
||
330 | * @deprecated Commodity method for simple transition to version 1.0.0 |
||
331 | */ |
||
332 | public function getStored() |
||
341 | |||
342 | /** |
||
343 | * Moves the cursor to the selected row |
||
344 | * |
||
345 | * @param int $num The number of the row to move the cursor to |
||
346 | * @return static |
||
347 | * @throws ResultSetException If the row does not exist |
||
348 | */ |
||
349 | public function toRow($num) |
||
364 | |||
365 | /** |
||
366 | * Moves the cursor to the next row |
||
367 | * |
||
368 | * @return static $this |
||
369 | * @throws ResultSetException If the next row does not exist |
||
370 | */ |
||
371 | public function toNextRow() |
||
376 | |||
377 | /** |
||
378 | * Fetches all the rows as an array of associative arrays |
||
379 | * |
||
380 | * @return array |
||
381 | */ |
||
382 | public function fetchAllAssoc() |
||
386 | |||
387 | /** |
||
388 | * Fetches all the rows as an array of indexed arrays |
||
389 | * |
||
390 | * @return array |
||
391 | */ |
||
392 | public function fetchAllNum() |
||
396 | |||
397 | /** |
||
398 | * Fetches a row as an associative array |
||
399 | * |
||
400 | * @return array |
||
401 | */ |
||
402 | public function fetchAssoc() |
||
406 | |||
407 | /** |
||
408 | * Fetches a row as an indexed array |
||
409 | * |
||
410 | * @return array|null |
||
411 | */ |
||
412 | public function fetchNum() |
||
416 | |||
417 | /** |
||
418 | * @param ResultSetAdapter::FETCH_ASSOC|ResultSetAdapter::FETCH_NUM $fetch_type |
||
419 | * @return array|null |
||
420 | */ |
||
421 | protected function fetch($fetch_type) |
||
435 | |||
436 | /** |
||
437 | * Frees the memory from the result |
||
438 | * Call it after you're done with a result set |
||
439 | * |
||
440 | * @return static |
||
441 | */ |
||
442 | public function freeResult() |
||
447 | } |
||
448 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.