Complex classes like SQLAnywhereStatement 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 SQLAnywhereStatement, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
43 | class SQLAnywhereStatement implements IteratorAggregate, Statement |
||
44 | { |
||
45 | /** @var resource The connection resource. */ |
||
46 | private $conn; |
||
47 | |||
48 | /** @var string Name of the default class to instantiate when fetching class instances. */ |
||
49 | private $defaultFetchClass = '\stdClass'; |
||
50 | |||
51 | /** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */ |
||
52 | private $defaultFetchClassCtorArgs = []; |
||
53 | |||
54 | /** @var int Default fetch mode to use. */ |
||
55 | private $defaultFetchMode = FetchMode::MIXED; |
||
56 | |||
57 | /** @var resource The result set resource to fetch. */ |
||
58 | private $result; |
||
59 | |||
60 | /** @var resource The prepared SQL statement to execute. */ |
||
61 | private $stmt; |
||
62 | |||
63 | /** @var mixed[] The references to bound parameter values. */ |
||
64 | private $boundValues = []; |
||
65 | |||
66 | /** |
||
67 | * Prepares given statement for given connection. |
||
68 | * |
||
69 | * @param resource $conn The connection resource to use. |
||
70 | * @param string $sql The SQL statement to prepare. |
||
71 | * |
||
72 | * @throws SQLAnywhereException |
||
73 | */ |
||
74 | public function __construct($conn, string $sql) |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | * |
||
94 | * @throws SQLAnywhereException |
||
95 | */ |
||
96 | public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null) : void |
||
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | public function bindValue($param, $value, int $type = ParameterType::STRING) : void |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function closeCursor() : void |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function columnCount() : int |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | * |
||
154 | * @throws SQLAnywhereException |
||
155 | */ |
||
156 | public function execute(?array $params = null) : void |
||
176 | |||
177 | /** |
||
178 | * {@inheritdoc} |
||
179 | * |
||
180 | * @throws SQLAnywhereException |
||
181 | */ |
||
182 | public function fetch(?int $fetchMode = null, ...$args) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | public function fetchAll(?int $fetchMode = null, ...$args) : array |
||
256 | |||
257 | /** |
||
258 | * {@inheritdoc} |
||
259 | */ |
||
260 | public function fetchColumn(int $columnIndex = 0) |
||
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | public function getIterator() |
||
282 | |||
283 | /** |
||
284 | * {@inheritdoc} |
||
285 | */ |
||
286 | public function rowCount() : int |
||
290 | |||
291 | /** |
||
292 | * {@inheritdoc} |
||
293 | */ |
||
294 | public function setFetchMode(int $fetchMode, ...$args) : void |
||
308 | |||
309 | /** |
||
310 | * Casts a stdClass object to the given class name mapping its' properties. |
||
311 | * |
||
312 | * @param stdClass $sourceObject Object to cast from. |
||
313 | * @param string|object $destinationClass Name of the class or class instance to cast to. |
||
314 | * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. |
||
315 | * |
||
316 | * @throws SQLAnywhereException |
||
317 | */ |
||
318 | private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = []) : object |
||
353 | } |
||
354 |