Complex classes like QueryCompiler 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 QueryCompiler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class QueryCompiler implements QueryCompilerInterface |
||
27 | { |
||
28 | /** |
||
29 | * @inheritdoc |
||
30 | */ |
||
31 | 27 | public function compile(AbstractBuilder $qb) |
|
35 | |||
36 | /** |
||
37 | * @param AbstractBuilder $qb |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | 27 | private function compileRaw(AbstractBuilder $qb) |
|
59 | |||
60 | /** |
||
61 | * @param string $rawSQL |
||
62 | * @param AbstractBuilder $qb |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | 27 | private function compileReferences($rawSQL, AbstractBuilder $qb) |
|
70 | |||
71 | /** |
||
72 | * @param AbstractBuilder $qb |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | 27 | private function compileInsert(AbstractBuilder $qb) |
|
84 | |||
85 | /** |
||
86 | * @param AbstractBuilder $qb |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | 27 | private function compileUpdate(AbstractBuilder $qb) |
|
98 | |||
99 | /** |
||
100 | * @param AbstractBuilder $qb |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 27 | private function compileSelect(AbstractBuilder $qb) |
|
112 | |||
113 | /** |
||
114 | * @param AbstractBuilder $qb |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 27 | private function compileSet(AbstractBuilder $qb) |
|
126 | |||
127 | /** |
||
128 | * @param AbstractBuilder $qb |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 27 | private function compileWhere(AbstractBuilder $qb) |
|
140 | |||
141 | /** |
||
142 | * @param AbstractBuilder $qb |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | 27 | private function compileGroupBy(AbstractBuilder $qb) |
|
154 | |||
155 | /** |
||
156 | * @param AbstractBuilder $qb |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | 27 | private function compileHaving(AbstractBuilder $qb) |
|
168 | |||
169 | /** |
||
170 | * @param AbstractBuilder $qb |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | 27 | private function compileOrderBy(AbstractBuilder $qb) |
|
182 | |||
183 | /** |
||
184 | * @param AbstractBuilder $qb |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | 27 | private function compileLimit(AbstractBuilder $qb) |
|
196 | |||
197 | /** |
||
198 | * @param AbstractBuilder $qb |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | 27 | private function compileRootTables(AbstractBuilder $qb) |
|
218 | |||
219 | /** |
||
220 | * @param AbstractBuilder $qb |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | 27 | private function compileJoinTables(AbstractBuilder $qb) |
|
232 | |||
233 | /** |
||
234 | * @param AbstractBuilder $qb |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | 27 | private function compileInsertValues(AbstractBuilder $qb) |
|
248 | |||
249 | /** |
||
250 | * @param AbstractBuilder $qb |
||
251 | * |
||
252 | * @return string |
||
253 | */ |
||
254 | 27 | private function compileInsertColumns(AbstractBuilder $qb) |
|
262 | |||
263 | /** |
||
264 | * @param AbstractTable $table |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | 26 | private function compileTableDeclaration(AbstractTable $table) |
|
288 | } |