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 |
||
9 | class SQLite extends _Abstract { |
||
10 | /** |
||
11 | * @var \SQLite3 Instance of DB connection |
||
12 | */ |
||
13 | protected $instance; |
||
14 | /** |
||
15 | * @param string $database Ignored for SQLite |
||
16 | * @param string $user Ignored for SQLite |
||
17 | * @param string $password Ignored for SQLite |
||
18 | * @param string $host Path to database file, relatively to website root or absolute |
||
19 | * @param string $charset Ignored for SQLite |
||
20 | * @param string $prefix |
||
21 | */ |
||
22 | function __construct ($database, $user = '', $password = '', $host = '', $charset = '', $prefix = '') { |
||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | function q ($query, $params = [], ...$param) { |
||
42 | /** |
||
43 | * @inheritdoc |
||
44 | * |
||
45 | * @return bool|\SQLite3Result |
||
46 | */ |
||
47 | protected function q_internal ($query) { |
||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | protected function q_multi_internal ($query) { |
||
63 | /** |
||
64 | * @deprecated |
||
65 | * @todo remove after 4.x release |
||
66 | * |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | function n ($query_result) { |
||
85 | /** |
||
86 | * @inheritdoc |
||
87 | * |
||
88 | * @param false|\SQLite3Result $query_result |
||
89 | */ |
||
90 | function f ($query_result, $single_column = false, $array = false, $indexed = false) { |
||
106 | /** |
||
107 | * @inheritdoc |
||
108 | */ |
||
109 | function id () { |
||
112 | /** |
||
113 | * @inheritdoc |
||
114 | */ |
||
115 | function affected () { |
||
118 | /** |
||
119 | * @inheritdoc |
||
120 | * |
||
121 | * @param false|\SQLite3Result $query_result |
||
122 | */ |
||
123 | function free ($query_result) { |
||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | function columns ($table, $like = false) { |
||
161 | /** |
||
162 | * @inheritdoc |
||
163 | */ |
||
164 | function tables ($like = false) { |
||
187 | /** |
||
188 | * @inheritdoc |
||
189 | */ |
||
190 | protected function s_internal ($string, $single_quotes_around) { |
||
194 | /** |
||
195 | * @inheritdoc |
||
196 | */ |
||
197 | function server () { |
||
200 | /** |
||
201 | * @inheritdoc |
||
202 | */ |
||
203 | function __destruct () { |
||
209 | } |
||
210 |