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 | 22 | function __construct ($database, $user = '', $password = '', $host = '', $prefix = '') { |
|
40 | /** |
||
41 | * @inheritdoc |
||
42 | */ |
||
43 | 22 | function q ($query, $params = [], ...$param) { |
|
48 | /** |
||
49 | * @inheritdoc |
||
50 | * |
||
51 | * @return false|SQLite3Result |
||
52 | */ |
||
53 | 22 | protected function q_internal ($query) { |
|
59 | /** |
||
60 | * @inheritdoc |
||
61 | */ |
||
62 | 6 | protected function q_multi_internal ($query) { |
|
69 | /** |
||
70 | * @inheritdoc |
||
71 | * |
||
72 | * @param false|SQLite3Result $query_result |
||
73 | */ |
||
74 | 21 | function f ($query_result, $single_column = false, $array = false, $indexed = false) { |
|
90 | /** |
||
91 | * @inheritdoc |
||
92 | */ |
||
93 | 15 | function id () { |
|
96 | /** |
||
97 | * @inheritdoc |
||
98 | */ |
||
99 | 1 | function affected () { |
|
102 | /** |
||
103 | * @inheritdoc |
||
104 | * |
||
105 | * @param false|SQLite3Result $query_result |
||
106 | */ |
||
107 | 18 | function free ($query_result) { |
|
113 | /** |
||
114 | * @inheritdoc |
||
115 | */ |
||
116 | 2 | function columns ($table, $like = false) { |
|
147 | /** |
||
148 | * @inheritdoc |
||
149 | */ |
||
150 | 1 | function tables ($like = false) { |
|
173 | /** |
||
174 | * @inheritdoc |
||
175 | */ |
||
176 | 22 | protected function s_internal ($string, $single_quotes_around) { |
|
180 | /** |
||
181 | * @inheritdoc |
||
182 | */ |
||
183 | 1 | function server () { |
|
186 | /** |
||
187 | * @inheritdoc |
||
188 | */ |
||
189 | 2 | function __destruct () { |
|
195 | } |
||
196 |