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 |
||
28 | class ExprBuilder implements ExpressionInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var ExpressionInterface $wrappedExpression |
||
32 | */ |
||
33 | private $wrappedExpression; |
||
34 | |||
35 | /** |
||
36 | * ExprBuilder constructor. |
||
37 | */ |
||
38 | 27 | public function __construct() |
|
42 | |||
43 | /** |
||
44 | * @return ExpressionInterface |
||
45 | */ |
||
46 | public function getWrappedExpression() |
||
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | 27 | public function compile() |
|
58 | |||
59 | /** |
||
60 | * @param mixed $alias |
||
61 | * |
||
62 | * @return ExprBuilder |
||
63 | */ |
||
64 | 3 | public function alias($alias) |
|
70 | |||
71 | /** |
||
72 | * @return ExprBuilder |
||
73 | */ |
||
74 | public function sumNullable() |
||
78 | |||
79 | /** |
||
80 | * @return ExprBuilder |
||
81 | */ |
||
82 | 1 | public function in() |
|
88 | |||
89 | /** |
||
90 | * @return ExprBuilder |
||
91 | */ |
||
92 | public function using() |
||
96 | |||
97 | /** |
||
98 | * @return ExprBuilder |
||
99 | */ |
||
100 | 1 | public function desc() |
|
104 | |||
105 | /** |
||
106 | * @return ExprBuilder |
||
107 | */ |
||
108 | 1 | public function asc() |
|
112 | |||
113 | /** |
||
114 | * @param string $connector |
||
115 | * @param mixed $expression |
||
116 | * |
||
117 | * @return ExprBuilder |
||
118 | */ |
||
119 | 2 | public function conjunction($connector, $expression) |
|
125 | |||
126 | /** |
||
127 | * @param string $functionName |
||
128 | * @param FunctionCallContext|null $context |
||
129 | * |
||
130 | * @return ExprBuilder |
||
131 | */ |
||
132 | 10 | public function func($functionName, FunctionCallContext $context = null) |
|
136 | |||
137 | ############################### |
||
138 | ### COMPARISION EXPRESSIONS ### |
||
139 | ############################### |
||
140 | |||
141 | /** |
||
142 | * @param mixed $from |
||
143 | * @param mixed $to |
||
144 | * |
||
145 | * @return ExprBuilder |
||
146 | */ |
||
147 | 1 | public function between($from, $to) |
|
154 | |||
155 | /** |
||
156 | * @param mixed $expression |
||
157 | * |
||
158 | * @return ExprBuilder |
||
159 | */ |
||
160 | public function eq($expression) |
||
166 | |||
167 | /** |
||
168 | * @param mixed $expression |
||
169 | * |
||
170 | * @return ExprBuilder |
||
171 | */ |
||
172 | 1 | public function gt($expression) |
|
178 | |||
179 | /** |
||
180 | * @param mixed $expression |
||
181 | * |
||
182 | * @return ExprBuilder |
||
183 | */ |
||
184 | public function gte($expression) |
||
190 | |||
191 | /** |
||
192 | * @return ExprBuilder |
||
193 | */ |
||
194 | public function isNull() |
||
198 | |||
199 | /** |
||
200 | * @param mixed $expression |
||
201 | * |
||
202 | * @return ExprBuilder |
||
203 | */ |
||
204 | public function lt($expression) |
||
210 | |||
211 | /** |
||
212 | * @param mixed $expression |
||
213 | * |
||
214 | * @return ExprBuilder |
||
215 | */ |
||
216 | public function lte($expression) |
||
222 | |||
223 | /** |
||
224 | * @param mixed $expression |
||
225 | * |
||
226 | * @return ExprBuilder |
||
227 | */ |
||
228 | public function neq($expression) |
||
234 | |||
235 | /** |
||
236 | * @param mixed $from |
||
237 | * @param mixed $to |
||
238 | * |
||
239 | * @return ExprBuilder |
||
240 | */ |
||
241 | 1 | public function notBetween($from, $to) |
|
248 | |||
249 | /** |
||
250 | * @param mixed $expression |
||
251 | * |
||
252 | * @return ExprBuilder |
||
253 | */ |
||
254 | public function nullEq($expression) |
||
260 | |||
261 | ############################## |
||
262 | ### ARITHMETIC EXPRESSIONS ### |
||
263 | ############################## |
||
264 | |||
265 | /** |
||
266 | * @param mixed $expression |
||
267 | * |
||
268 | * @return ExprBuilder |
||
269 | */ |
||
270 | 1 | public function add($expression) |
|
276 | |||
277 | /** |
||
278 | * @param mixed $expression |
||
279 | * |
||
280 | * @return ExprBuilder |
||
281 | */ |
||
282 | public function div($expression) |
||
288 | |||
289 | /** |
||
290 | * @param mixed $expression |
||
291 | * |
||
292 | * @return ExprBuilder |
||
293 | */ |
||
294 | public function divide($expression) |
||
300 | |||
301 | /** |
||
302 | * @param mixed $expression |
||
303 | * |
||
304 | * @return ExprBuilder |
||
305 | */ |
||
306 | public function modulo($expression) |
||
312 | |||
313 | /** |
||
314 | * @param mixed $expression |
||
315 | * |
||
316 | * @return ExprBuilder |
||
317 | */ |
||
318 | public function multiply($expression) |
||
324 | |||
325 | /** |
||
326 | * @param mixed $expression |
||
327 | * |
||
328 | * @return ExprBuilder |
||
329 | */ |
||
330 | public function subtract($expression) |
||
336 | |||
337 | ################# |
||
338 | ### FUNCTIONS ### |
||
339 | ################# |
||
340 | |||
341 | /** |
||
342 | * @return ExprBuilder |
||
343 | */ |
||
344 | 1 | public function asci() |
|
348 | |||
349 | /** |
||
350 | * @return ExprBuilder |
||
351 | */ |
||
352 | public function bin() |
||
356 | |||
357 | /** |
||
358 | * @return ExprBuilder |
||
359 | */ |
||
360 | public function bitLength() |
||
364 | |||
365 | /** |
||
366 | * @param mixed $using |
||
367 | * |
||
368 | * @return ExprBuilder |
||
369 | */ |
||
370 | 1 | public function char($using = null) |
|
382 | |||
383 | /** |
||
384 | * @return ExprBuilder |
||
385 | */ |
||
386 | 1 | public function coalesce() |
|
390 | |||
391 | /** |
||
392 | * @return ExprBuilder |
||
393 | */ |
||
394 | public function concat() |
||
398 | |||
399 | /** |
||
400 | * @return ExprBuilder |
||
401 | */ |
||
402 | public function concatWs() |
||
406 | |||
407 | /** |
||
408 | * @return ExprBuilder |
||
409 | */ |
||
410 | public function elt() |
||
414 | |||
415 | /** |
||
416 | * @return ExprBuilder |
||
417 | */ |
||
418 | public function exportSet() |
||
422 | |||
423 | /** |
||
424 | * @return ExprBuilder |
||
425 | */ |
||
426 | 1 | public function field() |
|
430 | |||
431 | /** |
||
432 | * @param mixed $expression |
||
433 | * |
||
434 | * @return ExprBuilder |
||
435 | */ |
||
436 | 1 | public function ifNull($expression) |
|
443 | |||
444 | /** |
||
445 | * @return ExprBuilder |
||
446 | */ |
||
447 | 2 | public function max() |
|
451 | |||
452 | /** |
||
453 | * @return ExprBuilder |
||
454 | */ |
||
455 | 4 | public function sum() |
|
459 | |||
460 | /** |
||
461 | * @return ExprBuilder |
||
462 | */ |
||
463 | 1 | public function year() |
|
467 | } |