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 | 64 | public function __construct ($database, $user = '', $password = '', $host = '', $prefix = '') { |
|
| 39 | /** |
||
| 40 | * @inheritdoc |
||
| 41 | */ |
||
| 42 | 64 | public function q ($query, ...$params) { |
|
| 48 | /** |
||
| 49 | * Convert small subset of MySQL queries into SQLite-compatible syntax |
||
| 50 | * |
||
| 51 | * @param string $query |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 64 | protected function convert_sql ($query) { |
|
| 58 | /** |
||
| 59 | * @inheritdoc |
||
| 60 | * |
||
| 61 | * @return false|SQLite3Result |
||
| 62 | */ |
||
| 63 | 64 | protected function q_internal ($query, $parameters = []) { |
|
| 81 | /** |
||
| 82 | * @inheritdoc |
||
| 83 | * |
||
| 84 | * @param false|SQLite3Result $query_result |
||
| 85 | */ |
||
| 86 | 64 | public function f ($query_result, $single_column = false, $array = false, $indexed = false) { |
|
| 102 | /** |
||
| 103 | * @inheritdoc |
||
| 104 | */ |
||
| 105 | 48 | public function id () { |
|
| 108 | /** |
||
| 109 | * @inheritdoc |
||
| 110 | */ |
||
| 111 | 2 | public function affected () { |
|
| 114 | /** |
||
| 115 | * @inheritdoc |
||
| 116 | * |
||
| 117 | * @param false|SQLite3Result $query_result |
||
| 118 | */ |
||
| 119 | 54 | public function free ($query_result) { |
|
| 125 | /** |
||
| 126 | * @inheritdoc |
||
| 127 | */ |
||
| 128 | 6 | public function columns ($table, $like = false) { |
|
| 159 | /** |
||
| 160 | * @inheritdoc |
||
| 161 | */ |
||
| 162 | 2 | public function tables ($like = false) { |
|
| 185 | /** |
||
| 186 | * @inheritdoc |
||
| 187 | */ |
||
| 188 | 58 | protected function s_internal ($string, $single_quotes_around) { |
|
| 192 | /** |
||
| 193 | * @inheritdoc |
||
| 194 | */ |
||
| 195 | 2 | public function server () { |
|
| 198 | /** |
||
| 199 | * @inheritdoc |
||
| 200 | */ |
||
| 201 | 2 | public function __destruct () { |
|
| 207 | } |
||
| 208 |