Complex classes like SQLite 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 SQLite, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class SQLite extends _Abstract { |
||
| 13 | /** |
||
| 14 | * @var \SQLite3 Instance of DB connection |
||
| 15 | */ |
||
| 16 | protected $instance; |
||
| 17 | /** |
||
| 18 | * @param string $database Ignored for SQLite |
||
| 19 | * @param string $user Ignored for SQLite |
||
| 20 | * @param string $password Ignored for SQLite |
||
| 21 | * @param string $host Path to database file, relatively to website root or absolute |
||
| 22 | * @param string $prefix |
||
| 23 | */ |
||
| 24 | 24 | public function __construct ($database, $user = '', $password = '', $host = '', $prefix = '') { |
|
| 40 | /** |
||
| 41 | * @inheritdoc |
||
| 42 | */ |
||
| 43 | 24 | public function q ($query, ...$params) { |
|
| 49 | /** |
||
| 50 | * Convert small subset of MySQL queries into SQLite-compatible syntax |
||
| 51 | * |
||
| 52 | * @param string $query |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | 24 | protected function convert_sql ($query) { |
|
| 59 | /** |
||
| 60 | * @inheritdoc |
||
| 61 | * |
||
| 62 | * @return false|SQLite3Result |
||
| 63 | */ |
||
| 64 | 24 | protected function q_internal ($query, $parameters = []) { |
|
| 82 | /** |
||
| 83 | * @inheritdoc |
||
| 84 | * |
||
| 85 | * @param false|SQLite3Result $query_result |
||
| 86 | */ |
||
| 87 | 23 | public function f ($query_result, $single_column = false, $array = false, $indexed = false) { |
|
| 103 | /** |
||
| 104 | * @inheritdoc |
||
| 105 | */ |
||
| 106 | 17 | public function id () { |
|
| 109 | /** |
||
| 110 | * @inheritdoc |
||
| 111 | */ |
||
| 112 | 1 | public function affected () { |
|
| 115 | /** |
||
| 116 | * @inheritdoc |
||
| 117 | * |
||
| 118 | * @param false|SQLite3Result $query_result |
||
| 119 | */ |
||
| 120 | 20 | public function free ($query_result) { |
|
| 126 | /** |
||
| 127 | * @inheritdoc |
||
| 128 | */ |
||
| 129 | 2 | public function columns ($table, $like = false) { |
|
| 160 | /** |
||
| 161 | * @inheritdoc |
||
| 162 | */ |
||
| 163 | 1 | public function tables ($like = false) { |
|
| 186 | /** |
||
| 187 | * @inheritdoc |
||
| 188 | */ |
||
| 189 | 22 | protected function s_internal ($string, $single_quotes_around) { |
|
| 193 | /** |
||
| 194 | * @inheritdoc |
||
| 195 | */ |
||
| 196 | 1 | public function server () { |
|
| 199 | /** |
||
| 200 | * @inheritdoc |
||
| 201 | */ |
||
| 202 | 2 | public function __destruct () { |
|
| 208 | } |
||
| 209 |