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 = []) { |
|
79 | /** |
||
80 | * @inheritdoc |
||
81 | * |
||
82 | * @param false|SQLite3Result $query_result |
||
83 | */ |
||
84 | 23 | public function f ($query_result, $single_column = false, $array = false, $indexed = false) { |
|
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | 17 | public function id () { |
|
106 | /** |
||
107 | * @inheritdoc |
||
108 | */ |
||
109 | 1 | public function affected () { |
|
112 | /** |
||
113 | * @inheritdoc |
||
114 | * |
||
115 | * @param false|SQLite3Result $query_result |
||
116 | */ |
||
117 | 20 | public function free ($query_result) { |
|
123 | /** |
||
124 | * @inheritdoc |
||
125 | */ |
||
126 | 2 | public function columns ($table, $like = false) { |
|
157 | /** |
||
158 | * @inheritdoc |
||
159 | */ |
||
160 | 1 | public function tables ($like = false) { |
|
183 | /** |
||
184 | * @inheritdoc |
||
185 | */ |
||
186 | 22 | protected function s_internal ($string, $single_quotes_around) { |
|
190 | /** |
||
191 | * @inheritdoc |
||
192 | */ |
||
193 | 1 | public function server () { |
|
196 | /** |
||
197 | * @inheritdoc |
||
198 | */ |
||
199 | 2 | public function __destruct () { |
|
205 | } |
||
206 |