Complex classes like ExprBuilder 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 ExprBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class ExprBuilder implements ExpressionInterface |
||
28 | { |
||
29 | /** |
||
30 | * @var ExpressionInterface $wrappedExpression |
||
31 | */ |
||
32 | private $wrappedExpression; |
||
33 | |||
34 | /** |
||
35 | * ExprBuilder constructor. |
||
36 | */ |
||
37 | 29 | public function __construct() |
|
41 | |||
42 | /** |
||
43 | * @return ExpressionInterface |
||
44 | */ |
||
45 | public function getWrappedExpression() |
||
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | 28 | public function compile() |
|
57 | |||
58 | /** |
||
59 | * @param mixed $alias |
||
60 | * |
||
61 | * @return ExprBuilder |
||
62 | */ |
||
63 | 3 | public function alias($alias) |
|
69 | |||
70 | /** |
||
71 | * @return ExprBuilder |
||
72 | */ |
||
73 | public function sumNullable() |
||
77 | |||
78 | /** |
||
79 | * @return ExprBuilder |
||
80 | */ |
||
81 | 1 | public function in() |
|
87 | |||
88 | /** |
||
89 | * @return ExprBuilder |
||
90 | */ |
||
91 | public function using() |
||
95 | |||
96 | /** |
||
97 | * @return ExprBuilder |
||
98 | */ |
||
99 | 1 | public function desc() |
|
103 | |||
104 | /** |
||
105 | * @return ExprBuilder |
||
106 | */ |
||
107 | 1 | public function asc() |
|
111 | |||
112 | /** |
||
113 | * @param string $connector |
||
114 | * @param mixed $expression |
||
115 | * |
||
116 | * @return ExprBuilder |
||
117 | */ |
||
118 | 3 | public function conjunction($connector, $expression) |
|
124 | |||
125 | /** |
||
126 | * @param string $functionName |
||
127 | * @param FunctionCallContext|null $context |
||
128 | * |
||
129 | * @return ExprBuilder |
||
130 | */ |
||
131 | 11 | public function func($functionName, FunctionCallContext $context = null) |
|
135 | |||
136 | ############################### |
||
137 | ### COMPARISION EXPRESSIONS ### |
||
138 | ############################### |
||
139 | |||
140 | /** |
||
141 | * @param mixed $from |
||
142 | * @param mixed $to |
||
143 | * |
||
144 | * @return ExprBuilder |
||
145 | */ |
||
146 | 1 | public function between($from, $to) |
|
153 | |||
154 | /** |
||
155 | * @param mixed $expression |
||
156 | * |
||
157 | * @return ExprBuilder |
||
158 | */ |
||
159 | 1 | public function eq($expression) |
|
165 | |||
166 | /** |
||
167 | * @param mixed $expression |
||
168 | * |
||
169 | * @return ExprBuilder |
||
170 | */ |
||
171 | 1 | public function gt($expression) |
|
177 | |||
178 | /** |
||
179 | * @param mixed $expression |
||
180 | * |
||
181 | * @return ExprBuilder |
||
182 | */ |
||
183 | public function gte($expression) |
||
189 | |||
190 | /** |
||
191 | * @return ExprBuilder |
||
192 | */ |
||
193 | public function isNull() |
||
197 | |||
198 | /** |
||
199 | * @param mixed $expression |
||
200 | * |
||
201 | * @return ExprBuilder |
||
202 | */ |
||
203 | public function lt($expression) |
||
209 | |||
210 | /** |
||
211 | * @param mixed $expression |
||
212 | * |
||
213 | * @return ExprBuilder |
||
214 | */ |
||
215 | public function lte($expression) |
||
221 | |||
222 | /** |
||
223 | * @param mixed $expression |
||
224 | * |
||
225 | * @return ExprBuilder |
||
226 | */ |
||
227 | public function neq($expression) |
||
233 | |||
234 | /** |
||
235 | * @param mixed $from |
||
236 | * @param mixed $to |
||
237 | * |
||
238 | * @return ExprBuilder |
||
239 | */ |
||
240 | 1 | public function notBetween($from, $to) |
|
247 | |||
248 | /** |
||
249 | * @param mixed $expression |
||
250 | * |
||
251 | * @return ExprBuilder |
||
252 | */ |
||
253 | public function nullEq($expression) |
||
259 | |||
260 | ############################## |
||
261 | ### ARITHMETIC EXPRESSIONS ### |
||
262 | ############################## |
||
263 | |||
264 | /** |
||
265 | * @param mixed $expression |
||
266 | * |
||
267 | * @return ExprBuilder |
||
268 | */ |
||
269 | 1 | public function add($expression) |
|
275 | |||
276 | /** |
||
277 | * @param mixed $expression |
||
278 | * |
||
279 | * @return ExprBuilder |
||
280 | */ |
||
281 | public function div($expression) |
||
287 | |||
288 | /** |
||
289 | * @param mixed $expression |
||
290 | * |
||
291 | * @return ExprBuilder |
||
292 | */ |
||
293 | public function divide($expression) |
||
299 | |||
300 | /** |
||
301 | * @param mixed $expression |
||
302 | * |
||
303 | * @return ExprBuilder |
||
304 | */ |
||
305 | public function modulo($expression) |
||
311 | |||
312 | /** |
||
313 | * @param mixed $expression |
||
314 | * |
||
315 | * @return ExprBuilder |
||
316 | */ |
||
317 | public function multiply($expression) |
||
323 | |||
324 | /** |
||
325 | * @param mixed $expression |
||
326 | * |
||
327 | * @return ExprBuilder |
||
328 | */ |
||
329 | public function subtract($expression) |
||
335 | |||
336 | ################# |
||
337 | ### FUNCTIONS ### |
||
338 | ################# |
||
339 | |||
340 | /** |
||
341 | * @return ExprBuilder |
||
342 | */ |
||
343 | 1 | public function asci() |
|
347 | |||
348 | /** |
||
349 | * @return ExprBuilder |
||
350 | */ |
||
351 | public function bin() |
||
355 | |||
356 | /** |
||
357 | * @return ExprBuilder |
||
358 | */ |
||
359 | public function bitLength() |
||
363 | |||
364 | /** |
||
365 | * @param mixed $using |
||
366 | * |
||
367 | * @return ExprBuilder |
||
368 | */ |
||
369 | 1 | public function char($using = null) |
|
381 | |||
382 | /** |
||
383 | * @return ExprBuilder |
||
384 | */ |
||
385 | 1 | public function coalesce() |
|
389 | |||
390 | /** |
||
391 | * @return ExprBuilder |
||
392 | */ |
||
393 | public function concat() |
||
397 | |||
398 | /** |
||
399 | * @return ExprBuilder |
||
400 | */ |
||
401 | public function concatWs() |
||
405 | |||
406 | /** |
||
407 | * @return ExprBuilder |
||
408 | */ |
||
409 | public function elt() |
||
413 | |||
414 | /** |
||
415 | * @return ExprBuilder |
||
416 | */ |
||
417 | 1 | public function exportSet() |
|
421 | |||
422 | /** |
||
423 | * @return ExprBuilder |
||
424 | */ |
||
425 | 1 | public function field() |
|
429 | |||
430 | /** |
||
431 | * @param mixed $expression |
||
432 | * |
||
433 | * @return ExprBuilder |
||
434 | */ |
||
435 | 1 | public function ifNull($expression) |
|
442 | |||
443 | /** |
||
444 | * @return ExprBuilder |
||
445 | */ |
||
446 | 2 | public function max() |
|
450 | |||
451 | /** |
||
452 | * @return ExprBuilder |
||
453 | */ |
||
454 | 4 | public function sum() |
|
458 | |||
459 | /** |
||
460 | * @return ExprBuilder |
||
461 | */ |
||
462 | 1 | public function year() |
|
466 | } |